Nicolas

RSI and Linear Regression trading signals

Category: Indicators By: Nicolas Created: September 25, 2020, 12:26 PM
September 25, 2020, 12:26 PM
Indicators
21 Comments
RSI and Linear Regression trading signals

Trading signals based upon a linear regression channel applied to a classic RSI indicator.

If the RSI exceeds the upper band, the price should reverse to its mean and therefore a sell signals is announced.

If the RSI breaks the lower band, the price should reverse to its mean and a buy signals is plotted on the indicator.

You can adjust the RSI period of calculation (with variable ‘len’) and the linear regression channel period with “period”. The upper and lower band spread can be adjusted with the “deviations” setting (default is a 2 times multiplier from the mean).

//PRC_RSILinearRegressionSignals| indicator
//25.09.2020
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from tradingview
//https://www.prorealcode.com/topic/rsi-linear-regresion/

// --- settings 
len = 21 //RSI Length
period     = 200 //Period
deviations = 2.0 //Deviation(s)
// --- end of settings 

irsi = rsi[len](close)
periodMinusOne = period-1

Ex = 0.0
Ey = 0.0
Ex2 = 0.0
Exy = 0.0
for i=0 to periodMinusOne
closeI = (irsi[i])
Ex = Ex + i
Ey = Ey + closeI
Ex2 = Ex2 + (i * i)
Exy = Exy + (closeI * i)
ExEx = Ex * Ex
next
//slope
if Ex2=ExEx  then 
slope = 0.0 
else
slope= (period * Exy - Ex * Ey) / (period * Ex2 - ExEx)
endif
ilinearRegression = (Ey - slope * Ex) / period
intercept = ilinearRegression + barindex * slope
deviation = 0.0
for i=0 to periodMinusOne
deviation = deviation + square((irsi[i]) - (intercept - slope * (barindex[i])))
next
deviation = deviations * sqrt(deviation / periodMinusOne)
startingPointY = ilinearRegression + slope / periodMinusOne
//lineColor 
if startingPointY > startingPointY[1] then 
//color.blue 
r=0
b=255
else
//color.red
r=255
b=0
endif 
a = startingPointY-deviation
c1 = startingPointY
b = startingPointY+deviation

up=irsi crosses over a
down=irsi crosses under b
if up then 
drawtext("↑ up",barindex,irsi-5,dialog,standard,20) coloured(0,255,0)
endif 
if down then 
drawtext("↓ down",barindex,irsi+5,dialog,standard,20) coloured(255,0,0)
endif
 
return irsi, a coloured(r,0,b) style(line,3)  as "curve low",c1 coloured(r,0,b) style(line,3) as "curve", b coloured(r,0,b) style(line,3)  as "curve high"

 

Download
Filename: PRC_RSILinearRegressionSignals.itf
Downloads: 940
Nicolas
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

manafull
3 years ago
#

Thanks Nicolas, I post my question, along with the codes I am trying to convert from your indicator, in the ProScreener Forum... So please review there. Thanks again.

Nicolas
3 years ago
#

I replied to your post here: https://www.prorealcode.com/topic/screener-for-rsi-and-linear-regression-trading-signals/#post-218189

manafull
3 years ago
#

Awesome work Nicolas! By any chance, do you have the Screener version for this "RSI and Linear Regression trading signals". I tried to convert the indicator to screener by replacing the drawing at the end i.e. "SCREENER[Signal](Signal AS "1=↑, 2=↓")", where I use the Signal =1 or 2 to replace the two condition of drawing in the codes ... but at the end I always get the error "Syntax error: This variable is not used in the {did not show any further info}". It would complete your indicator perfectly if you can add the screener here for us. Thank you and Best regards.

Nicolas
3 years ago
#

Please open a topic in ProScreener forum with your query, I'll reply you there. Thank you.

DonTony
5 years ago
#

Bonjour Nicolas, Très bel indicateur! Bravo!

DIOS
6 years ago
#

Bonjour Nicolas, comment coder un indicateur de rsi de Divergence? Merci pour ta réponse

Nicolas
6 years ago
#

En apprenant la programmation :) Plus sérieusement, il y a quantité d'exemples dans la library et dans les forums.

HappyBunny
6 years ago
#

You are using variables "r" abd "b" for the color red and blue but unfortunately after setting r or b to 255, you reset b with b = startingPointY+deviation Do you rely on prorealcode knowing difference between integer b (255) and floating point b (deviation), or was this a mistake?

Nicolas
6 years ago
#

good spot! indeed, that's a mistake. Change the variable name for the b color, while I don't think it would change the calculation result of the indicator itself.

bearbull
6 years ago
#

....also note in the alarm settings that for this indicator you cannot get an email email notification?

Nicolas
6 years ago
#

email notification are not available for custom indicators.

bearbull
6 years ago
#

Nicolas.......does this mean that I will now automatically have an alarm on every buy/sell signal? or will I have to manually reset it for every buy/ sell signal?

bearbull
6 years ago
#

Thank you sir!!

bearbull
6 years ago
#

how would one incorporate an alarm at the buy/sell signal?

Nicolas
6 years ago
#

Change the last line with: return irsi, a coloured(r,0,b) style(line,3) as "curve low",c1 coloured(r,0,b) style(line,3) as "curve", b coloured(r,0,b) style(line,3) as "curve high",up,down and use the alert tool from the platform with "up" and "down" returned signals.

Sofitech
6 years ago
#

I try to ad this indicator on DAX or EurUSD on M5 and on tick chart but nothing appears on the price chart. What can be the problem ?

Nicolas
6 years ago
#

Try to expand the units displayed on your chart. Or use this simplified code which is the same: https://www.prorealcode.com/topic/infinite-loop-issue/#post-146094

Abz
Abz
6 years ago
#

Hello , is it possible to use this in a MTF screener without getting this fault? This ProScreener market scan cannot be executed because there is an infinite loop within the program code. An infinite loop is a sequence of instructions which repeats itself endlessly when the code is executed. This may happen if: - the loop doesn't have a termination condition - the termination condition can never be met - the termination causes the loop to start over To run the scan, modify the code of your ProScreener.

Nicolas
6 years ago
#

Sure, please open a new topic in the ProScreener section of the forum for that specific query. Please respect the posting rules also. Thanks.

Demon
6 years ago
#

On this way of exploiting the RSI, read the article by Samuel Rondot: https://www.abcbourse.com/analyses/chronique-80_de_taux_de_reussite_sur_le_cac_40_en_15_ans-203. Thanks . How can I made a difference betteen the high and low deviation?

Nicolas
6 years ago
#

In this article, the author uses the standard deviation from the mean of the RSI, in this case this indicator is not the same, use this one instead: https://www.prorealcode.com/prorealtime-indicators/rsi-self-adjusting-bands/

ProRealCode ProRealCode
Loading...