OPEN-SOURCE SCRIPT
target tendance

//version=6
indicator("target tendance", "TT", overlay = true)
// Trend settings
st_factor = input.float(12, title="Supertrend Factor", minval=1, step=0.5, group="Trend Settings",
tooltip="Multiplier for the ATR to determine Supertrend bands width. Higher values create wider bands and fewer signals.")
st_atr_period = input.int(90, title="Supertrend ATR Period", minval=1, group="Trend Settings",
tooltip="Number of bars used to calculate the ATR for Supertrend. Longer periods create smoother, less reactive bands.")
wma_length = input.int(40, title="WMA Length", minval=1, group="Trend Settings",
tooltip="Length of the Weighted Moving Average applied to the SuperTrend. Higher values create smoother, less reactive lines.")
ema_length = input.int(14, title="EMA Length", minval=1, group="Trend Settings",
tooltip="Length of the Exponential Moving Average applied to the WMA. Controls the final smoothness of the trend line.")
//Continuation settings
cont_factor = input.int(3, title="Confirmation count", minval=1, group="Rejection Settings",
tooltip="Number of consecutive bars that must consolidate at the trend line before a rejection signal is generated. Higher values require more bars to confirm a trend.")
// Volatility settings
shw_TP1 = input.bool(true, title="Show Take Profit Levels", group="Targets",
tooltip="Toggle visibility of take profit target levels on the chart.")
atr_period = input.int(14, title="Volatility (ATR) period", minval=1, group="Targets",
tooltip="Number of bars used to calculate the Average True Range for position sizing and targets.")
sl_multiplier = input.float(5, title="Stop Loss ATR Multiplier", minval=0.1, step=0.1, group="Targets",
tooltip="Multiplier applied to ATR to determine stop loss distance from entry. Higher values place stops further away.")
tp1_multiplier = input.float(0.5, title="TP1 Multiplier", minval=0.1, step=0.1, tooltip="Multiple of SL distance for first take profit target.", group="Targets")
tp2_multiplier = input.float(1.0, title="TP2 Multiplier", minval=0.1, step=0.1, tooltip="Multiple of SL distance for second take profit target.", group="Targets")
tp3_multiplier = input.float(1.5, title="TP3 Multiplier", minval=0.1, step=0.1, tooltip="Multiple of SL distance for third take profit target.", group="Targets")
volatility = ta.atr(atr_period)
// Appearance settings
green = input.color(#95eed6, title="Bullish Color", tooltip="Color used for bullishness", group="Appearance")
red = input.color(#ff1100, title="Bearish Color", tooltip="Color used for bearishness", group="Appearance")
pine_supertrend(factor, atrPeriod) =>
src = hl2
atr = ta.atr(atrPeriod)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
[lowerBand, upperBand]
[lwr, upr] = pine_supertrend(st_factor, st_atr_period)
tL = ta.ema(ta.wma(math.avg(lwr, upr), wma_length), ema_length)
var trend = 0
if ta.crossover(tL, tL[1])
trend := 1
if ta.crossunder(tL, tL[1])
trend := -1
var rejcount = 0
bullishrej = trend == 1 and high > tL and low < tL
bearishrej = trend == -1 and high > tL and low < tL
if (bullishrej or bearishrej)
rejcount += 1
if ta.cross(trend, 0) or (not (bullishrej or bearishrej) and rejcount > 0)
rejcount := 0
plotchar((rejcount > cont_factor and trend == 1) ? tL : na, "Bullish Rejection", "▲", location.belowbar, green, size = size.tiny)
plotchar((rejcount > cont_factor and trend == -1) ? tL : na, "Bearish Rejection", "▼", location.abovebar, red, size = size.tiny)
plot(tL, "Baseline", color=trend == 1 ? color.new(green, 50) : color.new(red, 50), linewidth = 2)
barcolor(trend == 1 ? color.new(green, 50) : color.new(red, 50))
plotshape(ta.crossover(tL, tL[1]) ? tL : na, title="Bullish Trend Change", style=shape.labelup, location=location.absolute, size=size.small, color=green)
plotshape(ta.crossunder(tL, tL[1]) ? tL : na, title="Bearish Trend Change", style=shape.labeldown, location=location.absolute, size=size.small, color=red)
longSignal = ta.crossover(trend, 0)
shortSignal = ta.crossunder(trend, 0)
var SL = 0.0
var TP1_lvl = 0.0
var TP2_lvl = 0.0
var TP3_lvl = 0.0
var line entry_line = na
var line sl_line = na
var line tp1_line = na
var line tp2_line = na
var line tp3_line = na
var label entry_label = na
var label sl_label = na
var label tp1_label = na
var label tp2_label = na
var label tp3_label = na
if longSignal and shw_TP1
SL := low - volatility * sl_multiplier
TP1_lvl := close + math.abs(close - SL) * tp1_multiplier
TP2_lvl := close + math.abs(close - SL) * tp2_multiplier
TP3_lvl := close + math.abs(close - SL) * tp3_multiplier
entry_line := line.new(bar_index, close, bar_index, close, color = green, width = 3)
entry_label := label.new(bar_index, close, text = "Entry ▸ " + str.tostring(close, format.mintick), style = label.style_label_left, color = green, textcolor = color.white)
sl_line := line.new(bar_index, SL, bar_index, SL, color = color.new(red, 80), width = 3)
sl_label := label.new(bar_index, SL, text = "✘ SL ▸ " + str.tostring(SL, format.mintick), style = label.style_label_left, color = color.new(red, 80), textcolor = color.white)
indicator("target tendance", "TT", overlay = true)
// Trend settings
st_factor = input.float(12, title="Supertrend Factor", minval=1, step=0.5, group="Trend Settings",
tooltip="Multiplier for the ATR to determine Supertrend bands width. Higher values create wider bands and fewer signals.")
st_atr_period = input.int(90, title="Supertrend ATR Period", minval=1, group="Trend Settings",
tooltip="Number of bars used to calculate the ATR for Supertrend. Longer periods create smoother, less reactive bands.")
wma_length = input.int(40, title="WMA Length", minval=1, group="Trend Settings",
tooltip="Length of the Weighted Moving Average applied to the SuperTrend. Higher values create smoother, less reactive lines.")
ema_length = input.int(14, title="EMA Length", minval=1, group="Trend Settings",
tooltip="Length of the Exponential Moving Average applied to the WMA. Controls the final smoothness of the trend line.")
//Continuation settings
cont_factor = input.int(3, title="Confirmation count", minval=1, group="Rejection Settings",
tooltip="Number of consecutive bars that must consolidate at the trend line before a rejection signal is generated. Higher values require more bars to confirm a trend.")
// Volatility settings
shw_TP1 = input.bool(true, title="Show Take Profit Levels", group="Targets",
tooltip="Toggle visibility of take profit target levels on the chart.")
atr_period = input.int(14, title="Volatility (ATR) period", minval=1, group="Targets",
tooltip="Number of bars used to calculate the Average True Range for position sizing and targets.")
sl_multiplier = input.float(5, title="Stop Loss ATR Multiplier", minval=0.1, step=0.1, group="Targets",
tooltip="Multiplier applied to ATR to determine stop loss distance from entry. Higher values place stops further away.")
tp1_multiplier = input.float(0.5, title="TP1 Multiplier", minval=0.1, step=0.1, tooltip="Multiple of SL distance for first take profit target.", group="Targets")
tp2_multiplier = input.float(1.0, title="TP2 Multiplier", minval=0.1, step=0.1, tooltip="Multiple of SL distance for second take profit target.", group="Targets")
tp3_multiplier = input.float(1.5, title="TP3 Multiplier", minval=0.1, step=0.1, tooltip="Multiple of SL distance for third take profit target.", group="Targets")
volatility = ta.atr(atr_period)
// Appearance settings
green = input.color(#95eed6, title="Bullish Color", tooltip="Color used for bullishness", group="Appearance")
red = input.color(#ff1100, title="Bearish Color", tooltip="Color used for bearishness", group="Appearance")
pine_supertrend(factor, atrPeriod) =>
src = hl2
atr = ta.atr(atrPeriod)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
[lowerBand, upperBand]
[lwr, upr] = pine_supertrend(st_factor, st_atr_period)
tL = ta.ema(ta.wma(math.avg(lwr, upr), wma_length), ema_length)
var trend = 0
if ta.crossover(tL, tL[1])
trend := 1
if ta.crossunder(tL, tL[1])
trend := -1
var rejcount = 0
bullishrej = trend == 1 and high > tL and low < tL
bearishrej = trend == -1 and high > tL and low < tL
if (bullishrej or bearishrej)
rejcount += 1
if ta.cross(trend, 0) or (not (bullishrej or bearishrej) and rejcount > 0)
rejcount := 0
plotchar((rejcount > cont_factor and trend == 1) ? tL : na, "Bullish Rejection", "▲", location.belowbar, green, size = size.tiny)
plotchar((rejcount > cont_factor and trend == -1) ? tL : na, "Bearish Rejection", "▼", location.abovebar, red, size = size.tiny)
plot(tL, "Baseline", color=trend == 1 ? color.new(green, 50) : color.new(red, 50), linewidth = 2)
barcolor(trend == 1 ? color.new(green, 50) : color.new(red, 50))
plotshape(ta.crossover(tL, tL[1]) ? tL : na, title="Bullish Trend Change", style=shape.labelup, location=location.absolute, size=size.small, color=green)
plotshape(ta.crossunder(tL, tL[1]) ? tL : na, title="Bearish Trend Change", style=shape.labeldown, location=location.absolute, size=size.small, color=red)
longSignal = ta.crossover(trend, 0)
shortSignal = ta.crossunder(trend, 0)
var SL = 0.0
var TP1_lvl = 0.0
var TP2_lvl = 0.0
var TP3_lvl = 0.0
var line entry_line = na
var line sl_line = na
var line tp1_line = na
var line tp2_line = na
var line tp3_line = na
var label entry_label = na
var label sl_label = na
var label tp1_label = na
var label tp2_label = na
var label tp3_label = na
if longSignal and shw_TP1
SL := low - volatility * sl_multiplier
TP1_lvl := close + math.abs(close - SL) * tp1_multiplier
TP2_lvl := close + math.abs(close - SL) * tp2_multiplier
TP3_lvl := close + math.abs(close - SL) * tp3_multiplier
entry_line := line.new(bar_index, close, bar_index, close, color = green, width = 3)
entry_label := label.new(bar_index, close, text = "Entry ▸ " + str.tostring(close, format.mintick), style = label.style_label_left, color = green, textcolor = color.white)
sl_line := line.new(bar_index, SL, bar_index, SL, color = color.new(red, 80), width = 3)
sl_label := label.new(bar_index, SL, text = "✘ SL ▸ " + str.tostring(SL, format.mintick), style = label.style_label_left, color = color.new(red, 80), textcolor = color.white)
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.