MetaTrader5
Mastering Object Manipulation in MetaTrader 5: A Guide to Hacking Indicator Objects
Hey there, fellow traders! Today, we’re diving into a neat trick that lets you tweak the objects in an indicator even if you don’t have the source code. Some indicators don’t use buffers and instead rely solely on objects, making it a bit tricky when you want to customize them. While iCustom is a lifesaver for indicators that do use buffers, what do you do when you’re dealing with objects only?
For this demonstration, we’re using a free market indicator for MT5 called PZ Multidiagonals MT5. Make sure you install this indicator from the marketplace before you start playing around with the code.
First things first, we need an object prefix name to kick off our modifications. I created a handy function called LogChartObjectNames() to log all the names of the objects that are part of the indicator.
Next up, we’ll manipulate the objects using the ModifyChartObjects() function. This function takes two parameters: the prefix name (which should match the start of a descriptive object name) and an integer that indicates how many objects you want to leave untouched.
The PZ Multidiagonals indicator is quite the trend indicator, automatically drawing trend lines, but sometimes it goes a bit overboard. Here’s what the default setup looks like:
As you can see from the data window, this indicator doesn’t use any buffers whatsoever; everything is built entirely with objects.
Now, starting from a clean chart and loading the Hacking Objects.mq5 script, you'll notice how I managed to clear away a lot of the trend lines, keeping only what I believe are the most relevant ones. And I did this not by tweaking the inputs, but by hacking the objects directly:
So there you have it! With a bit of code and creativity, you can take control of your indicators and make them work for you. Happy trading!
2024.07.17