How can you modify the Indicator code so it displays only those lines that you need, or the lines have the required thickness and colors immediately when the Indicator is set? Today we’ll see what the solution to the problem is.
One day, in one of the trading systems, I met the Ichimoku indicator with non-standard settings. For example, the indicator Ichimoku looks like:
This effect can be achieved, for instance, by changing the Indicator settings:
As you can see, all unnecessary lines are switched off – they are made invisible using the None attribute. The main line thickness is set at 2 points with Blue color.
Now the settings are fixed in the active terminal version for the Indicator. What shall we do, however, if we need to transfer the Indicator to another terminal or send it to a friend?
If you copy the Indicator from the terminal folder, the settings are not saved, and you’ll transfer the Indicator file with default settings.
One solution is to create an actual graphic template. After that, copy the template and indicator to another terminal and apply the template on the new chart. This method, however, has a significant drawback. Along with the necessary indicator settings, the settings of the entire chart will be transferred, and if non-standard candle colors or the colors of other indicators are set on your chart, they can change to the colors of the original chart.
What’s the way out here? It is pretty simple and universal! If your Indicator in the .mql4 format is the source code, modifications can be performed in it directly. Let’s consider step-by-step how it can be done.
To begin with, let’s see how Ichimoku Indicator looks in MetaTrader 4.
Change Lines Colors in the Code
Press F4 or select “MetaQuotes Language Editor” in main menu to start the code editor.
Choose the desired indicator in the Navigator window and click twice on it with the left mouse button. Remember that to modify the indicator code, it must have the source code –.mq4 format.
That’s what we’ll see in the main editor window:
Remember our programming lessons. This parameter changes the color of the line:
#property indicator_color 1…7
As you can see from the above example, all seven lines of the indicator have their color.
We need to keep on just a single line, switching off the other 6 lines; setting it with the Blue color and 2-point thickness.
How can we find out the color of which line must be changed and what line we need to keep at all — indeed, there are 7 lines! Perhaps it is possible to search through and switch off all lines one by one: it is also an option when we did not see the desirable setting of the Indicator.
In this case, you remember, we saw the settings:
At the 5th line – is blue color, while other lines are disabled.
Some confusion often bewilders inexperienced programmers. Although buffers on MQL4 number from 0, in the color setting, the numbering starts with 1. Therefore, the desirable line is numbered 6:
Let’s switch off the remaining lines simply changing the color parameter to clrNONE.
Enter the desired color that we need for the desired line – clrBlue.
That’s what we’ll see:
Press F7 or click “Compile”:
And look at the appearance of the indicator after the modification:
A single line remains, but it is not exactly what we need – the indicator line is dashed and is not very noticeable. Let’s make it solid and increase the thickness.
To this purpose, we must scroll the window with the indicator code to void OnInit (void). It is the Indicator initializing code – it defines the buffer settings and line appearance.
Remember now that buffers are numbered from 0, so here we are interested in No.5 buffer (highlighted with yellow):
STYLE_DOT – sets the line appearance as dotted. We need to change it to STYLE_SOLID – a solid line.
Put a comma right after the new parameter and set the line thickness – 2.
Click “Compile” and you will see the result on the graphic:
What we wanted!