Trader’s Tech – Writing Your Own EA Part 76 – Chart Objects

Forex Robot

Hahaha! Who was I kidding, it’s not cooling off here yet! 😉

If you’re new to this series and want to check it out from the beginning, you can find that here. And look here for a list of all the programming articles.

In Part 75 we wrapped up our discussion of arrays. This time I’m going to follow up on my promise to talk about some tricks for placement of chart drawing objects.

When I discussed the DrawVersion() function in our generic start code, I told you I would give you some tips on object placement. Here they are:

  • Remember that MT4 uses the very top row of the chart for prices and EA names, so it’s best to leave the top 20 pixels or so blank.
  • Remember the corners are numbered from top to bottom, left to right starting from 0. The way we read English.
  • When creating OBJ_LABEL objects using ObjectCreate(objName,OBJ_LABEL,0,0,0), ObjectSet(objName, OBJPROP_XDISTANCE, 10) and ObjectSet(objName,OBJPROP_YDISTANCE,20), remember that the X distance (horizontal) and Y distance (vertical) are measured in pixels from the corner of the chart specified by ObjectSet(objName,OBJPROP_CORNER,0). In our generic DrawVersion() function (slightly modified) for example:
void DrawVersion(string Version)
   string name = "EPIC_Version";
   } //void DrawVersion()


This creates an object named EPIC_Version, 5 pixels right and 2 pixels up from the lower left corner of the chart. The object contains the value of the string variable Version that has been passed to the function as a parameter. It uses the Verdana font with a font size of 8. The OBJ_LABEL object type ignores the Price and Time parameters in the ObjectCreate() function and gets placed according to the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE instances of the ObjectSet() function.

  • OBJ_LABEL objects placed in either of the two right corners will be right-justified. Those placed in either of the left two corners will be right-justified. The only way to get them to align differently would be to use a monospace font and format them as strings with space padding for proper placement.
  • You can use the Comment() function to easily print some text on the chart without going through the fancy ObjectCreate() functions. This is a good quickie way to put something on the chart. It’s inelegant and hard to read, but it’s simple. You can put up to 64 parameters in the function (separated by commas) and they will be printed in the upper left corner. Variables of type double will be displayed with 4 digits after the decimal point. You can use DoubleToStr() to have more control. For proper display of datetime values, you will want to use the TimeToStr() function (we’ll talk more about conversion functions in a future installment.) You can have your comment move to the next line by using a linefeed character (“\n” – enclosed in quotes.)

We’ll continue discussion of object placement in our next installment. Thanks for your attention and please follow me on Twitter and LinkedIn.


The following two tabs change content below.
Winners Edge Trading was founded in 2009 and is working to create the most current and useful Forex information and training available on the internet.

Winner’s Edge Trading, as seen on:

Winner's Edge Trading in the news