Advertisement
Maurizio-Ciullo

Breakout Strategy Luca Boiardi

Feb 21st, 2023
1,385
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. //@version=5
  4. 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)
  5.  
  6. // https://www.youtube.com/watch?v=uhS1yFKrZA4&t=1046s
  7. // https://it.tradingview.com/script/mC1Xu8bT/
  8.  
  9.  
  10.  
  11. // Define the length of the Bollinger Bands
  12. bbLength = input.int (15,title="BBLength")
  13. bbDev = input.float (2.0,title="BBDev")
  14.  
  15. trendfilterperiod=input(130,title="Trend Filter MA Period")
  16. trendfiltertype=input.string (title="Trend Filter MA Type", defval="EMA",options=["EMA","SMA"])
  17.  
  18. volatilityfilter=input.bool(true,title="Volatility Filter")
  19. volatilitystdevlength=input(20,title="Vol Filter STDev Length")
  20. volatilitystdevmalength=input(30,title="Vol Filter STDev MA Length")
  21.  
  22. start = timestamp(input(2018, "start year"), input(1, "start month"), input(1, "start day"), 00, 00)
  23. end = timestamp(input(2050, "end year"), input(1, "end month"), input(1, "end day"), 00, 00)
  24.  
  25. TrendConditionL=if trendfiltertype =="EMA"
  26.     close>ta.ema(close,trendfilterperiod)
  27. else
  28.     close>ta.sma(close,trendfilterperiod)
  29.    
  30. TrendConditionS=if trendfiltertype =="EMA"
  31.     close<ta.ema(close,trendfilterperiod)
  32. else
  33.     close<ta.sma(close,trendfilterperiod)
  34.  
  35. VolatilityCondition=if volatilityfilter
  36.     ta.stdev(close,volatilitystdevlength)>ta.sma(ta.stdev(close,volatilitystdevlength),volatilitystdevmalength)
  37. else
  38.     true
  39.  
  40. // Calculate the Bollinger Bands
  41. [middle, upper, lower] = ta.bb (close, bbLength, bbDev)
  42.  
  43. // Buy if price crosses below upper Bollinger Band
  44. if ta.crossover(close, upper)and TrendConditionL and VolatilityCondition and time > start and time < end
  45.     strategy.entry("Long", strategy.long)
  46.  
  47. if ta.crossunder(close, lower)and TrendConditionS and VolatilityCondition and time > start and time < end
  48.     strategy.entry("Short", strategy.short)
  49.  
  50. // Sell if price crosses above lower Bollinger Band
  51.  
  52. strategy.close("Long",when=ta.crossunder(close, lower))
  53.  
  54. strategy.close("Short",when=ta.crossover(close, upper))
  55.  
  56. // Plot the Bollinger Bands
  57. plot(upper, color = color.red, linewidth = 2)
  58. plot(lower, color = color.blue, linewidth = 2)
  59. plot (ta.ema(close,trendfilterperiod))
  60. plot (ta.sma(close,trendfilterperiod),color=color.yellow)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement