bandas de bollinger y estocastico tradingview

 


//@version=5 script tradingview

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 la anterior y por debajo de las bandas de bollinger

// parametros: lower bandas de bollinger, k y d estocastico

long_signal = close [1< lower [1and k < 20 and d < 20 and d < k

short_signal = open [1> upper [1and k > 20 and d > 20 and d > k


//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)