I want to stress again that the square root and log formulas are from Jeff Grover and Bob Sage, and the Metastock formula from Jan Robert Wolensky. I couldn't have begun this wretched thing without them.
//AIQ Volatility Indicator, translated for QP2 by Brooke, //with square root and log formulas by Jeff Grover and Bob Sage //Metastock translation, Jan Robert Wolensky //100*(Sqrt(12.5* //(Sum((Log(C/Ref(C,-1))*Log(C/Ref(C,-1))),21)- //((Sum(Log(C/Ref(C,-1)),21)*Sum(Log(C/Ref(C,-1)),21)))/21))) //AIQ Volatility Indicator, translated for QP2 by Brooke input="volvol.lst"; output="volatility.lst"; daystoload=500; float x,xx,n,n3,n5,n7,n9,n11,n13,n15,lnx,sumlnx,sumlnxlnx, sumlnxsumlnx,formula1,formula2,in,out,fx,xxx,period; integer i,j; period:=14; sumlnx:=0; sumlnxlnx:=0; for i=-(period-1) to 0 step 1 do x:=close(i)/close(i-1); //Jeff Grover's log formula 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); //Log(C/Ref(C,-1))
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;
sumlnx:= sumlnx+lnx; //Sum(Log(C/Ref(C,-1)),21) sumlnxlnx:=sumlnxlnx+(lnx*lnx); //Sum((Log(C/Ref(C,-1))*Log(C/Ref(C,-1))),21) next i; sumlnxsumlnx:=sumlnx*sumlnx; //((Sum(Log(C/Ref(C,-1)),21)*Sum(Log(C/Ref(C,-1)),21)) formula1:=sumlnxlnx-(sumlnxsumlnx/period); //( Sum((Log(C/Ref(C,-1))*Log(C/Ref(C,-1))),21) - // ((Sum(Log(C/Ref(C,-1)),21)*Sum(Log(C/Ref(C,-1)),21)) )/21) formula2:=12.5*formula1; println symbol:-5, " ", "sumlnx: ", " ", sumlnx:10:5, " ", "sumlnxlnx: ", " ", sumlnxlnx:10:5, " ", "sumlnxsumlnx: ", " ", sumlnxsumlnx:10:5, " ", "formula1: ", " ", formula1:10:5, " ", "formula2: ", " ", formula2:10:5, " ", symbol:-5; //Jeff Grover's square root formula, with Bob Jagow in := formula2; xxx := 1.0; fx := 1.0; for j = 0 to 9 step 1 do xxx := xxx - fx/(2*xxx); fx := xxx*xxx - in; next j; out := xxx; println symbol, ", ", "AIQ Volatility Indicator: ", " ", 100*out:6:2; |