|
ADX help
Can someone program this into MT4 indicator for me please, all MT4 ADX indicators I have seen use different way to calculate.
Directional Movement Index (DMI)
formula
1. The Directional movement:
If today's High is higher than yesterday's High then:
+DM = today's High - yesterday's High
If today's Low is lower than yesterday's Low then:
-DM = yesterday's Low - today's Low
If +DM is greater than -DM then:
-DM = 0
If +DM is less than -DM then:
+DM = 0
2. The true range:
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|
3. Moving average of +DM, -DM and True Range:
+DMMA = exponential moving average of +DM
-DMMA = exponential moving average of -DM
TRMA = exponential moving average of True Range
4. The Directional Indicators:
+DI = +DMMA / TRMA
-DI = -DMMA / TRMA
5. Directional Index:
DX = |(+DI - (-DI))| / (+DI + (-DI))
6. The Average Directional Movement Index:
ADX = the exponential moving average of DX
resource codes
for(i=0; i<n; i++)
{
if(m_aHigh[i]>m_aHigh[i+1])
aPDM[i]=m_aHigh[i]-m_aHigh[i+1];
if(m_aLow[i]<m_aLow[i+1])
aNDM[i]=m_aLow[i+1]-m_aLow[i];
if(aPDM[i]>0.0)&&((aNDM[i]>0.0))
{
if(aPDM[i]>aNDM[i])
aNDM[i]=0.0;
else
aPDM[i]=0.0;
}
da=fabs(m_aHigh[i]-m_aLow[i]);
db=fabs(m_aHigh[i]-m_aClose[i+1]);
dc=fabs(m_aLow[i]-m_aClose[i+1]);
dd=max(da,db);
aTR[i]=max(dd,dc);
}
EMA(aPDM, p1, aPDMMA);
EMA(aNDM, p1, aNDMMA);
EMA(aTR, p1, aTRMA);
for(i=0; i<n-p1; i++)
{
if(aTRMA[i]!=0.0)
{
m_aPDI[i]=aPDMMA[i]/aTRMA[i]*100.0;
m_aNDI[i]=aNDMMA[i]/aTRMA[i]*100.0;
}
if(m_aPDI[i]!=-m_aNDI[i])
aADX[i]=fabs(m_aPDI[i]-m_aNDI[i])/(m_aPDI[i]+m_aNDI[i]);
}
EMA(aADX, p1, m_aADXMA);
for(i=n-p1-1; i>=0; i--)
m_aADXMA[i]=m_aADXMA[i]*100.0;
|