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

We’ll skip the deinit() function since we covered it’s only call,  the DeleteAllObjects() function here.

When I mentioned the functions called from the start() function, I meant more specifically that these functions should be called at every market tick. As I’ve said in the past, I like to keep the start() function clear of riff-raff. I want the start() function to be an overall outline of the program, easy to read and decipher. I don’t put much in the way of real program code in the start() function. I just call the functions that do the heavy lifting.

That having been said, the only thing that will actually reside in the start() function regarding icons might be a function named CheckIcons(). That allows someone perusing the code to understand what it does, without inundating them with a bunch of details they’ll have to decipher. And by someone, I mean you, the programmer, in six months when you are called on to add a small modification to your program and you have no clue how it all works. 😉

So it falls on the CheckIcons() function to perform the three activities I mentioned at the start:

1) Detect when an icon is out of place.
2) Move the icon back to it’s assigned location
3) Perform whatever actions are called for by the icon movement.

Well, here’s the cool part. We’ve already written the second function. We called it ShowIcons(). So let’s take a look at the CheckIcons() function:

bool CheckIcons()
   bool IconMoved = false;

         //Perform stuff that happens when the Move icon is moved
         }  //if(iconMoveActive)
      IconMoved = true;
      }  //if(IconMoved("Move")

         //Perform stuff that happens when the Move icon is moved
         }  //if(iconHideActive)
      IconMoved = true;
      }  //if(IconMoved("Hide")

         //Perform stuff that happens when the Move icon is moved
         }  //if(iconBuyActive)
      IconMoved = true;
      }  //if(IconMoved("Buy")

         //Perform stuff that happens when the Move icon is moved
         }  //if(iconSellActive)
      IconMoved = true;
      }  //if(IconMoved("Sell")

   //Move the icons back in place   

   }  //void CheckIcons()


Even though we’re not using this functionality in our current code, I’m going to return a boolean from this function to let the caller know if an icon had been moved. Since we have to keep track of whether an icon has been moved so we can reset the icons, we may as well pass that information back to the caller. Remember, just because a function is declared with something other than void (which is used when the function doesn’t return a value), doesn’t mean we actually have to use the value in the calling function.

This, again, is a fairly straightforward function. It tests each icon for movement. If there is movement, it tests to see if the icon is active. If the icon is moved and active, it performs whatever functions are appropriate for the icon. After it finishes that, it sets the boolean variable IconMoved to true.

After we’ve checked all the icons for movement, if icons are out of place we execute the ShowIcons() function to put them back. As you know, that function deletes the icons and redraws them in their assigned locations.

Next time we’ll wrap our discussion of “drag buttons”. 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