Is OnChartEvent() actually called during a "Stratagy Tester - Visual Testing" mode session?

 

Hi,

I've written an Expert that contains a few graphical buttons to enable me to change certain trading parameters "on-the-fly". I then want to be able to press these buttons during a Strategy Tester - Visual Tester mode session.

According to the documentation in https://www.mql5.com/en/docs/runtime/testing#objects :

"When testing in an EA, we can handle custom events using the OnChartEvent() function..."

and:

"

Graphical Objects in Testing

During testing/optimization graphical objects are not plotted. Thus, when referring to the properties of a created object during testing/optimization, an Expert Advisor will receive zero values.

This limitation does not apply to testing in visual mode.


"

Having created the Expert, I'm unfortunately running into problems trying to use it within the visual tester. The buttons are created in the OnInit() handler of the Expert and these buttons appear as they should in the visual tester. However, when the buttons are pressed, the coded button functionality doesn't run (it obviously does run if I attach the Expert to a normal live chart).

After a bit of playing around, it appears that contrary to the documentation, the OnChartEvent() handler doesn't actually appear to be called during a chart event when the Expert is run within the visual tester? For instance, if I run the following Expert on a normal chart, the messages  "*** Expert Started ***" and "***Chart Event received***" get printed in the log when the Expert is started and the chart is clicked on. If the Expert is run in the visual tester however, the message "*** Expert Started ***" is printed in the log but any clicks on the chart result in nothing...


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
    Print("*** Expert Started ***");
    return 0;
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
    Print("*** Chart Event received ***");
}    


Am I missing something here or is this a bug? Any help with this would be greatly appreciated..

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
MQL5 programs / Testing Trading Strategies - Reference on algorithmic/automated trading language for MetaTrader 5
 

Bugs should be reported to ServiceDesk.

Please keep us posted.

 
Alain Verleyen:

Bugs should be reported to ServiceDesk.

Please keep us posted.


Thanks Alain - have passed this onto the Service Desk. Will keep you updated re. the outcome...
 

Hi Alain,

Just letting you know that this issue has (finally) been confirmed as a bug by MetaQuotes. The "OnChartEvent()" event handler definitely doesn't get called when it's used within an Expert running in "Visual Simulation" mode (works fine on a live chart). It does however, get called if the event handler is placed within an Indicator and then that Indicator is run within a "Visual Simulation" mode session.

Metaquotes aren't able to provide a fix date, so it'll just be a matter of keeping an eye on the release notes I guess...

 
cowil:

Hi Alain,

Just letting you know that this issue has (finally) been confirmed as a bug by MetaQuotes. The "OnChartEvent()" event handler definitely doesn't get called when it's used within an Expert running in "Visual Simulation" mode (works fine on a live chart). It does however, get called if the event handler is placed within an Indicator and then that Indicator is run within a "Visual Simulation" mode session.

Metaquotes aren't able to provide a fix date, so it'll just be a matter of keeping an eye on the release notes I guess...

Thank you :-)
 

Problem accessing buttons from a panel.

Within tester environment OnChartEvent() does not work. Eventhandling must be in the onTick() function

If I have the button directly created in onInit() it is no problem to access the button from onTick()

 if(ObjectGetInteger(0,"CloseButton",OBJPROP_STATE)==true)
        {
         CloseOpenPosition();
         ObjectSetInteger(0,"CloseButton",OBJPROP_STATE,false);
        }

But the problem:

If I have a Panel with buttons I cannot get reference of the buttons of the panel from the onTick() function.

Somebody knows how to reference a button in a panel?

 
Terence Gronowski:

Problem accessing buttons from a panel.

Within tester environment OnChartEvent() does not work. Eventhandling must be in the onTick() function

If I have the button directly created in onInit() it is no problem to access the button from onTick()

But the problem:

If I have a Panel with buttons I cannot get reference of the buttons of the panel from the onTick() function.

Somebody knows how to reference a button in a panel?

I'm assuming that you are creating a panel using CAppDialog, and the button is of type CButton.

These standard library functions create regular graphical objects, just like a button you would create manually.

Simply load the panel, right-click->Object properties->List all

You will see all buttons created by the panel there. They are prefaced with an ID, which changes, but you can either chase that down in the code or use StringSubstr() to find.

buttons

Reason: