How to Change Lines Colors in the MQL Source Code

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:

Ichimoku Indicator Modified Version

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

Ichimoku Indicators 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.

Ichimoku Classic Indicator

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

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

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 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). 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):

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

What we wanted!

Good Luck & Big Profits


About MAFX Solutions:

We provide Trading Systems, Expert Advisors, and Indicators for trading. With over 20 years of experience in trading, programming, and refining trading systems and strategies, we are excited to share our expertise with you. Discover exclusive trading products, along with a wealth of tips, tricks for profitable trading, and additional opportunities to boost your profits.

✔️ OVER 20 YEARS of experience in trading and programming trading algorithms
✔️ HIGH-QUALITY CODE and the latest innovations in trading algorithm development
✔️ UNIQUE TRADING ALGORITHMS and regular updates and improvements to our products
✔️ DETAILED MANUALS for our products and regularly updated educational materials for both beginners and experienced traders
✔️ LOTS OF POSITIVE FEEDBACKS and satisfied clients

Follow the News:
Back to top button