In Part 84, we wrapped up the discussion of detecting price action’s presence within a graphical rectangle object. This time around we’ll talk about what I’ve come to call “drag buttons”.
One of the things that was left out of MQL4, was any data input type functionality. I’m going to spare you having to listen to one of my MT4 rants, but it would be nice if there was some sort of text input field and button. There are a number of workarounds, but the simplest to implement and the most reliable is the drag button. The drag button is a little tedious to use, especially for the uninitiated, but once you’ve gotten used to it, it’s better than nothing.
For the more advance programmers in our readership, I know it’s possible to detect a mouse-click event using Windows DLLs, then determining mouse location and so on, but I’m trying to keep this on a beginner’s level for right now. I actually think the best way to solve this problem would be to implement a Windows desktop control panel tied to all your MT4 platforms, but that’s an article series for another time.
A “drag button” is an icon (label, graphical object, etc. for the purposes of my “drag buttons” I call them all icons) that resides in a set position on your chart. To “activate the icon” (my terminology for “clicking the button”), you select it and click and drag it out of position. The action is not quite as simple as clicking a button, since you have to double-click to select it (you can select with a single click if you check the “Select object by single mouse click” checkbox in Tools/Options/Objects), then click and drag the object (hence my name “drag button”.)
To program for a drag button, you have to do the following steps:
Called from the init() function:
1) Assign the location for the icon(s).
2) Assign the look of the icon(s).
3) Draw the icon(s).
Called from the deinit() function:
Delete the icon(s). If you use my object naming standards (or something similar), this will be handled automatically by the generic DeleteAllObjects() function.
Called from the start() function:
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.
Next time we’ll look at the code to handle these actions. Thanks for your attention and please follow me on Twitter and LinkedIn.
Winner’s Edge Trading, as seen on: