Menu

#87 ADX function

closed-works-for-me
Bug (61)
5
2014-08-19
2009-01-27
Joao Matos
No

Hello,

I've been using Tradery (www.tradery.com) which uses your lib.
When comparing the ADX(14) function with TradeStation's I found that they are different.
TradeStation's starts having a value on the 14th while yours only returns a value on the 27th bar.

My e-mail is joao.matos (a) inet.com.pt in case you need more details.
I would appreciate if you could send me an e-mail if/when you correct this bug.

Thx,

João Matos

Discussion

  • Mario Fortier

    Mario Fortier - 2009-01-28

    It is expected that ADX(14) have a lookback of 27 (and returns a value on the 28th bar, I assume here you did an off by one mistake).

    Here is a cut&paste of an answer that I just provided to Adrian from tradery.com:

    ________________________________________
    From: Mario Fortier [mailto:XXXXX]
    Sent: Tuesday, January 27, 2009 8:35 PM
    To: adrian@XXXXXX
    Subject: RE: Question about ADX
    Hi Adrian,

    To validate the algo, I recommend to use Wilder’s book.

    I advise to not use Tradestation as a reference. Tradestation algo are (surprisingly) often “different” when it comes to smoothing logic. I found a few algo that starts the smoothing way too early. I suspect they did that to minimize “visual empty space” at the beginning of their chart.

    Metastock does the same. As an example, their EMA calculation always starts on the second price bar, regardless of the period (they use the first price bar as the “previous EMA”).

    ==

    The comments in the TA-Lib source code is pretty much what you find in Wilder’s book, and I will use that to demonstrate why the lookback of ADX(10) is 19.

    http://ta-lib.svn.sourceforge.net/viewvc/ta-lib/trunk/ta-lib/c/src/ta_func/ta_ADX.c?view=markup

    The example is to calculate ADX(14).

    The first TR1 requires two price bar (lookback is 1=2-1)
    The first TR14 is the summation of the first 14 TR1 (lookback is 13=14-1)
    TR14 is used for the +DI14 and –DI14 calculation.
    +DI14 and –DI14 are used to calculate DX14
    The first ADX14 is the sum of the first 14 DX14 (lookback is 13=14-1)

    (When I wrote DX in the source code comments I meant DX14).

    Putting it all together, we end up with a lookback equal to (14-1)+(14-1)+(2-1) = (Period * 2)-1

    It is then expected that ADX(10) will have a lookback of 19.

    ==

    I have tested my implementations against examples provided in Wilder’s book, so I am quite confident about this.

    ATR is a totally different algo. It is the smoothing of true range. So the lookback is equal to (period-1) for the smoothing plus a fix lookback of 1 for the first TR1. Meaning (Period-1)+1=Period

    It is then expected that ATR(10) will have a lookback of 10.

    ==

    Because the lookback formula is specific to each function, you should not make any assumption like “expected lookback is equal to the period parameter”.

    It is not even true for a trivial example such as SMA, where the lookback is Period-1.

    ==

    There is no significant changes for the C/C++ users at this time to justify a new TA-Lib release. I have chosen to release only if a significant bug is found or if about 10 new TA functions are added. In other word, I will release only when it will be worth for the users to upgrade.

    \Mario

    From: Adrian Michel [mailto:XXXXXX]
    Sent: Tuesday, January 27, 2009 4:50 PM
    To: 'Mario Fortier'
    Subject: Question about ADX

    Hi Mario,

    I hope all is well with you.

    I have a question for you. One tradery.com user noticed that when he calculates the ADX indicator, it will generally have more values set to 0 than the period, for example, ADX( 10 ) will generate the first 19 bars 0. The expectation was that you would get 10 bars set to 0 - he ran a test in tradestation and he got this behavior.. Is this as intended in ta-lib, or is it a bug?

    BTW, I'm using the exact same code internally for the ATR indicator, and this one generates the expected result, so ATR( 10 ) will have the first 10 values set to 0, so it seems to be specific to the ADX indicator.

    BTW, when are you planning to release the new version of ta-lib?

    Thanks,

    Adrian

     
  • Mario Fortier

    Mario Fortier - 2009-01-28
    • status: open --> closed-works-for-me
     
  • Joao Matos

    Joao Matos - 2009-01-28
    • status: closed-works-for-me --> open-works-for-me
     
  • Joao Matos

    Joao Matos - 2009-01-28

    Hello,

    Thanks for the explanation.
    The values of ADX(14) is also different between the 3 apps (Tradery, TradeStation and Metastock).
    Do you know if the explanation is the same?

    Best regards,

    João Matos

     
  • Mario Fortier

    Mario Fortier - 2009-01-29
    • status: open-works-for-me --> closed-works-for-me
     
  • Mario Fortier

    Mario Fortier - 2009-01-29

    Using different smoothing algo or initialization logic (which I suspect is being done here with the other apps) has a significant effect on the first few output values. Assuming they did not deviate drastically from the original algo, the result will be very similar after about a hundred inputs (because the effect of how the algo handle differently its initialization has less and less impact).

    If you want to get to the bottom of this, get Wilder's book and write to Tradestation and Equis to ask why their output differs from the book.

    If you have Excel look for test_ADX.xls in the TA-Lib package. The TA-Lib output is compared to a pure Excel implementation and the output of another software (Wealth-Lab). Use that when comparing to Wilder's example.

    \Mario

     
  • Joao Matos

    Joao Matos - 2009-01-29

    Hello,

    Thank you.

    João Matos

     
  • Joao Matos

    Joao Matos - 2009-01-29
    • status: closed-works-for-me --> open-works-for-me
     
  • Mario Fortier

    Mario Fortier - 2010-04-24
    • status: open-works-for-me --> closed-works-for-me
     

Log in to post a comment.

MongoDB Logo MongoDB