drawing objects on charts from an EA

 

I'm almost embarrassed asking this seemingly trivial question, as I am an experienced programmer, however the answer has evaded me for over a week now.   I am trying to get to the bottom of an EA of mine, and I was wanting to plot some graphics objects on the chart where I'm running the EA. 

I'm simply wanting to plot a line on the chart, basically an indicator, but it has to be drawn from the EA during a backtest.

I wrote my own drawing functions, then discovered these libraries, which i thought was great, however I still run into the same issues:

#include <ChartObjects\ChartObjectsLines.mqh>

#include <ChartObjects\ChartObjectsTxtControls.mqh>

 

The issue is that I run my EA over a certain time period.  The EA runs, it should be creating objects, then the chart opens, and the only objects on the chart are the trades taken (arrows, and trendlines).

After much messing about with no luck, I got rid of my complex EA, and decided to just plot a line and some text (in the init function) and do this on every new bar.   I've discovered a few things which seem a little wierd, which is why my code below contains certain features... 

- chart doesn't open up after the EA (to view our objects) unless you have a trade.  I therefore added in a trade so the chart would open.  However i've never seen any objects drawn on the chart from my EA (except the ones MT5 puts on automatically for the trades the EA takes).

 

The code attached, should write some text on the chart at a certain position.  It should also draw a line connecting up the lows of the bars. 

I would appreciate so much if someone can tell me what is wrong with my approach.  I've read all the docco i can find, i thought it might have something to do with window numbers, etc, and a bunch of other things, but everything I've read seems to indicate that what I've done is okay.  There's obviosuly something wrong.

I would love to know:

1) what is wrong with my code

2)  is there a better way to draw a line like an indicator from an EA, with buffers or something?  It seems a little silly to be having to create so many different objects for a line plot on the chart. 

3) Does anyone have some code that plots a line like what I am doing from an EA.

The important part here is i need it to be plotting from the EA when running a backtest.   Indicators and other things are no good to me.

 

thanks so much for your help...

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Documentation on MQL5
Files:
 
Just wondering if anyone has any suggestions on this, or if anyone can comment on whether they have been able to draw objects on a chart from a backrest. Thanks
 

Objects drawing in backtest seems like it could be disabled to save resources...

An alternative will be to create text-file or similar simple way of storing data, and have the backtest dump the results once it is completed. You can then use such a file in a script which can put the results of generated file on your chart in your desired form.

I haven't looked at code yet but it seems like just the type of thing MQL5 doesn't support yet. 

 

Hi Lugner, 

Thanks for the comments.    Possibly could be what's going one.  That would make sense based on what I've observed, however VERY frustrating.   If so I really wish that was documented in the help files for the object creation things.

 I wonder if anyone from the MT5 developers/ admin can comment /  confirm that this is the case. 

Or if there's some setting I can change somewhere to enable the object creation during backtest.

 

Thanks for the suggestions thoguh, and I'll probably dump to a text file and plot in another software.  However, this seems a very silly and limiting feature if this is the case.  I am SURE that there will be a bunch of people wanting to draw on charts during a backtest.  As mentioned, from the point of view of debugging and verifying EAs it's invaluable.   For example, in MT4 I regularly drew objects to show where I varied SL points in complex trailing strategies, etc.

 

thanks

 

"Visual Backtest" from my observation here is a subject MetaQuotes guys are not commenting on so much as of yet/lately; there are many requests for such a feature, and I think for now the this similar concept you have is being overlooked.

I'm sure the capability will be there soon; I would plan for your project to have such functionality but (for now) to look on to some other functions of your program...

Reason: