Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

//@version=5

strategy("Bollinger Bands Strategy", overlay=true)


source = close
length = input.int(20, minval=1)
mult = input.float(2.0, minval=0.001, maxval=50)
basis = ta.sma(source, length)
dev = mult * ta.stdev(source, length)
upper = basis + dev
lower = basis - dev
buyEntry = ta.crossover(source, lower)
sellEntry = ta.crossunder(source, upper)
longstop = ta.lowest(low,1) - 3
shortstop = ta.highest(high,1) + 3

if buyEntry
strategy.entry("long", strategy.long, stop=lower, oca_name="BollingerBands",
oca_type=strategy.oca.cancel, comment="long")
strategy.exit("SL",stop=longstop,when=buyEntry,comment="SL")
if sellEntry
strategy.entry("short", strategy.short, stop=upper,
oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="short")
strategy.exit("SL",stop=shortstop,comment="SL")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2,
style=plot.style_areabr)

plot(upper, title="upper", color=color.red,linewidth=1,style=plot.style_linebr)


plot(lower, title="lower", color=color.red,linewidth=1,style=plot.style_linebr)
plot(basis, title="media", color=color.blue,linewidth=1,style=plot.style_linebr)

You might also like