Would anyone like to translate the Choppiness formula?
I think the formula might be of general interest to ESignal users.
Choppiness has its uses. Here's the Metastock code by Gibbons Burke:
((Log(Sum(ATR(1),14) / (HHV(If(H,>=,Ref(C,-1),H,Ref(C,-1)),14)-LLV(If(L,<=,
Ref(C,-1),L,Ref(C,-1)),14)))/Log(10))/(Log(14)/Log(10)))*10
And ESignal: Thanks for all your improvements. A very fine program.
Below is a QP2 translation I did of the formula some time ago (years ago, I
think), incorporating others' code for ATR and logs. That might help.
Best regards,
Brooke
output = "choppiness.lst";
input ="commplus.lst";
issuetype common;
float cl, ATRlen, tr, sumATR,
x,xx,n,n3,n5,n7,n9,n11,n13,n15,lnx,
high1,maxhi, low1, minlo, maxhiminlo,
sumatrmaxhi, xdivlog, logdiv, choppiness;
integer bar, nn, nnn, nnnn, lenATR;
lenATR:= 14;
for nn = -13 to 0 step 1 do
DaysToLoad = 250;
DaysRequired = 250;
ATRlen:= 0;
for bar = (nn -lenATR)+1 to nn do
cl:= close(bar-1);
tr:= range(bar);
if cl > high(bar) then
tr:= cl - low(bar);
else
if cl < low(bar) then
tr:= high(bar) - cl;
endif;
endif;
ATRlen := ATRlen + tr;
sumATR:=0;
sumATR:=sumATR + ATRlen;
next bar;
ATRlen:= ATRlen/lenATR;
next nn;
maxhi:=0;
for nnn = -13 to 0 step 1 do
If High(nnn)>=close(nnn-1) then
high1:=high(nnn);
Else
high1:=close(nnn-1);
endif;
if high1 >= maxhi then
maxhi := high1;
endif;
next nnn;
minlo:=500;
for nnnn = -13 to 0 step 1 do
If low(nnnn)<=close(nnnn-1) then
low1:=low(nnnn);
Else
low1:=close(nnnn-1);
endif;
if low1 <= minlo then
minlo := low1;
endif;
next nnnn;
maxhiminlo:=maxhi-minlo;
sumATRmaxhi:=sumATR/(maxhiminlo+.00001);
x:=sumATRmaxhi;
if x >= 100000 then xx := x /100000; else
if x >= 10000 then xx := x / 10000; else
if x >= 1000 then xx := x / 1000; else
if x >= 100 then xx := x / 100; else
if x >= 10 then xx := x / 10; else
xx := x; endif; endif; endif; endif; endif;
n :=(xx-1)/(xx+1); n3 :=n*n*n; n5 :=n3*n*n;
n7 :=n5*n*n; n9 :=n7*n*n; n11 :=n9*n*n;
n13 :=n11*n*n; n15 :=n13*n*n;
lnx := 2*(n+n3/3+n5/5+n7/7+n9/9+n11/11+n13/13+n15/15);
if x >= 100000 then lnx := lnx + 11.51293; else
if x >= 10000 then lnx := lnx + 9.21034; else
if x >= 1000 then lnx := lnx + 6.90776; else
if x >= 100 then lnx := lnx + 4.60517; else
if x >= 10 then lnx := lnx + 2.30258;
endif; endif; endif; endif; endif;
xdivlog:=(lnx/2.3026);
logdiv:=xdivlog/1.1461;
choppiness:=logdiv*10;
println symbol:-6, " ", "Choppiness: ", choppiness:4:3;
I think the formula might be of general interest to ESignal users.
Choppiness has its uses. Here's the Metastock code by Gibbons Burke:
((Log(Sum(ATR(1),14) / (HHV(If(H,>=,Ref(C,-1),H,Ref(C,-1)),14)-LLV(If(L,<=,
Ref(C,-1),L,Ref(C,-1)),14)))/Log(10))/(Log(14)/Log(10)))*10
And ESignal: Thanks for all your improvements. A very fine program.
Below is a QP2 translation I did of the formula some time ago (years ago, I
think), incorporating others' code for ATR and logs. That might help.
Best regards,
Brooke
output = "choppiness.lst";
input ="commplus.lst";
issuetype common;
float cl, ATRlen, tr, sumATR,
x,xx,n,n3,n5,n7,n9,n11,n13,n15,lnx,
high1,maxhi, low1, minlo, maxhiminlo,
sumatrmaxhi, xdivlog, logdiv, choppiness;
integer bar, nn, nnn, nnnn, lenATR;
lenATR:= 14;
for nn = -13 to 0 step 1 do
DaysToLoad = 250;
DaysRequired = 250;
ATRlen:= 0;
for bar = (nn -lenATR)+1 to nn do
cl:= close(bar-1);
tr:= range(bar);
if cl > high(bar) then
tr:= cl - low(bar);
else
if cl < low(bar) then
tr:= high(bar) - cl;
endif;
endif;
ATRlen := ATRlen + tr;
sumATR:=0;
sumATR:=sumATR + ATRlen;
next bar;
ATRlen:= ATRlen/lenATR;
next nn;
maxhi:=0;
for nnn = -13 to 0 step 1 do
If High(nnn)>=close(nnn-1) then
high1:=high(nnn);
Else
high1:=close(nnn-1);
endif;
if high1 >= maxhi then
maxhi := high1;
endif;
next nnn;
minlo:=500;
for nnnn = -13 to 0 step 1 do
If low(nnnn)<=close(nnnn-1) then
low1:=low(nnnn);
Else
low1:=close(nnnn-1);
endif;
if low1 <= minlo then
minlo := low1;
endif;
next nnnn;
maxhiminlo:=maxhi-minlo;
sumATRmaxhi:=sumATR/(maxhiminlo+.00001);
x:=sumATRmaxhi;
if x >= 100000 then xx := x /100000; else
if x >= 10000 then xx := x / 10000; else
if x >= 1000 then xx := x / 1000; else
if x >= 100 then xx := x / 100; else
if x >= 10 then xx := x / 10; else
xx := x; endif; endif; endif; endif; endif;
n :=(xx-1)/(xx+1); n3 :=n*n*n; n5 :=n3*n*n;
n7 :=n5*n*n; n9 :=n7*n*n; n11 :=n9*n*n;
n13 :=n11*n*n; n15 :=n13*n*n;
lnx := 2*(n+n3/3+n5/5+n7/7+n9/9+n11/11+n13/13+n15/15);
if x >= 100000 then lnx := lnx + 11.51293; else
if x >= 10000 then lnx := lnx + 9.21034; else
if x >= 1000 then lnx := lnx + 6.90776; else
if x >= 100 then lnx := lnx + 4.60517; else
if x >= 10 then lnx := lnx + 2.30258;
endif; endif; endif; endif; endif;
xdivlog:=(lnx/2.3026);
logdiv:=xdivlog/1.1461;
choppiness:=logdiv*10;
println symbol:-6, " ", "Choppiness: ", choppiness:4:3;