CopyBuffer Oninit Tester - Not Working

 

Hi,

I want to do some analysis of the data within the Oninit() function before entering the execution. The data I want to analyze are the ones of an indicator and for this reason I am using the CopyBuffer function:

handle = iCustom(_Symbol, PERIOD_CURRENT, "Custom\\indicator.ex5");
double buffer[];
CopyBuffer(handle, 0, 0, 1000, buffer); 

Improperly formatted code edited by moderator.

Whereas everything is working perfectly when I attach the EA at the live chart, I am facing a problem when testing the EA on the strategy tester: the buffer is just filled with 0 (and not with the indicator values).

Any suggestion?

 
EdoardoBerardo: I want to do some analysis of the data within the Oninit() function before entering the execution.

I suggest you don't do that. That is not the purpose of the OnInit event handler and there is no guarantee there will be data available at the time, and you should not be holding up the initialisation procedure.

EdoardoBerardo: I am facing a problem when testing the EA on the strategy tester: the buffer is just filled with 0 (and not with the indicator values).

Instead, process it on the first tick, in one of the other event handlers, after all the data has finished loading correctly.

 

Please always use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Fernando Carreiro #:

I suggest you don't do that. That is not the purpose of the OnInit event handler and there is no guarantee there will be data available at the time, and you should not be holding up the initialisation procedure.

Instead, process it on the first tick, in one of the other event handlers, after all the data has finished loading correctly.

Thanks Fernando, very helpful. Would you know how to increase the history to retrieve as well? In live I can use Copybuffer to source 1'000'000 data (or even more), whereas in the tester the maximum that is achieved is around 500'000 (even if I use the same period as of today, so it is not a matter of missing historical data). Also, I need to make the code sleep for 60 seconds after taking the data before moving to the execution, but this is no more considered now.