ATR formula in AmiBroker

#1
Hi,

I'm trying to write my own ATR to work exactly like AmiBroker ATR (for further implementation of weights). I attempted to apply formula from here
, unfortunately it returns different results and performs worse than AmiBroker implementation in BackTester. Could you help me with that ? This is what I have:

Code:
amiATR=ATR(3);

myATR = (
     Ref(Max(H-L,Max(abs(H-Ref(C,-1)),abs(L-Ref(C,-1)))),0) +

     Ref(Max(H-L,Max(abs(H-Ref(C,-1)),abs(L-Ref(C,-1)))),-1) + 

     Ref(Max(H-L,Max(abs(H-Ref(C,-1)),abs(L-Ref(C,-1)))),-2)
        ) / 3;


Plot(amiATR,"AmiBroker ATR",colorBlack);
Plot(myATR ,"my ATR",colorRed);
 
#2
function myATR(par_Length) {
t_myATR[0] = H[0]-L[0];
for (nn7 = 1; nn7 < BarCount; nn7++) {
t_myATR[nn7] = (Max(H[nn7]-L[nn7],Max(abs(H[nn7]-C[nn7-1]),abs(C[nn7-1]-L[nn7])))+t_myATR[nn7-1]*(par_Length-1))/par_Length;
}
return t_myATR;
}
 
#3
function myATR(par_Length) {
t_myATR[0] = H[0]-L[0];
for (nn7 = 1; nn7 < BarCount; nn7++) {
t_myATR[nn7] = (Max(H[nn7]-L[nn7],Max(abs(H[nn7]-C[nn7-1]),abs(C[nn7-1]-L[nn7])))+t_myATR[nn7-1]*(par_Length-1))/par_Length;
}
return t_myATR;
}
 

Similar threads