The Need for Platform Independence: Analyzing the Odd MT4 Indicator Implementations

When you develop strategies using Metatrader 4 you quickly become dependent on the indicator implementations within this trading platform. For most people this wouldn’t seem to be a very significant problem – since the indicators seem to be pretty standard – but after doing some analysis on the MT4 indicator implementations it becomes apparent that the indicators values derived from MT4 are hard – an sometimes seemingly impossible – to reproduce on independent testing solutions. After spending a few weeks with the development of FreePascal and C++ implementations to reproduce MT4 testing results it seems that this problem is quite important, especially if your strategies are indicator dependent. Through the following few paragraphs I will talk to you about the indicator dependency problem and how we can solve it using independently developed non-MT4 indicators.

When I started developing systems for the Metatrader 4 platform one of the last things on my mind was the reproducibility of the indicators which come preloaded with this piece of software. The indicators seem to be very standard – like an RSI or stochastic oscillator – and it therefore seems pretty straight forward to get the same results on any different implementation provided that you code the indicators correctly (as they are publicly known in technical analysis literature). However when it was time to take some of this indicator values and test them on a C++ framework -something brought to my attention by two different Asirikuy members – a situation started to arise where indicator values did not match those on MT4. My independent tests to reproduce this on FreePascal yielded the exact same results, even though all attempts have correctly coded indicators (and they do match each other!). Below a comparison between TA-lib and MT4 calculated ATR values (provided by an Asirikuy member).

It was quite surprising to see that a calculation as simple as an RSI can give results which are so different between MT4 and independent calculations using the exact same data set. It seems that metatrader 4 does something to calculate indicators which it is not telling us which seems to significantly skew our calculations. I took the greatest care when implementing the indicators on FreePascal, using the exact same logic as you find within the custom indicator code snippets found within the MT4 installation (which match the internal indicators on the platform). However – time and time again – I couldn’t get a match on the indicators.

It is true that the values of some indicators – like the RSI – have globally the same makeup with only slight -yet important – fluctuations, but others such as the Average True Range are almost entirely different when compared with the internal ATR implementation. Even when using professional open source indicator code to calculate the values (TA-lib) we find that the values are completely different to those calculated within MT4. Curiously enough my calculations on FreePascal do match TA-lib, something which points to something obscure being done behind the curtains within MT4.

You would think then that this problem is irrelevant (since we use indicator values within MT4) but the truth is that the problem is very relevant since platform changes (even to MT5) become very difficult if indicator values tend to mismatch. This means that systems would need to be re-optimized for each new platform in order to find the equivalent settings with the new indicator calculation types. However this very annoying problem has a very elegant solution which is the way in which we will evolve into the future with Asirikuy.

Since right now we know that reproducing MT4 indicator values can be quite hard, it becomes necessary to find a platform independent indicator solution which is open source and provides us with the necessary indicator values whenever we need them. This has the flexibility of allowing us to port our systems to whichever type of execution we want (MT4, MT5, independent API, etc) knowing that the calculated values of our indicators will always correspond to the exact same mathematical formula and the results will always be the same within the same data set.

For this reason we are currently in the process of implementing a DLL – which implements TA-lib indicator definitions — which will be called from any type of application, allowing us to retrieve indicator values according to some reliable definitions which are widely used in both practical quantitative trading solutions and academia. This DLL will also provide us with a good way to transition between MT4-MT5 and even future independent direct platforms using a broker’s API. It will also allow us to make our trading systems independent of internal changes within the MT4 internal indicators – which can happen on platform updates if the people at Metaquotes want to – and they will allow us to perform external testing using our much more powerful C++ testing solutions.

When this solution is done we will implement it across all indicator-dependent Asirikuy systems, reoptimizing for one last time to get in line with the independent indicator codes. If you would like to know more about my work in automated trading and how you too can develop indicator based systems with sound profit and draw down targets please consider joining Asirikuy.com, a website filled with educational videos, trading systems, development and a sound, honest and transparent approach towards automated trading in general . I hope you enjoyed this article ! :o)

Print Friendly, PDF & Email
You can leave a response, or trackback from your own site.

6 Responses to “The Need for Platform Independence: Analyzing the Odd MT4 Indicator Implementations”

  1. Maxim says:

    Daniel,

    Who could think that this is the case!
    Have you communicated this finding to Metaquotes?

    Maxim

    • admin says:

      Hello Maxim,

      Thank you for your comment :o) I was also very surprised to see this was the case and I don’t seem to be able to find what I am doing different. It may be something related to calculations (related to rounding or something like that) or to the way in which some internal MT4 functions work. Nonetheless I believe the people at Metaquotes won’t be interested since they are the only ones who now the true nature of this and perhaps even introduced this on purpose to keep people’s trading implementations tied to their platforms. Even if they didn’t and wanted to make their indicators match TA-lib they wouldn’t probably change their current implementations as they would affect the trading of many people who rely on the current MT4 internal indicators. As I said on the article it is much better to move to an independent open source solution which we totally control and understand :o) Thanks again for your comment Maxim,

      Best Regards,

      Daniel

  2. erick says:

    have also read that indicators in the custom indicator mt4 folder set are “slower” that the standard mt4 indicators.

  3. Al says:

    Hi Daniel,

    This is a great catch! Thanks you.

    Even if there’s a perfectly reasonable explanation for the differences you’ve found (so far), I think that a 3rd-party open source indicators will be a better and safer direction anyhow.

    Thanks again.

  4. plamen says:

    I started digging the net about this problem when today I found out that MT4’s SMA differs almost 1% from my SaxoTrader and FXCM TS2 platforms?!?!?! I got pictures, but here are the figures (today is 22 March 2011):

    SMA(200) /Simple, Closed/: NZDUSD Daily, 21 March 2011:
    SaxoTrader: MA = 0.74134
    FXCM TS2: MA = 0.74135
    MT5: MA = 0.74104 (?)
    MT4: MA = 0.7476 (??!!!??)

    The diefference in MT4 is so obvious that it is almost a half bar above the last one while on other platforms it crosses the top third of the that bar (the last one).

    Any ideas? (different MT4 brokers tested).

    Oh, btw, Stochastic slow is the same. Didn’t check other indicators.

    Weird.

Leave a Reply

WordPress › Error

There has been a critical error on this website.

Learn more about troubleshooting WordPress.