Indicator on indicator calculation

 
Hi all,

I'm having a problem calculating the moving average of the RSI. I thought that I had the code right, but, the values I'm returning from the code are different than what I'm getting in the indicator window. I've attached a screenshot (yes, I'm having similar problems with the Bollinger Bands median line - one problem at a time, though.)

For the screenshot, look at the first "RSIMA Vals:". The first value should be the current one and should match up with the "MA(8)" value in the indicator window. The subsequent "RSIMA Vals:" values should be previous MA values.

The RSIMA val being calculated on period 0 is 36.797. But, the indicator window is showing 42.7375. The RSI value is correct.

Also, the solid blue line in the indicator window is the RSI, the dashed orange line is the EMA applied to the RSI.



Here's the code I'm using to run my calculation:

double rsiMAVal()
{
  int RSIMAPeriod = 8; // use an 8 period EMA on the RSI
  int RSIPeriod = 8; // use an 8 period RSI
  double rsi[8]; // create an array to hold the RSI values
  for(int i=0;iRSIMAPeriod;i++)
  rsi[i]=iRSI(Symbol(),0, RSIPeriod, PRICE_CLOSE,i); //populate RSI array
  double ma = iMAOnArray(rsi, 0,RSIMAPeriod,0,MODE_EMA,0); //find current MA value of RSI
  return(ma);
}
 
This problem has been resolved. https://www.mql5.com/en/forum/46093
 
stockwet wrote:
This problem has been resolved. https://www.mql5.com/en/forum/46093

Hi Stockwet, I don't understand your solution in https://www.mql5.com/en/forum/46093. I am hoping your can clear some things up. In the following, what is the value of shift? I think the value of your RSIPeriod must be 8, right? Also, what about RSIMAPeriod, what is the value of that?

double rsiMAVal(int shift)
{
  double rsi[];
  ArrayResize(rsi, Bars);
  ArraySetAsSeries(rsi,true);
  for(int i=Bars; i>=0; i--)
  {
  rsi[i]=iRSI(Symbol(),0, RSIPeriod, PRICE_CLOSE,i+shift);
  }
  double ma = iMAOnArray(rsi,0,RSIMAPeriod,0,MODE_EMA,0);
  return(ma);
}
Finally, when you say

double ma = iMAOnArray(rsi,0,RSIMAPeriod,0,MODE_EMA,0);
How does this line know what to look up?
Thanks
Steve