OnChartEvent() not called in Expert Advisor (EA)

Back to topics list To post a new topic, please log in or register
avatar
62
nikolaygmt 2016.05.21 18:36
 

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()");

}


avatar
62
nikolaygmt 2016.05.21 21:47 #
 

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);
}


avatar
Moderator
3423
GumRai 2016.05.21 23:54 #
 
OnChartEvent does not work in the strategy tester when testing EAs
avatar
62
nikolaygmt 2016.05.22 00:12 #
 

@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?

avatar
1223
FMIC 2016.05.22 00:13 #
 

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://forum.mql4.com/61246#1033252


avatar
Moderator
3423
GumRai 2016.05.22 00:31 #
 
nikolaygmt:

@GumRai,

1) what is your source of information?


My experience with testing code that uses OnChartEvent in the strategy tester.
avatar
62
nikolaygmt 2016.05.22 00:50 #
 

@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.

Back to topics list  

To add comments, please log in or register