OnChartEvent() not called in Expert Advisor (EA)

 

When I press a key in the testing chart, OnChartEvent() does not display the Print message in the Tester Journal tab for the following simple EA (not an indicator). Any ideas why and how to fix it?

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
   Print("EA OnChartEvent()");

}

 

no smiley and no other indicators. This is what I see after I start the EA and press a some keys in the chart: https://scr.hu/AJadXD

int OnInit() {
   Print("OnChartEventEA initialized.");
   return INIT_SUCCEEDED;
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
   Print("OnChartEventEA OnChartEvent " + id);
}

 
OnChartEvent does not work in the strategy tester when testing EAs
 

@GumRai,

1) what is your source of information?

This link says: "The function can be called only in Expert Advisors and indicators"

And this link contains seemingly working examles, but they do not work when I run them in the Strat Tester.

2) Do you mean that OnChartEvent for EAs may work in some other cases, and if so in which?

 

As GumRai has stated, when testing EA's, the "OnChartEvent()" does not work (it only works in "real-time", not in the "Strategy Tester").

However, depending on what kind of Chart Event you are trying to implement, some of them can be "simulated" with some extra code. In the following post, I used some code to simulate and check when a button is clicked: https://www.mql5.com/en/forum/149901

 
nikolaygmt:

@GumRai,

1) what is your source of information?


My experience with testing code that uses OnChartEvent in the strategy tester.
 

@GumRai, thank you! I asked just in case to make sure that I am not missing important documentation. And obviously I just had such an experience and I am learning from it :)

@FMIC, thanks for clarifying that it does not work in the StratTester, but works in real-time. And for the link!

I wanted to react to key presses and instead of the EA, implemented the reaction in an indicator, that I attach additionally to the chart while testing. If the source code for the event reaction is abstracted into separate mqh files, one could easily (not so hard) switch the source code for the EA for the two cases: 1) Strategy Tester and 2) Real time.

Reason: