Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy("Breakout Strategy Luca Boiardi",overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.06, slippage = 2, default_qty_value=100)
- // https://www.youtube.com/watch?v=uhS1yFKrZA4&t=1046s
- // https://it.tradingview.com/script/mC1Xu8bT/
- // Define the length of the Bollinger Bands
- bbLength = input.int (15,title="BBLength")
- bbDev = input.float (2.0,title="BBDev")
- trendfilterperiod=input(130,title="Trend Filter MA Period")
- trendfiltertype=input.string (title="Trend Filter MA Type", defval="EMA",options=["EMA","SMA"])
- volatilityfilter=input.bool(true,title="Volatility Filter")
- volatilitystdevlength=input(20,title="Vol Filter STDev Length")
- volatilitystdevmalength=input(30,title="Vol Filter STDev MA Length")
- start = timestamp(input(2018, "start year"), input(1, "start month"), input(1, "start day"), 00, 00)
- end = timestamp(input(2050, "end year"), input(1, "end month"), input(1, "end day"), 00, 00)
- TrendConditionL=if trendfiltertype =="EMA"
- close>ta.ema(close,trendfilterperiod)
- else
- close>ta.sma(close,trendfilterperiod)
- TrendConditionS=if trendfiltertype =="EMA"
- close<ta.ema(close,trendfilterperiod)
- else
- close<ta.sma(close,trendfilterperiod)
- VolatilityCondition=if volatilityfilter
- ta.stdev(close,volatilitystdevlength)>ta.sma(ta.stdev(close,volatilitystdevlength),volatilitystdevmalength)
- else
- true
- // Calculate the Bollinger Bands
- [middle, upper, lower] = ta.bb (close, bbLength, bbDev)
- // Buy if price crosses below upper Bollinger Band
- if ta.crossover(close, upper)and TrendConditionL and VolatilityCondition and time > start and time < end
- strategy.entry("Long", strategy.long)
- if ta.crossunder(close, lower)and TrendConditionS and VolatilityCondition and time > start and time < end
- strategy.entry("Short", strategy.short)
- // Sell if price crosses above lower Bollinger Band
- strategy.close("Long",when=ta.crossunder(close, lower))
- strategy.close("Short",when=ta.crossover(close, upper))
- // Plot the Bollinger Bands
- plot(upper, color = color.red, linewidth = 2)
- plot(lower, color = color.blue, linewidth = 2)
- plot (ta.ema(close,trendfilterperiod))
- plot (ta.sma(close,trendfilterperiod),color=color.yellow)
Advertisement
Advertisement