## Regression slope strategy

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

### Regression slope strategy

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)
isamegrelo
FXCodeBase: Initiate

Posts: 114
Joined: Mon May 29, 2017 3:36 pm

### Re: Regression slope strategy

Your request is added to the development list under Id Number 4663

Apprentice
FXCodeBase: Confirmed User

Posts: 28461
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: Regression slope strategy

Apprentice
FXCodeBase: Confirmed User

Posts: 28461
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia