Page 1 of 1

Regression slope strategy

PostPosted: Wed May 15, 2019 8:04 am
by isamegrelo
Please create strategy from this code:

strategy("Regression", overlay=false)

src = input(defval=close, title="Source")

per = input(defval=50, minval=0, title="Sampling Period")

smper = input(defval=10, minval=1, title="Smoothing Period")

RS(x, t)=>
indx1 = n
indx2 = pow(n, 2)
a1 = sum(indx2, t) - pow(sum(indx1, t), 2)/t
a2 = sum(indx1*indx2, t) - (sum(indx1, t) * sum(indx2, t))/t
a3 = sum(pow(indx2, 2), t) - pow(sum(indx2, t), 2)/t
y1 = sum(x*indx1, t) - (sum(x, t)*sum(indx1, t))/t
y2 = sum(x*indx2, t) - (sum(x, t)*sum(indx2, t))/t
avindx1 = sma(indx1, t)
avindx2 = sma(indx2, t)
avsrc = sma(x, t)
b2 = ((y1*a3) - (y2*a2))/(a3*a1 - pow(a2, 2))
b3 = ((y2*a1) - (y1*a2))/(a3*a1 - pow(a2, 2))
b1 = avsrc - b2*avindx1 - b3*avindx2
qr = b1 + b2*indx1 + b3*indx2
RS = qr - qr[1]
RS
rs = ema(RS(src, per), smper)

Take_Profit = input(80)
Stop_Loss = input(80)

longCondition = crossover(rs, 0)
if (longCondition)
strategy.entry("LongEntry", strategy.long)
strategy.exit("LongExit", "LongEntry", profit = Take_Profit, loss = Stop_Loss)

shortCondition = crossunder(rs, 0)
if (shortCondition)
strategy.entry("ShortEntry", strategy.short)
strategy.exit("ShortExit", "ShortEntry", profit = Take_Profit, loss = Stop_Loss)

Re: Regression slope strategy

PostPosted: Fri May 17, 2019 8:11 am
by Apprentice
Your request is added to the development list under Id Number 4663

Re: Regression slope strategy

PostPosted: Tue May 21, 2019 9:22 am
by Apprentice