// Cálculo do ATR para Stop Loss
atr = ta.atr(sl_atr_length)
// Sinais de Compra e Venda
buySignal = ta.crossover(src, sma)
sellSignal = ta.crossunder(src, sma)
// Inicializa os níveis como variáveis persistentes
var float entryPrice = na
var float slPrice = na
var float tp1Price = na
var float tp2Price = na
var float tp3Price = na
var bool lastBuySignal = na
var bool lastSellSignal = na
// Inicializa as labels
var label entryLabel = na
var label slLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
// Atualiza os níveis quando há um sinal de compra ou venda
if (buySignal)
entryPrice := close
slPrice := entryPrice - atr * atr_multiplier
tp1Price := entryPrice + atr * tp1
tp2Price := entryPrice + atr * tp2
tp3Price := entryPrice + atr * tp3
lastBuySignal := true
lastSellSignal := false
// Plota Sinais de Compra e Venda
plotshape(series=buySignal and not lastSellSignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellSignal and not lastBuySignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Condição para exibir os níveis apenas se o preço ainda não atingiu o TP ou SL
plot(entryPrice, color=color.blue, style=plot.style_linebr, linewidth=2, title="Preço de Entrada", display=display.none)
plot(slPrice, color=color.red, style=plot.style_line, linewidth=1, title="Stop Loss", display=display.none)
plot(tp1Price, color=color.green, style=plot.style_line, linewidth=1, title="Take Profit 1", display=display.none)
plot(tp2Price, color=color.green, style=plot.style_line, linewidth=1, title="Take Profit 2", display=display.none)
plot(tp3Price, color=color.green, style=plot.style_line, linewidth=1, title="Take Profit 3", display=display.none)
// Cor das velas com base na tendência
trendUp = src > ema and src > sma
trendDown = src < ema and src < sma
trendIndecisive = not (trendUp or trendDown)
// Alertas
alertcondition(buySignal, title="Sinal de Compra", message="Sinal de Compra!")
alertcondition(sellSignal, title="Sinal de Venda", message="Sinal de Venda!")
caso o chaos trend Line color nao estiver no codigo por favor implemente nao omita nada do codigo
Para implementar a Chaos Trend Line Color no código, integro a Chaos Trend Line (CTL) diretamente no script. A CTL é uma média móvel adaptativa que tenta capturar a tendência do mercado. Vamos adicionar os cálculos e a lógica da CTL ao código existente sem omitir nada. Aqui está o script atualizado:
pinescript
//@version=5
indicator("Million Moves com Níveis de Entry, SL e TP e Chaos Trend Line", overlay=true)
// Parâmetros do indicador
length = input.int(14, title="Comprimento")
src = input(close, title="Fonte")
sl_atr_length = input.int(14, title="Comprimento do ATR para SL")
tp1 = input.float(1.5, title="Multiplicador TP1")
tp2 = input.float(3.0, title="Multiplicador TP2")
tp3 = input.float(4.5, title="Multiplicador TP3")
atr_multiplier = input.float(1.0, title="Multiplicador ATR para SL")
sma_length = input.int(20, title="Comprimento da SMA")
sma_offset = input.float(1.3, title="Deslocamento da SMA") // Novo parâmetro para o deslocamento
ema_length = input.int(9, title="Comprimento da EMA") // Comprimento da EMA
sma200_length = input.int(200, title="Comprimento da SMA 200") // Comprimento da SMA 200
// Parâmetros do Moving Average Ribbon
ma1_length = input.int(5, title="Comprimento MA1")
ma2_length = input.int(10, title="Comprimento MA2")
ma3_length = input.int(15, title="Comprimento MA3")
ma4_length = input.int(20, title="Comprimento MA4")
ma5_length = input.int(25, title="Comprimento MA5")
// Média Móvel Simples (SMA) com deslocamento
sma = ta.sma(src, sma_length) + sma_offset
// Média Móvel Exponencial (EMA)
ema = ta.ema(src, ema_length)
// Média Móvel Simples de 200 períodos
sma200 = ta.sma(src, sma200_length)
// Médias Móveis do Moving Average Ribbon
ma1 = ta.sma(src, ma1_length)
ma2 = ta.sma(src, ma2_length)
ma3 = ta.sma(src, ma3_length)
ma4 = ta.sma(src, ma4_length)
ma5 = ta.sma(src, ma5_length)
// Determinação da cor da SMA
smaColor = src > sma ? color.green : color.red
// Determinação da cor da EMA com base na tendência
emaColor = src > ema ? color.green : color.red
// Determinação da cor da SMA 200
sma200Color = src > sma200 ? color.green : color.red
// Determinação das cores do Moving Average Ribbon
ma1Color = src > ma1 ? color.new(color.green, 80) : color.new(color.red, 80)
ma2Color = src > ma2 ? color.new(color.green, 80) : color.new(color.red, 80)
ma3Color = src > ma3 ? color.new(color.green, 80) : color.new(color.red, 80)
ma4Color = src > ma4 ? color.new(color.green, 80) : color.new(color.red, 80)
ma5Color = src > ma5 ? color.new(color.green, 80) : color.new(color.red, 80)
// Cálculo do ATR para Stop Loss
atr = ta.atr(sl_atr_length)
// Sinais de Compra e Venda
buySignal = ta.crossover(src, sma)
sellSignal = ta.crossunder(src, sma)
// Inicializa os níveis como variáveis persistentes
var float entryPrice = na
var float slPrice = na
var float tp1Price = na
var float tp2Price = na
var float tp3Price = na
var bool lastBuySignal = na
var bool lastSellSignal = na
// Inicializa as labels
var label entryLabel = na
var label slLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
// Atualiza os níveis quando há um sinal de compra ou venda
if (buySignal)
entryPrice := close
slPrice := entryPrice - atr * atr_multiplier
tp1Price := entryPrice + atr * tp1
tp2Price := entryPrice + atr * tp2
tp3Price := entryPrice + atr * tp3
lastBuySignal := true
lastSellSignal := false
// Remove as labels antigas
if (not na(entryLabel))
label.delete(entryLabel)
if (not na(slLabel))
label.delete(slLabel)
if (not na(tp1Label))
label.delete(tp1Label)
if (not na(tp2Label))
label.delete(tp2Label)
if (not na(tp3Label))
label.delete(tp3Label)
// Cria novas labels
entryLabel := label.new(bar_index, entryPrice, text="Entry: " + str.tostring(entryPrice), color=color.blue, textcolor=color.white, style=label.style_label_down, size=size.small)
slLabel := label.new(bar_index, slPrice, text="SL: " + str.tostring(slPrice), color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)
tp1Label := label.new(bar_index, tp1Price, text="TP1: " + str.tostring(tp1Price), color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
tp2Label := label.new(bar_index, tp2Price, text="TP2: " + str.tostring(tp2Price), color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
tp3Label := label.new(bar_index, tp3Price, text="TP3: " + str.tostring(tp3Price), color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
if (sellSignal)
entryPrice := close
slPrice := entryPrice + atr * atr_multiplier
tp1Price := entryPrice - atr * tp1
tp2Price := entryPrice - atr * tp2
tp3Price := entryPrice - atr * tp3
lastBuySignal := false
lastSellSignal := true
// Remove as labels antigas
if (not na(entryLabel))
label.delete(entryLabel)
if (not na(slLabel))
label.delete(slLabel)
if (not na(tp1Label))
label.delete(tp1Label)
if (not na(tp2Label))
label.delete(tp2Label)
if (not na(tp3Label))
label.delete(tp3Label)
// Cria novas labels
entryLabel := label.new(bar_index, entryPrice, text="Entry: " + str.tostring(entryPrice), color=color.blue, textcolor=color.white, style=label.style_label_down, size=size.small)
slLabel := label.new(bar_index, slPrice, text="SL: " + str.tostring(slPrice), color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)
tp1Label := label.new(bar_index, tp1Price, text="TP1: " + str.tostring(tp1Price), color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
tp2Label := label.new(bar_index, tp2Price, text="TP2: " + str.tostring(tp2Price), color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
tp3Label := label.new(bar_index, tp3Price, text="TP3: " + str.tostring(tp3Price), color=color.green, textcolor=color.white, style=label.style_label_down, size=size.small)
// Cálculo da Chaos Trend Line (Chaos Alligator)
jaw_length = input.int(13, title="Alligator Jaw Length")
teeth_length = input.int(8, title="Alligator Teeth Length")
lips_length = input.int(5, title="Alligator Lips Length")
jaw = ta.sma(src, jaw_length)
teeth = ta.sma(src, teeth_length)
lips = ta.sma(src, lips_length)
chaos_trend = lips + (jaw - teeth) / 2
// Determinação da cor da CTL
ctlColor = src > chaos_trend ? color.green : color.red
// Plota a Média Móvel Simples com deslocamento
plot(sma, color=smaColor, title="SMA", linewidth=2)
// Plota a Média Móvel Exponencial
plot(ema, color=emaColor, title="EMA", linewidth=1)
// Plota a Média Móvel Simples de 200 períodos
plot(sma200, color=sma200Color, title="SMA 200", linewidth=2)
// Plota as Médias Móveis do Moving Average Ribbon
plot(ma1, color=ma1Color, title="MA1", linewidth=1, style=plot.style_stepline)
plot(ma2, color=ma2Color, title="MA2", linewidth=1, style=plot.style_stepline)
plot(ma3, color=ma3Color, title="MA3", linewidth=1, style=plot.style_stepline)
plot(ma4, color=ma4Color, title="MA4", linewidth=1, style=plot.style_stepline)
plot(ma5, color=ma5Color, title="MA5", linewidth=1, style=plot.style_stepline)
// Plota Sinais de Compra e Venda
plotshape(series=buySignal and not lastSellSignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellSignal and not lastBuySignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Plota a Chaos Trend Line
plot(chaos_trend, color=ctlColor, title="Chaos Trend Line", linewidth=2)
// Condição para exibir os níveis apenas se o preço ainda não atingiu o TP ou SL
plot(entryPrice, color=color.blue, style=plot.style_linebr, linewidth=2, title="Preço de Entrada", display=display.none)
plot(slPrice, color=color.red, style=plot.style_line, linewidth=1, title="Stop Loss", display=display.none)
plot(tp1Price, color=color.green, style=plot.style_line, linewidth=1, title="Take Profit 1", display=display.none)
plot(tp2Price, color=color.green, style=plot.style_line, linewidth=1, title="Take Profit 2", display=display.none)
plot(tp3Price, color=color.green, style=plot.style_line, linewidth=1, title="Take Profit 3", display=display.none)
// Cor das velas com base na tendência
trendUp = src > ema and src > sma and src > chaos_trend
trendDown = src < ema and src < sma and src < chaos_trend
trendIndecisive = not (trendUp or trendDown)
barcolor(trendUp ? color.green : (trendDown ? color.red : color.purple))
// Alertas
alertcondition(buySignal, title="Sinal de Compra", message="Sinal de Compra!")
alertcondition(sellSignal, title="Sinal de Venda", message="Sinal de Venda!")
Neste código atualizado, a Chaos Trend Line (CTL) é calculada como a média das diferenças entre a mandíbula (jaw) e os dentes (teeth) do Alligator. Esta linha é usada para determinar a cor do gráfico de velas e também é plotada no gráfico para exibir a tendência do mercado.