MQL Script for Charts Synchronization

24 October 2016, 12:32
Stanislav Korotky
2
194
Traders do often work with many charts simultaneously. And one of common use cases is when they need to compare 2 charts visually. This is handy, for example, if you test an expert adviser and want to view multiple resulting charts (for different parameters) side by side. Of course, they should be for the same symbol/timeframe, shifted to the same bars, and use the same time scale. While symbol/timeframe is not an issue since you use common tester settings, aligning the charts by bars and scaling them accordingly may become a boring repetitive task. Unfortunately MetaTrader does not provide a convenient tool for chart synchronization (people familiar with graphics editors may think of it as of a lock/combine tool, which sticks together multiple layers or figures).

This is why traders try to automate the synchoronization between charts using MQL and external libraries. Some of them are heavy and feature-rich (which seems an overkill for me), and some are not open source (and I think most of you prefer an open source solution than a black box). As a result, I made a little utility script, which helps me in solving this issue. Its source code is attached. It's tested in MetaTrader 4, but should hopefully work in MetaTrader 5 as well. 

MetaTrader 4 charts synchronization using MQL script

The usage is simple. Drop the script on charts you want to synchronize. All charts for the same symbol/timeframe running the script will automatically adjust themselves to position and scale applied manually to any one of them. The time of refreshes is defined in the source as half of a second, but you may change it to your needs. Please note that increasing the number of synchronized charts may lead to noticable delays in refreshes and higher CPU usage.

Bar alignment is made by first (leftmost) visible bar. If you need to use rightmost bar as the synchronization point, feel free to adjust the source appropriately.

Files:
synchro.mq4 3 kb
Share it with friends: