Hello all, only just found this site, have been using PRT for a few years now. Would anyone know how to code ADX/Directional movement but using exponential averages instead of wilders smooth averages. I basically want the directional movement DI+ and Di – with ADX line how it is in PRT now but with exponential averages used instead of wilders. Been struggling to do this for a long time, any help would be greatly appreciated.
Thanks
Please find below a quick fix to get the ADX and Directional Movement Index in the same window, calculated with Exponential Moving Average instead of Wilder’s Average.
Wilders smoothing formula is almost like EMA, for your information. A bit more smoothed though.
Here is the code:
p=14
plusDM = MAX(HIGH-HIGH[1], 0)
minusDM = MAX(LOW[1]-LOW, 0)
IF plusDM > minusDM THEN
minusDM = 0
ENDIF
IF plusDM < minusDM THEN
plusDM = 0
ENDIF
IF plusDM = minusDM THEN
plusDM = 0
minusDM = 0
ENDIF
plusDI = exponentialaverage[p](plusDM)//WILDERAVERAGE[p](plusDM)
minusDI = exponentialaverage[p](minusDM)//WILDERAVERAGE[p](minusDM)
DM = (plusDI-minusDI)/pointsize
DX = ABS(plusDI - minusDI) / (plusDI + minusDI) * 100
myADX = exponentialaverage[p](DX)//wilderAverage[p](DX)
Return DM*10,myADX
Thank you very much for your reply, what is the original code for the directional movement indicator in PRT?
Thanks
This one but without any of the ADX formula (lines 24 and 25) and with the Wilders average instructions I commented with //
Thank you for your reply. I’m new to the coding so struggling a bit. I loaded up this code and it has the adx but what i was looking for was for it to look like the one in the screenshot but calculated on the exponential with just DI+, DI- and ADX. I’m probably missing something obvious but thanks again for your reply.
Oh ok, so you don’t need DMI but only DI+ and DI-, so please find below the modified code:
p=14
plusDM = MAX(HIGH-HIGH[1], 0)
minusDM = MAX(LOW[1]-LOW, 0)
IF plusDM > minusDM THEN
minusDM = 0
ENDIF
IF plusDM < minusDM THEN
plusDM = 0
ENDIF
IF plusDM = minusDM THEN
plusDM = 0
minusDM = 0
ENDIF
plusDI = exponentialaverage[p](plusDM)//WILDERAVERAGE[p](plusDM)
minusDI = exponentialaverage[p](minusDM)//WILDERAVERAGE[p](minusDM)
//DM = (plusDI-minusDI)/pointsize
DX = ABS(plusDI - minusDI) / (plusDI + minusDI)
myADX = exponentialaverage[p](DX)//wilderAverage[p](DX)
Return myADX as "ADX",plusDI coloured(200,0,0) as "DI+",minusDI coloured(0,200,0) as "DI-"
Thank you very much for this.