Our First Tests of Indicator Independence: Porting Teyacanani to Use Our TA-Lib MT4 DLL

On a previous post dealing with the unreliability of indicators on the MT4 platform we talked about how the indicator implementations within MT4/5 were “weird” and not in line with what the industry would consider the standard calculations used for the derivation of these indicators. It was evident through several examples that the code used to get internal indicator values in MT4/5 wasn’t transparent and there were some issue which made the reproduction of results on independent testing platforms a “nightmare”. From this article the idea of using an independent indicator library through a DLL – using TAlib – was proposed. Within the next few paragraphs you will get a glimpse at some of our first Asirikuy results using TA-lib and how they differ from our previous MT4/5 based implementations.

In order to make indicator usage as transparent as possible, with full access to the indicator code and the ability to reproduce the calculations on ANY platform without the risk of facing problems due to changes in the MT4/5 internal indicator implementations we decided to start a process to change our Asirikuy indicator base to TA-lib. This library is a free open source project where indicators are coded in C++ with the source available in an open way. By using TA-lib we can have reliable and transparent indicator values which allow us to develop trading systems in a very independent way from the MT4/5 platforms.

Thanks to the invaluable help of an Asirikuy member – who is helping me with the development of our C++ projects – we now have an MT4 compatible TA-lib DLL which allows us to obtain many different indicator values from this open source library. The DLL can be called from any testing platform as well as from MT4/5, allowing us to obtain reproducible indicator values – regarding the calculation in itself – without worrying about differences in implementation amongst platforms. The functions included within the DLL calculate a wide array of classic indicators going from Bollinger Bands to moving averages, the ATR, Stochastic, etc. Added to that is the fact that the TA-lib implementation is lightning fast, giving us a speed advantage over even internal MQL4 indicator calculations.

Certainly the million dollar question here is how the changes in indicators affect some Asirikuy systems. In order to find out I took the time to implement our first test by using the DLL to replace the ATR calculation within Teyacanani. Since Teyacanani only uses this indicator within its code it was the easiest EA to port since we could easily see changes coming out from the single changing of indicators from an MT4 to a TA-lib implementation. The change was done pretty easily since the DLL allows us to get indicator values with TA-lib with a very simple function call which includes the necessary array data (open, high, low and/or close) and the necessary indicator parameter values.

The results – as we would have expected – are different from those of the MT4 implementation as the optimum values for the indicator period and therefore the adaptive variables which descend from it have changed. Nonetheless the results – even on this less than optimum parameters – are still profitable although the average compounded yearly profit to maximum draw down ratio is about half of the original optimum settings on the MT4 ATR. The next step is simply to carry out the same optimization procedure with the new indicator values which makes the implementation achieve an even better result than the regular optimal Teyacanani parameters (remember that optimizations were carried out from 2000-2009 and 2010 was used as an out of sample year).

This shows that although the values of the indicator on the MT4 implementation are inherently different than those of the TA-lib implementation once you re-optimize the systems in the same fashion to take into account new TA-lib indicator values even “better than before” results can be achieved. Certainly this results do not mean that we will immediately move all of our systems and indicators to TA-lib implementations since this would require an enormous amount of work, retesting and reimplementation which is clearly not necessary right now (as we currently trade only on MT4). However when we migrate to MT5 we will take the step forward and migrate all system code to use TA-lib systems, carrying out the appropriate re-optimization procedures to make our systems use the new indicator values. Also consider that we still need to test this TA-lib implementation thoroughly to ensure it is as reliable from a simulation perspective as our current MT4 indicators.

The creation of this TA-lib DLL marks an important step in the search for more reliable and less platform dependent coding implementations, opening up the way towards the reproduction of tests and results under a wide array of different platforms and setups. With the use of this DLL to calculate indicator values independently we will be able to produce much more powerful genetic frameworks – as the C++ framework we’re currently working on – and we will be able to move our systems even to independent API solutions without the need to worry about the exact reproduction of MT4/5 indicator values.

This weekend I will probably release a video in Asirikuy explaining how to use this DLL, talking a little bit more in depth about its results. If you would like to learn more about my work in automated trading and how this TA-lib DLL works  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.

12 Responses to “Our First Tests of Indicator Independence: Porting Teyacanani to Use Our TA-Lib MT4 DLL”

  1. McDuck says:

    Daniel,
    the differences are due to different mathematical formula in MT4 v.s. TA lib, or to rounding errors?. Thx.

    • admin says:

      Hi McDuck,

      Thank you for your comment :o) As I said on the previous post we cannot know since we don’t have access to the internal MT4 implementation. I hope this answers your question !

      Best Regards,

      Daniel

      • Skyline says:

        Hi Daniel,
        each standard indicator code available for metatrader can be found in the codebase , for example the ATR source code is here http://codebase.mql4.com/source/1184 so it should be easy to compare the two algorithm calculation and check why they are so different.
        Thx for your great work with Asirikuy !! :)

        • admin says:

          Hello Skyline,

          Thank you for your comment :o) That code is the code of the indicators found within the custom indicator folder which resemble the internal indicators but we cannot trust them to be the same implementation as we simply cannot access the code of the internal indicators. If they were the same then it would reveal the fact that MT4/5 indicators are dependent on every bar of the chart as the ATR here – for example – is calculated based on all the chart’s bars (each value of the indicator depends on the value of the indicator for the past X periods). Doing the ATR calculation in this way introduces big rounding errors compared to the best way to calculate the indicators (each bar independently using OHLC data). However as I say we will never know if internal indicators are implemented in this exact same way :o) Thanks again for your comment,

          Best Regards,

          Daniel

          • Skyline says:

            Hi Daniel,
            thanks for your reply!
            Yes we cannot be sure they are the same indicators but it’s still possible to backtest the expert advisor using the iCustom function instead the iATR so to use the custom ATR and check if equity is still different.
            Btw I’m not sure to understand when you say that custom ATR routine is wrongly calculated. How is the ATR TA-Lib calulated instead ?
            Btw very interesting discussion indeed ;)

            Thank you !
            Best Regards

          • admin says:

            Hi Skyline,

            Thank you for your reply :o) I am not implying that the calculation done in MT4 is wrong but merely that it is different in nature from the one within the TA-lib implementation (which is the one formally used by most implementations out there). I think you will get a much better glimpse at this once the TA-lib DLL is released this week-end. You can also go to TA-lib’s homepage to get a look at the C++ code and how the ATR is actually calculated there.Thanks again for your comment !

            Best Regards,

            Daniel

  2. McDuck says:

    Ok, thanks.

  3. Chris says:

    Daniel-

    Thanks for advancing the state of automated forex trading on the MT4 platform – and in this case fixing problems we didn’t even knew we had!

    Keep up the good work!

    Chris

    • admin says:

      Hi Chris,

      Thank you very much for your comment :o) I am glad you like my on-going work ! As you say there are problems which we didn’t know in the past which we realize as time goes on. As always I do my best to move forward with the whole Asirikuy community :o) Thanks again for being such a faithful reader !

      Best Regards,

      Daniel

  4. Franco says:

    Nice job Daniel,

    Can’t wait for the new dll implementation!

  5. Mike says:

    Hi, is this TA-lib DLL available to the public or only to asirikuy members?

Leave a Reply

WordPress › Error

There has been a critical error on this website.

Learn more about troubleshooting WordPress.