CopyBuffer Error in Tester

 
handleATR = iATR(_Symbol, PERIOD_D1, 20);
ArraySetAsSeries(arrayATR, true);
if(CopyBuffer(handleATR, 0, 0, 40, arrayATR) < 0)
{
   Alert("ERROR: unable to copy atr. exiting...");
   return(false);
}

cannot copy atr data. Initialization returns false. how can i solve this problem? if I disable this part it works normally.


OnInit as following;

int OnInit()
{
  if(!Initialization())
  {
  return(INIT_FAILED);
  }
 return(INIT_SUCCEEDED);
}
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
Mokara:

cannot copy atr data. Initialization returns false. how can i solve this problem? if I disable this part it works normally.


OnInit as following;

Hi,

i think the issue may be connected  with the array you want to store the ATR into 

arrayATR

What is the size of this array ?

If you havent set the size of it, the issue is most probably because its size is 0,and youre pushing 40 elements into it

 
Mokara :

cannot copy atr data. Initialization returns false. how can i solve this problem? if I disable this part it works normally.


OnInit as following;

In OnInit, you can (and should) create an indicator handle.

But you need to receive data from the indicator (using CopyBuffer) in OnTick ().


Do not be lazy to show the complete MQL5 code. Do not be lazy to format the code correctly: name and code extension ...

 
Solved. copybuffer shouldn't be called inside OnInit().