// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RyoAsukae
//@version=5
strategy(title = "Regression-Strat", shorttitle="Reg-Strat", overlay=true,initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity)
src = close
l1 = 25
l2 = 200
l3 = 600
lin1 = ta.linreg(close,l1,0)
lin2 = ta.linreg(close,l2,0)
lin3 = ta.linreg(close,l3,0)
slope1 = (lin1 - lin1[l1])/l1
slope2 = (lin2 - lin2[l2])/l2
slope3 = (lin3 - lin3[l3])/l3
above = ta.crossover(close,lin1) and slope2 > 0 and slope2 > slope3 or ta.crossover(0,l1) or ta.crossover(lin2,lin3)
below = ta.crossover(lin1,close) and slope2 < 0 and slope2 < slope3 or ta.crossover(l1,0) or ta.crossover(lin3,lin2)
trueRange = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
sensitivity = input(1.0,"Sensitivity")
atr = trueRange/sensitivity
short = below and ta.atr(10) >= atr
long = above and ta.atr(10) >= atr
p = input(50,"TP")
l = input(50,"SL")
Y = input(2021,"Year")
M = input(1,"Month")
D = input(1,"Day")
date = time >= timestamp(syminfo.timezone,Y,M,D,0,0)
strategy.entry("long",strategy.long, when = long and date)
strategy.exit("exit","long",loss = l,profit = p)
strategy.entry("short",strategy.short, when = short and date)
strategy.exit("exit","short",loss = l,profit = p)
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}