MT5 backtester returning different values than visual tester

 
int corr_handle;
double Close[];
double Close2[];


int OnInit()
  {

   corr_handle = iCustom(Symbol(),Period(),IndicatorName,OverLay);

   return(INIT_SUCCEEDED);
  }

void OnTick(){
   int copy;
   ArraySetAsSeries(Close,true); 
   ResetLastError(); 
   CopyBufferAsSeries(corr_handle,3,0,1,true,Close2);

   Print("Close[0] is " + Close[0]);
   Print("Close2[0] is " + Close2[0]);
}

bool CopyBufferAsSeries( int handle, // indicator's handle int bufer, // buffer index int start, // start index int number, // number of elements to copy bool asSeries, // if it's true, the elements will be indexed as series double &M[] // target array ) { //--- filling the array M with current values of the indicator if(CopyBuffer(handle,bufer,start,number,M)<=0) return(false); //--- the elements will be indexed as follows: //--- if asSeries=true, it will be indexed as timeseries //--- if asSeries=false, it will be indexed as default ArraySetAsSeries(M,asSeries); //--- return(true); }


Basically, it prints out proper values in the visual tester for Close2[], but nonsense values when run through the backtester.

Am I missing something?

 
Jose Francisco Casado Fernandez:
Where is CopyBufferAsSeries() function ??

Sorry I left that out. Added it in.

 
I had the same problem in MT4. ArraySetAsSeries, is like a local variable, you can't set it in a function and have it effect the caller/callee.
#property strict
#define test(a,b) PrintArrayMA(iMAOnArray(a, 0, 1, 0, MODE_SMA, 0),a,b)
void PrintArrayMA(double b, const double& array[], bool t){
   ArraySetAsSeries(array, t);
   double a[];    ArraySetAsSeries(a, true);    ArrayCopy(a, array);
   double array_ma = iMAOnArray(array, 0, 1, 0, MODE_SMA, 0);
   double a_ma     = iMAOnArray(a,     0, 1, 0, MODE_SMA, 0);
   PrintFormat("bef=%g array={%g,%g,%g} ave=%g a={%g,%g,%g} ave=%g", 
               b, array[2], array[1], array[0], array_ma,
                  a[2],     a[1],     a[0],     a_ma);   }
void OnStart(){
   double sa[]={1,2,3,4}; // not series
   test(sa,1);  // bef=4 array={2,3,4} ave=4 a={2,3,4} ave=4      ns r to l/pass no diff/set breaks copy
   test(sa,0);  // bef=4 array={3,2,1} ave=4 a={3,2,1} ave=1      passed array must be set correctly for copy.
   ArraySetAsSeries(sa,true);   for(int i=0; i<4; ++i) sa[i]=i+1;
   test(sa,1);  // bef=1 array={3,2,1} ave=1 a={3,2,1} ave=1      series=ok/pass no diff/
   test(sa,0);  // bef=1 array={2,3,4} ave=1 a={2,3,4} ave=4      passed array must be set correctly for copy.
}
 
whroeder1:
I had the same problem in MT4. ArraySetAsSeries, is like a local variable, you can't set it in a function and have it effect the caller/callee.

wow. That's really odd behavior. Thanks!

Reason: