ADX

Overview of the Average Directional Index calculation.

Average Directional Index - The average directional index (ADX) is a technical analysis indicator used by some traders to determine the strength of a trend. According to the creator Welles Wilder, the trend has strength when ADX is above 25 and the trend is weak or the price is trendless when ADX is below 20. Non-trending values do not necessarily mean the price isn't moving, it very well could be, but the price could also be making a trend change or is too volatile for a clear direction to be present. ADX is considered a non-directional indicator and registers trend whether the price is going up or down. The default setting is 14 bars, although other time periods can be used to increase or decrease the trend strength reading. ADX is plotted as a single line with values ranging from a low of 0 to a high of 100.

The source code for the ADX function is available here.

/* 
 * The DM1 (one period) is base on the largest part of
 * today's range that is outside of yesterdays range.
 * 
 * The following 7 cases explain how the +DM and -DM are
 * calculated on one period:
 *
 * Case 1:                       Case 2:
 *    C|                        A|
 *     |                         | C|
 *     | +DM1 = (C-A)           B|  | +DM1 = 0
 *     | -DM1 = 0                   | -DM1 = (B-D)
 * A|  |                           D| 
 *  | D|                    
 * B|
 *
 * Case 3:                       Case 4:
 *    C|                           C|
 *     |                        A|  |
 *     | +DM1 = (C-A)            |  | +DM1 = 0
 *     | -DM1 = 0               B|  | -DM1 = (B-D)
 * A|  |                            | 
 *  |  |                           D|
 * B|  |
 *    D|
 * 
 * Case 5:                      Case 6:
 * A|                           A| C|
 *  | C| +DM1 = 0                |  |  +DM1 = 0
 *  |  | -DM1 = 0                |  |  -DM1 = 0
 *  | D|                         |  |
 * B|                           B| D|
 *
 *
 * Case 7:
 * 
 *    C|
 * A|  |
 *  |  | +DM=0
 * B|  | -DM=0
 *    D|
 *
 * In case 3 and 4, the rule is that the smallest delta between
 * (C-A) and (B-D) determine which of +DM or -DM is zero.
 *
 * In case 7, (C-A) and (B-D) are equal, so both +DM and -DM are
 * zero.
 *
 * The rules remain the same when A=B and C=D (when the highs
 * equal the lows).
 *
 * When calculating the DM over a period > 1, the one-period DM
 * for the desired period are initialy sum. In other word, 
 * for a -DM14, sum the -DM1 for the first 14 days (that's 
 * 13 values because there is no DM for the first day!)
 * Subsequent DM are calculated using the Wilder's
 * smoothing approach:
 * 
 *                                    Previous -DM14
 *  Today's -DM14 = Previous -DM14 -  -------------- + Today's -DM1
 *                                         14
 *
 * (Same thing for +DM14)
 *
 * Calculation of a -DI14 is as follow:
 * 
 *               -DM14
 *     -DI14 =  --------
 *                TR14
 *
 * (Same thing for +DI14)
 *
 * Calculation of the TR14 is:
 *
 *                                   Previous TR14
 *    Today's TR14 = Previous TR14 - -------------- + Today's TR1
 *                                         14
 *
 *    The first TR14 is the summation of the first 14 TR1. See the
 *    TA_TRANGE function on how to calculate the true range.
 *
 * Calculation of the DX14 is:
 *    
 *    diffDI = ABS( (-DI14) - (+DI14) )
 *    sumDI  = (-DI14) + (+DI14)
 *
 *    DX14 = 100 * (diffDI / sumDI)
 *
 * Calculation of the first ADX:
 *
 *    ADX14 = SUM of the first 14 DX
 *
 * Calculation of subsequent ADX:
 *
 *            ((Previous ADX14)*(14-1))+ Today's DX
 *    ADX14 = -------------------------------------
 *                             14
 *
 * Reference:
 *    New Concepts In Technical Trading Systems, J. Welles Wilder Jr
 */

Last updated