A watermark is text you can add to the background of your chart to help annotate any piece of information you deem necessary for the chart’s background. Some useful purposes of a watermark on a chart could be to annotate: the period, or symbol, or current time of the chart.

By using a watermark and controlling its position on your chart it can easily display this essential information without being too obtrusive.

For example, here is a watermark I created to help display the time and symbol of the chart:

1 hour GBPUSD chart with watermark

Watermark on MQL4 chart displays time period and symbol

How can you display a watermark on your chart?

There are several functions needed to display a watermark on your chart. You initially start with the ObjectCreate method, and then apply additional properties to that object. Much of what you need can be found from the example on OBJ_LABEL on MetaTrader’s website. If you certainly need more detail than the code provided below be sure to check it out.

To code your watermark on your charts you need to determine what information you would like to display.

For the purposes of this example, I will create a watermark that is static - it will not change as price changes. Therefore, because of its nature I will create a function and then call this function in the onInit() method.

Watermark function

Here is the function in its entirety, for you to use it alongside your existing code you would need to extract the function createWatermark() and then call it within your onInit() method. Lastly, you would need to create the three external variables height_pixels, width_pixels, and font_size.

The reason for those three variables being external is that it makes it easier for you to change the values from the chart directly by right clicking and then selecting Expert Advisors > Properties > Inputs.

Therefore, the following code places a watermark feature of the chart’s time and symbol and places it in the centre of the chart:

What font can you use?

MetaTrader only uses the fonts available on your Windows system. To see what fonts are available navigate to Control Panel / Appearance / Fonts.

Here you will see a list of font’s available and their names. Simply copy the name of the font you want to use and in the code above where you see this line:

// set the font
ObjectSetString(0, name, OBJPROP_FONT, "Arial");

Change the string "Arial" to whatever you would prefer, such as "Courier New".

Can You Have More Than 1 Watermark on a Chart?

You may want to display information vertically, or you may want to display a watermark in the upper-right corner and lower-left corner. If you’d like to display more than one piece of data on your chart you can do so with some slight modifications to the code.

If we modify the main inputs of our function and transform them as parameters then our chart can display an array of multiple watermarks:

Here is the result:

1 hour EURUSD chart with multiple watermarks

Create multiple vertical watermarks on your chart

By changing your code a little you can now call the watermark as many times as you wish:

createWatermark(width_pixels, height_pixels, font_size, txt, name);

Conclusion

In this post you discovered how to create a watermark feature on your charts to make it easier to read essential information about the chart. This feature is very handy when you are taking screenshots of your chart and are reviewing the performance of your trading system.

Depending on how you want your watermark to appear the free code above can help you position your watermark according to the dimensions you input into the Expert Advisor properties.

You also can add multiple watermarks if needed to your code and position them individually according to the parameter values you set.

A watermark is a great way to define the core information about your chart.