Indicator coding - how change lines colors

Indicator coding: how to change lines colors in the code

How you can 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 Ichimoku indicator with non-standard settings. For example, the indicator Ichimoku looks like:

Modified version of indicator Ichimoku

This effect can be achieved, for instance, by changing the Indicator settings:

Ichimoku indicator settings

As you can see, all unnecessary lines are switched off – they are made invisibles 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 simply copy the Indicator from the terminal folder, the settings are not saved and you’ll transfer the Indicator file with default settings.

There is a solution – create a template of the actual chart and copy the template as well as the Indicator to another terminal. This method, however, has a significant shortcoming. Along with the settings of the Indicator that you need, the settings of the entire chart will be transferred, and if you have set unorthodox candlestick colors or the colors of other indicators, they can change to the colors of the source 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.

Classic ichimoku

Change lines colors in the code

Press F4 or select “MetaQuotes Language Editor” in main menu to start the code editor.

Start Metaeditor

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:

Ichimoku MQL4 code

Remember our programming lessons. The line color is set with this parameter:

#property indicator_color 1…7

As you can see in the above example, only 7 colors are set – for all Indicator lines.

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 others lines are disabled.

There is some confusion which often bewilders inexperienced programmers. Although buffers on MQL4 number from 0, in the color setting numbering starts with 1. Therefore, the desirable line is numbered 6:

Buffer 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:

Code modification

Press F7 or click “Compile”:

And look at the appearance of the indicator after the modification:

Indicator after the first 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). This 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):

Function OnInit
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.

Line width

Click “Compile” and you will see the result on the graphic:

Modified version of the Ichimoku

Thats all we wanted!

Share with a friends

About Alex Minkoff

My name is Alex Minkoff. I’ve been working on the Forex market since 2004. I am an active trader, an investor, an IT developer and have a successful experience as a financial trustee. I’m also interested in binary options trading. I am happy to offer my experience and my developments to help you achieve financial freedom!

There are no comments yet


    Check Also

    Simplest strategy of the levels (SSL)

    AOTI: Simplest Strategy of the Levels (SSL) and more…

    Today we will talk about the Simplest Strategy of the Levels (SSL) for the All-in-One ...

    Pin It on Pinterest