Calculating Relative Strength index for 2 Moving Averages's Difference New comment (passing Array into Function)
I hope to be grasping correctly what you're trying to achieve. If we understand the standard version of the RSI as the
"ratio of the rolling n-period averages of the up-moves vs. down-moves of the close price, adjusted to a 0-100 scale",
then what you're probably trying instead is the
"ratio of the rolling n-period averages of the positive vs. negative MA changes, adjusted to a 0-100 scale"
Am I summarizing correctly so far? And why not? I think it's an interesting idea.
What I think is strange though in this context is, that you only count the up-moves and down-moves of the MA (via assigning ones and zeros) instead of taking the actual quantitative value, which would resemble more the usual concept of the RSI
for(int i=0;i<CalPeriod-1;i++) // this only makes sense if the index [CalPeriod-1] stands for the unfinished current candle, that you want to exclude from the calculation [which may be the case] { //get value of MAh1 and MAh4 value MA1_array[i] = InpMA1_array[i]; MA2_array[i] = InpMA2_array[i]; MADiff_array[i] = NormalizeDouble(MA1_array[i] - MA2_array[i],4); //pass the MADiff_array value to MANegative and Positive array base on their value MAPosDiff_array[i]=MathMax(0,MA1_array[i]-MA2_array[i]); MANegDiff_array[i]=MathMax(0,MA2_array[i]-MA1_array[i]); //ArraySetAsSeries(MANegDiff_array,true); //ArraySetAsSeries(MAPosDiff_array,true); } //Compute the average double AverageNegMADiff = NormalizeDouble(ArrayAverage(MANegDiff_array),4); double AveragePosMADiff = NormalizeDouble(ArrayAverage(MAPosDiff_array),4); double MAdiffRS = NormalizeDouble(100-(100/(1+AveragePosMADiff/AverageNegMADiff)),2); ........ ........
[I didn't look through all the rest of the code]
I hope to be grasping correctly what you're trying to achieve. If we understand the standard version of the RSI as the
"ratio of the rolling n-period averages of the up-moves vs. down-moves of the close price, adjusted to a 0-100 scale",
then what you're probably trying instead is the
"ratio of the rolling n-period averages of the positive vs. negative MA changes, adjusted to a 0-100 scale"
Am I summarizing correctly so far? And why not? I think it's an interesting idea.
What I think is strange though in this context is, that you only count the up-moves and down-moves of the MA (via assigning ones and zeros) instead of taking the actual quantitative value, which would resemble more the usual concept of the RSI
[I didn't look through all the rest of the code]
Thanks @Chris70 for your comment. Your understanding is indeed correct. I have opted back to actual quantitative value as per your suggestion (dummy {0.1} is initially chosen to reduce the small value change bias, but the 0-100 scale have actually cover for that).
Update: I have overcome the indicator display problem and now get the indicator worked as expected. I also add the 'trending' component into the MaRS to identify the trend up/ trend down of the MaRS (i.e. comparing the current value of MaRS with the average value of MaRS of the last x bars). The only problem I have is that the indicator seems taking a long time to load whenever I drop it on the chart. Can any one take a look at my code and suggest any optimization to help my indicator load faster. Thanks
Andre

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I am writing an indi on 2 Moving Average-cross and compute the Relative Strength Index (RSI) on the difference between these MAs. Basically it will measure the oscillation of the "Difference" between MovingAverage1 and MovingAverage2 (MaDiffRS). The codes is as below. The idea is to compute the 2 MAs and when the counter i pass over the RS's period (InpTIMEFRAME_RS).
I got stuck at getting the MaDiffRS at it return no value on the terminal. Can you check and advise what is wrong. I believe it may be caused by passing the MaLine1Buffer and MaLine2Buffer arrays into the function MAValidatorChk incorrectly but not sure.
Main part of the indicator:
Extern part:
Initialize part: