Download MetaTrader 5

iMAonArray not working

To add comments, please log in or register
Domenico
8
Domenico  

I'm trying to call this function with an array of RSI values to find the EMA but it's not working properly, always return 0.0 no matter which shift I choose. I can ensure the array gets properly filled with correct RSI values

It works fine if I make the same exact thing with closing prices

Any help appreciated, thanks in advance

int OnInit()
{
   double RSI_values[];
   ArrayResize(RSI_values, Bars, 0);
   ArraySetAsSeries(RSI_values, true);
   for(int i=0; i < Bars; i++)
   {
       RSI_values[i] = iRSI(Symbol(), NULL, RSI_period, RSI_applied_price, i);
   }

   double EMA = iMAOnArray(RSI_values, 0, 17, 0, MODE_EMA, 0);
   Alert(EMA);
}
whroeder1
15581
whroeder1  
Do it in OnTick when there is a chart which values.
Domenico
8
Domenico  
WHRoeder:
Do it in OnTick when there is a chart which values.

It seems to work and I can't thank you enough, could you please explain why?

I can't figure out how this is possible

honest_knave
Moderator
2327
honest_knave  

From here

It is not recommended to call start() from init() or to perform trade operations from init(), because during initialization values of information environment parameters may be not ready (information about charts, market prices and so on).
To add comments, please log in or register