// 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)