Facebook
From RyoAsukae, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 95
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © RyoAsukae
  3.  
  4. //@version=5
  5. strategy(title = "Regression-Strat", shorttitle="Reg-Strat", overlay=true,initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity)
  6.  
  7. src = close
  8. l1 = 25
  9. l2 = 200
  10. l3 = 600
  11.  
  12. lin1 = ta.linreg(close,l1,0)
  13. lin2 = ta.linreg(close,l2,0)
  14. lin3 = ta.linreg(close,l3,0)
  15. slope1 = (lin1 - lin1[l1])/l1
  16. slope2 = (lin2 - lin2[l2])/l2
  17. slope3 = (lin3 - lin3[l3])/l3
  18.  
  19. above = ta.crossover(close,lin1) and slope2 > 0 and slope2 > slope3 or ta.crossover(0,l1) or ta.crossover(lin2,lin3)
  20. below = ta.crossover(lin1,close) and slope2 < 0 and slope2 < slope3 or ta.crossover(l1,0) or ta.crossover(lin3,lin2)
  21.  
  22. trueRange = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
  23. sensitivity = input(1.0,"Sensitivity")
  24. atr = trueRange/sensitivity
  25.  
  26. short = below and ta.atr(10) >= atr
  27. long =  above and ta.atr(10) >= atr
  28.  
  29. p = input(50,"TP")
  30. l = input(50,"SL")
  31. Y = input(2021,"Year")
  32. M = input(1,"Month")
  33. D = input(1,"Day")
  34.  
  35. date = time >= timestamp(syminfo.timezone,Y,M,D,0,0)
  36.  
  37. strategy.entry("long",strategy.long, when = long and date)
  38. strategy.exit("exit","long",loss = l,profit = p)
  39.  
  40. strategy.entry("short",strategy.short, when = short and date)
  41. strategy.exit("exit","short",loss = l,profit = p)
  42.