Direction of OnCalculate() in MQL4 and MQL5 - page 2

 
honest_knave: The best way, given MetaQuotes propensity for inconsistent default behaviour between platforms.

Actually, that is what they instruct in the documentation as I noted above in my post.

Forum on trading, automated trading systems and testing trading strategies

Direction of OnCalculate() in MQL4 and MQL5

Fernando Carreiro, 2017.01.22 18:12

Also, according to the documentation, and I quote:

Arrays passed as a parameter to the OnCalculate() function must be checked for the order of accessing the array elements by ArrayGetAsSeries().
... or set explicitly as I do it in my code, for example.
 
honest_knave:
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   static bool HasRun=false;
   if(!HasRun)
     {
      printf("Default: time[0]=%s time[rates_total-1]=%s",
             TimeToString(time[0]),TimeToString(time[rates_total-1]));

      ArraySetAsSeries(time,true);
      printf("ArraySetAsSeries(true): time[0]=%s time[rates_total-1]=%s",
             TimeToString(time[0]),TimeToString(time[rates_total-1]));

      ArraySetAsSeries(time,false);
      printf("ArraySetAsSeries(false): time[0]=%s time[rates_total-1]=%s",
             TimeToString(time[0]),TimeToString(time[rates_total-1]));

      HasRun=true;
     }
   return(rates_total);
  }

In MT5:

 

In MT4:

 

Conclusion:

In MT5 default oldest index is [0]

In MT4 default oldest index is [rates_total-1]

Thank you very much!
Reason: