OPEN-SOURCE SCRIPT

3 VCT + SMA200

32
//version=5
indicator("3 VCT + SMA200", overlay=true)

// SMA200
smaLength = 200
sma200 = ta.sma(close, smaLength)
plot(sma200, "SMA200", color=color.orange, linewidth=2)

// Condiciones de velas
isBullish = close > open
isBearish = close < open

// Contador de velas consecutivas
var contraCount = 0

if (close > sma200) // Tendencia alcista → buscamos 3 velas bajistas
if isBearish
contraCount += 1
else
contraCount := 0

else if (close < sma200) // Tendencia bajista → buscamos 3 velas alcistas
if isBullish
contraCount += 1
else
contraCount := 0

// Señal cuando se cumplan 3 consecutivas en contra
signal = (contraCount == 3)

// Mostrar en gráfico
plotshape(signal, title="Señal 3 velas", style=shape.labeldown,
text="", location=location.abovebar,
color=color.red, size=size.tiny, textcolor=color.white)

// Crear condición de alerta
alertcondition(signal, title="3 Velas Contra Tendencia",
message="Se han formado 3 velas en contratendencia respecto a la SMA200.")

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.