Download MetaTrader 5

My indicator value seems incorrect in MT5 strategy tester

To add comments, please log in or register
toliuchen
13
toliuchen  

Hello,

 I wrote a function in MT5 to get the value of indicator ATR like this:

double mATR(int days)

   {

   double ATR[];

   int ATR_handle;

   ATR_handle=iATR(NULL,0,days);

   CopyBuffer(ATR_handle,0,0,1,ATR);

   ArraySetAsSeries(ATR,true);

   return(ATR[0]);

   } 

But I noticed that it get incorrect value when running EA in strategy tester, the EA and result as follows:

#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
int x=1;
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
   if(x==1)
     {
      Print(mATR(20));
      x=0;
      }
   }
//+------------------------------------------------------------------+
double mATR(int days)
   {
   double ATR[];
   int ATR_handle;
   ATR_handle=iATR(NULL,0,days);
   CopyBuffer(ATR_handle,0,0,1,ATR);
   ArraySetAsSeries(ATR,true);
   return(ATR[0]);
   }

 Strategy tester result: EA result in strategy tester

Actual ATR value:Actual ATR value 

 

I'm confused about this, my EA cannot work in MT5 tester.  :(

Is there anybody can help me? Thanks! 

To add comments, please log in or register