In Part 85, we began a discussion of how to program and use “drag buttons”. We’ll talk more about that this time.
Starting with the init() function duties, we need to talk about assigning a location for your icons. There are several factors to consider when locating your icons.
- Will they interfere with price action, indicators or status displays?
- How big will your icons be?
- Is there a location that’s more “convenient” for your icon, e.g. near a spot where your mouse will already be?
- If you have icons that should be grouped together, what are their overall dimensions?
I often place status displays on the right most side of the chart because you can use the “chart shift” capabilities of MT4 to shift the leading edge of your chart to the left. If you don’t use large status displays, this might be a good place to position your icons. If your icons are rather small (single character), you might be able to line them up across the top or bottom of the chart. You may even consider opening a small indicator window below your chart window just to put your icons in an out of the way place (we’ll discuss how to do that in a future article.)
One thing I do, is place the initialization for the variables holding the X and Y pixel locations of the icons near the top of the code – or even make them external variables – so it’s easy to move the icons when you discover that you picked a really lousy place to put them.
Also, since there are several variables associated with each icon and since there are usually several icons involved, I have a naming convention for them:
int iconMoveCorner = 0; int iconMoveRow = 0; int iconMoveCol = 530; string iconMoveName = "iconMove"; string iconMoveText = "Move"; color iconMoveActiveColor = Blue; color iconMovePassiveColor = LightGray;
This would be the variable initializations for an icon I’ve called Move. The three integers represent the home location for the icon. I use Row and Column because it immediately means something to me. Even though I’ve been steeped in engineering and mathematics all my life, I still have to stop and think about X being the horizontal axis and Y being the vertical axis. So I use Column and Row instead. But that’s just me. 😉
I assign a name for the object. Of course, when the object is actually created, I will add the EA’s prefix to the name as always. Next I assign the text of the icon. This can be a single wingding character if you like. To use a wingding character, say #164 for example:
string iconMoveText = CharToStr(164)
Now when you use the string variable iconMoveText in your ObjectSetText() function (we’ll get to that shortly), it will use the #164 character for the text.
Lastly, we assign two colors. I have a color for an icon that is active and one that is not active. Your plan may never include an inactive or passive icon, so you may not need that color. But my latest project was a trade management EA that would activate and deactivate icons based on when their use made sense and when it didn’t. You can’t keep the user from clicking and dragging an icon, but you can at least give him a visual cue that the icon will do nothing when moved.
Next time we’ll get into the object creation code. Thanks for your attention and please follow me on Twitter and LinkedIn.
Winner’s Edge Trading, as seen on: