Why in Strategy Tester ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true) returns false with an error code 4211 (ERR_CHART_NOT_FOUND)?!
Not in a tester it's all good an working. Does it mean we can not use CHART_EVENT_OBJECT_CREATE in MT4 tester (v.4.00 Build 765) ?
Here is the piece of code that does (or I should say does not do) that:
Thank you!
Hmmm, give this a try instead and see if it works. Could be either the Chart ID (though I doubt it) or the value it's expecting (bool). I'm thinking it's the bool that may be causing the problem - you're sending a value of 1:
bool result = ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);
Why in Strategy Tester ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true) returns false with an error code 4211 (ERR_CHART_NOT_FOUND)?!
Not in a tester it's all good an working. Does it mean we can not use CHART_EVENT_OBJECT_CREATE in MT4 tester (v.4.00 Build 765) ?
Here is the piece of code that does (or I should say does not do) that:
Thank you!
Use 0 instead of ChartID().
int OnInit() { //--- bool result = ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,1); if (result) Print("We are ok!"); else Print("We are NOT ok! "+GetLastError()); //--- return(INIT_SUCCEEDED); }Also you have to use this code in OnInit() instead of OnTick().
long chartID; int OnInit() { chartID = ChartID(); if ( IsTesting() ) chartID = 0; return(INIT_SUCCEDED); }Eugenio
Filter, angevoyageur and Eugenio, thank you for a very quick answer! You saved a lot of my time! I was thinking maybe instead of Boolean "true" I should use Integer "1", but that was not the issue. Indeed the issue is ChartID(), which for some reason gives a weird number in Tester. So using 0 instead of ChartID() when testing is a solution.
However, this issue is a part of a bigger whole. I was using Standard Classes, and I have a class derived from CAppDialog class, and by default if I provide ChartID as 0, some of the standard classes will reset chart id to what ChartID() function returns. So I have to change the core of Standard Classes to walk around the ChartID() issue in Tester. But even then it would not be enough, because CAppDialog uses graphical objects. For example it tries to create an OBJ_RECTANGLE_LABEL in ChartObjectsTxtControl.mqh (in CChartObjectRectLabel class). But in tester it is not allowed to create OBJ_RECTANGLE_LABEL, meaning that in Tester, I can't uses these Standard Classes (in my case CAppDialog class).
That does not sound like a good news! I need to stop using CAppDialog if the code needs to work in Tester.
Any thoughts on that?
Thank you!
Julius
Filter, angevoyageur and Eugenio, thank you for a very quick answer! You saved a lot of my time! I was thinking maybe instead of Boolean "true" I should use Integer "1", but that was not the issue. Indeed the issue is ChartID(), which for some reason gives a weird number in Tester. So using 0 instead of ChartID() when testing is a solution.
However, this issue is a part of a bigger whole. I was using Standard Classes, and I have a class derived from CAppDialog class, and by default if I provide ChartID as 0, some of the standard classes will reset chart id to what ChartID() function returns. So I have to change the core of Standard Classes to walk around the ChartID() issue in Tester. But even then it would not be enough, because CAppDialog uses graphical objects. For example it tries to create an OBJ_RECTANGLE_LABEL in ChartObjectsTxtControl.mqh (in CChartObjectRectLabel class). But in tester it is not allowed to create OBJ_RECTANGLE_LABEL, meaning that in Tester, I can't uses these Standard Classes (in my case CAppDialog class).
That does not sound like a good news! I need to stop using CAppDialog if the code needs to work in Tester.
Any thoughts on that?
Thank you!
Julius
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Why in Strategy Tester ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true) returns false with an error code 4211 (ERR_CHART_NOT_FOUND)?!
Not in a tester it's all good an working. Does it mean we can not use CHART_EVENT_OBJECT_CREATE in MT4 tester (v.4.00 Build 765) ?
Here is the piece of code that does (or I should say does not do) that:
Thank you!