******************************************************************************************

ADXi = [(ADX(i-1) * (n - 1)) + DXi] / n
     where n = Smoothing Period
DX = [ 100 * ABS( (+DI) - (-DI) ) ] / ( (+DI) + (-DI) )


+DI = 100 * wSum(+DMI, n) / wSum(TR, n)
-DI = 100 * wSum(-DMI, n) / wSum(TR, n)
    where n = DI Interval
    wSum = Welles Summation (Sum = Value + Sum.1* (n - 1) / n) 
The DMI is calculated as follows ... 
   HiDiff = HI - HI.1  (current high - previous high)
   LoDiff = LO.1 - LO  (previous low - current low) 
   if (HiDiff < 0 and LoDiff < 0) or (HiDiff = LoDiff) then
     +DMI = 0
     - DMI = 0
   if (HiDiff > LoDiff) then
     +DMI = HiDiff
     -DMI = 0
   if (HiDiff < LoDiff) then
     +DMI = 0
     -DMI = LoDiff


TR = MAX{
    ABS(HI - LO),
   ABS(HI - CL.1),
   ABS(CL.1 - LO)
}

******************************************************************************************

ADX FORMULA:

+ DI =  LA SUMA DE LOS PROMEDIOS  DE LOS MOMIVIENTOS DIRECCIONALES AL ALZA (+DM)

                        TR (VERDADERA AMPLITUD)

- DI= =  LA SUMA DE LOS PROMEDIOS  DE LOS MOMIVIENTOS DIRECCIONALES A LA BAJA (-DM)

                        TR (VERDADERA AMPLITUD)

TR  (True Range) = PROMEDIO DE TODOS LOS RAGOS DE CRECIMIENTO DE LOS PRECIOS DE n SESIONES LA DE TR DE HOY  / SOBRE n CANTIDAD DE SESIONES (14 TIPICA).

ADX=  se obtiene dividiendo la diferencia entre +DI y DI /  sobre la suma de los mismos  da entre 0 y 100 es una tasa. Que para expresar tendencia debe estar por encima de 25%

ADX=  (+DM) - (-DM) / (+DM)+ (-DM)

******************************************************************************************

ADX = modify moving average of DX
DX = 100 x ( (+DI - -DI)/( +DI + -DI) )
+DI = +DMn / TRn , -DI = -DM / TRn
+DM = Ht - Ht-1 , -DM = Lt - Lt-1
CL = Ct - Ct-1
TR = largest of +DM,-DM ,and CL 
where : 
    +DI = current positive directional index
    -DI = current negative directional index
    +DMn = current modified moving average of +DM
    +DM = current positive directional movement value
    Ht = current hign
    Ht-1 = previous high
    Lt = current low
    Lt-1 = previous low
    -DMn = current modified moving average of -DM
    -DM = current negative directional movement value
    TRn = current modified modified moving average of the true range
    TR = true range
    n = number of periods
    DX = current DX

******************************************************************************************

Construction
To calculate the Directional Movement System:

Calculate the Directional movement for today
+DM = Today's High - Yesterday's High (when price moves upward)
-DM  = Yesterday's Low - Today's Low (when price moves downward)

You cannot have both +DM and -DM on the same day. If there is an outside day (where both calculations are positive) then the larger of the two results is taken. An inside day (where both calculations are negative) will always equal zero.

Calculate the true range for the day. True range is the largest of: 
Today's High - Today's Low,
Today's High - Yesterday's Close, and
Yesterday's Close - Today's Low

+DM14 = exponential moving average* of +DM

-DM14  = exponential moving average* of -DM

TR14    = exponential moving average* of True Range

Next, calculate the Directional Indicators:

+DI14  = +DM14 divided by TR14

-DI14   = -DM14 divided by TR14

Then, calculate the components of the Average Directional Movement Index (ADX):

Calculate the DI Difference: 
Record the difference between +DI14 and -DI14 as a positive number.

Calculate the Directional Index (DX):
DX = DI Difference divided by the sum of +DI14 and -DI14

ADX = the exponential moving average* of DX

******************************************************************************************

Small Stocks Charting Program Formula:
TR := SUM(MAX(MAX(HIGH-LOW,ABS(HIGH-REF(CLOSE,1))),ABS(LOW-REF(CLOSE,1))),N);
HD := HIGH-REF(HIGH,1);
LD := REF(LOW,1)-LOW;
DMP:= SUM(IF(HD>0 & HD>LD,HD,0),N); 
DMM:= SUM(IF(LD>0 & LD>HD,LD,0),N); 
PDI: DMP*100/TR;
@SETNAME(PDI,'+DI');
MDI: DMM*100/TR;
@SETNAME(MDI,'-DI');
ADX: MA(ABS(MDI-PDI)/(MDI+PDI)*100,N),WIDTH2;

