Trader’s Tech – Writing Your Own EA Part 87 – 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 86, we continued our discussion of how to program and use “drag buttons”. We’ll continue that talk more this time.

We’ve discussed the global variables that contain the details of the icons. As I mentioned the group of variables will be repeated for each icon you want to include in your EA.

In an effort to keep the init() function as brief and readable as possible, we’ll write a function specifically to deal with the icons so all we will include in the init() function is a call to that function; let’s call it InitializeIcons().

The purpose of the InitializeIcons() function will be to… wait for it… initialize the icons (funny how that works, eh?) It will include any necessary calculations to determine whether the icons will be active or passive. Then it will display the icons on the chart. Since displaying the icons will be a regular event, we’ll write a few separate functions to perform that activity as well. InitializeIcons() can be a simple and straightforward function. In your EA, you may want to do more with it. For the purposes of this discussion, I’m going to add a simple global boolean variable for each icon that stores whether the specific icon is active or not:

bool iconMoveActive;

You may have other criteria that determines the active/passive status of your icons. Or you may not even have active/passive status at all. Again, for the purposes of this discussion, the CalculateIcons() function will determine the active/passive status of each icon.  I’ll leave that to you to determine those criteria and that function.

Here is an example of our InitializeIcons() function:

void InitializeIcons()
   {
   CalculateIcons();
   ShowIcons();
   } //void InitializeIcons()

 

We start by calculating the active/passive status of the icons. Then we come to the important function ShowIcons(). We’ll write this in such a way that we can reuse it later in the EA:

 

void ShowIcons()
   {
   DeleteIcons();

   ShowIcon("Move",iconMoveActive);
   ShowIcon("Hide",iconHideActive);
   ShowIcon("Buy",iconBuyActive);
   ShowIcon("Sell",iconSellActive);

   }  //void DisplayIcons()

 

You’ll notice I start by deleting all the icons. This will ensure that any residual “stuff” is removed from the chart when you start. Then it’s a simple matter of calling a function I call ShowIcon() that will handle the details of showing the icon. I usually just use the singular for the new function name. It makes sense to me. It may be confusing, though, so you may want to use a different function name such as ShowIconItem() or something to display the individual icons. I just find the extra typing unnecessary.

Next time we’ll talk about the ShowIcon() and DeleteIcons() functions. Thanks for your attention and please follow me on Twitter and LinkedIn.

Tim

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