bollinger y estocastico tradingview

 entrada alza:

a. vela cierra debajo de la banda de bollinger inferior
b. estocastico: linea verde supera a la linea roja


//@version=5
indicator("md bandas de bollinger y estocastico", shorttitle = "BBEST", overlay = true)

//bandas de bollinger
length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

ma(source, length, _type) =>
    switch _type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

//estocastico
periodK = input.int(14, title="%K Length", minval=1)
smoothK = input.int(1, title="%K Smoothing", minval=1)
periodD = input.int(3, title="%D Smoothing", minval=1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
plot(k, title="%K", color=#2962FF)
plot(d, title="%D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")

// señal alza cuando cierra vela debajo de banda bollinger inferior (lower)
// estocastico k y d menor a 20
// estocastico k y d se cruzan
long_signal = close [1] < lower [1] and k < 20 and d < 20 and k < d
short_signal = close [1] > upper [1] and k > 80 and d > 80 and k > d

//alertas
alertcondition(long_signal, title = "BBEST largo", message = "largo")
alertcondition(short_signal, title = "BBEST corto", message = "corto")
//alertas en grafico
plotshape(long_signal,  textcolor=color.lime, color=color.lime, style=shape.triangleup , title="compra" , text="compra" , location=location.belowbar,  offset=0, size=size.small)
plotshape(short_signal, textcolor=color.red,  color=color.red, style=shape.triangledown, title="venta", text="venta", location=location.abovebar,  offset=0, size=size.small)