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

Forex Robot 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 87, we continued our discussion of how to program and use “drag buttons”. We’ll continue that talk more this time.

Let’s start this time with a discussion of the DeleteIcons() function. It’s pretty straightforward:


void DeleteIcons()
   }  //void DeleteIcons()


That’s all there is to it. I’ve used DeleteIcon() for the individual icon deletion routine. As with the ShowIcon() function, it may be a little confusing to have the plural and singular of the function, so you may want to use DeleteIconItem() instead. That’s your call. As I mentioned, I just don’t think the extra typing is necessary. It may be unnecessary to have another level of function to do this, but it will allow you to add further functionality to this with ease. In this case, the only information you need to pass to the DeleteIcon() function is the name. It will be the job of the DeleteIcon() function to add the prefixes and so on:

void DeleteIcon(string name)
   string fname = StringConcatenate(Prefix,"icon",name);

   }  //void DeleteIcon(string name)


Very simple, but for a crazy organizer like myself it seems right to have it in a separate function. What can I say? Now on to the ShowIcon() function:

void ShowIcon(string name, bool active)
   string Name = StringConcatenate(Prefix,"icon",name); 
   string Text; 
   int Row,Col,Corner;
   color Color;

   if(name == "Move")
      Row = iconMoveRow;
      Col = iconMoveCol;
      Corner = iconMoveCorner;
      Text = "iconMoveText";

         Color = iconMoveActiveColor;
         Color = iconMovePassiveColor;
      }  //if(name == "Move")

   if(name == "Hide")
      Row = iconHideRow;
      Col = iconHideCol;
      Corner = iconHideCorner;
      Text = "iconHideText";

         Color = iconHideActiveColor;
         Color = iconHidePassiveColor;
      }  //if(name == "Hide")

   if(name == "Buy")
      Row = iconBuyRow;
      Col = iconBuyCol;
      Corner = iconBuyCorner;
      Text = "iconBuyText";

         Color = iconBuyActiveColor;
         Color = iconBuyPassiveColor;
      }  //if(name == "Buy")

   if(name == "Sell")
      Row = iconSellRow;
      Col = iconSellCol;
      Corner = iconSellCorner;
      Text = "iconSellText";

         Color = iconSellActiveColor;
         Color = iconSellPassiveColor;
      }  //if(name == "Sell")


   }  //void ShowIcon(string name, bool active)


Yes, there are other, maybe better, ways to do this. Like storing all the icon info in a group of arrays or something. I would  just rather have descriptive variable names. It all goes back to that “will I understand what I wrote in six months” mentality.

The first step is declaring the variables for the actual object creation. Then assigning the values for each of the variables based upon the name that has been passed to the function. Then we get to the actual meat of the function, the object creation.

As we’ve discussed object creation is a multi-step process. You first create the object with ObjectCreate(). Then you assign values for the various parameters that further describe your object. If you have a text-based object (OBJ_LABEL, OBJ_TEXT), you will use the ObjectSetText() function to set the text. Notice that I have used a couple more global variables for the font size and font type of the text.

Then use the ObjectSet() function to assign values for the OBJPROP_CORNER, OBJPROP_XDISTANCE (column) and OBJPROP_YDISTANCE (row) of the icon. As I’ve mentioned before, OBJPROP_CORNER describes the corner of the chart from which to measure (0, 1, 2, or 3) and the X and Y distances are measured in pixels.

Using anything but OBJ_LABEL type objects is not feasible for drag buttons. The object you use must be tied to the chart window rather than the price action. The OBJ_LABEL object is the only one I know of that is window based. You should be able to find whatever icon you want to use in the Wingding font set if straight text is not acceptable.

That wraps the code necessary for the init() function. We’ll talk about the icon code for the deinit() and start() functions next time. 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