Params
Numeric EffRatioLength(10);
Numeric FastAvgLength(2);
Numeric SlowAvgLength(30);
Vars
Numeric NetChg(0);
Numeric TotChg(0);
Numeric EffRatio(0);
Numeric ScaledSFSqr(0);
NumericSeries AMAValue;
Numeric SFDiff;
Begin
if(CurrentBar == 0)//当前第一根K线金子塔barpos
{
AMAValue = close;
}Else//从第二根K线开始计算
{
NetChg = Abs( close - close[EffRatioLength] );当前收盘价与前十根K线的收盘价之差的绝对值
TotChg = Summation( Abs( Price - Price[1] ), EffRatioLength );
前十个周期的前后收盘价之差的绝对值之和
EffRatio = IIF(TotChg > 0, NetChg / TotChg, 0);
SFDiff = 2 / ( FastAvgLength + 1 ) - 2 / ( SlowAvgLength + 1 );
ScaledSFSqr = Sqr( 2 / ( SlowAvgLength + 1 ) + EffRatio * SFDiff );sqr是求平方
AMAValue = AMAValue[1] + ScaledSFSqr * ( Price - AMAValue[1] );
}
End
//[]指的是回溯周期数
以上是TB版的卡夫曼自适应均线求翻译成金字塔版本
谢谢!
n:=10;
n2:=2;
n3:=30;
cn:=ref(c,n);
s1:=sum(abs(close-ref(close,1)),n);
variable:amavalue=0;
a1:=ref(amavalue,1);
if barpos=1 then amavalue:=close;
else then begin
netchg:=abs(c-cn);
totchg:=s1;
effratio:=if(totchg>0,netchg,0);
sfdiff:=2/(n2+1)-2/(n3+1);
scaledsfsqr:=SQRT(2/(n3+1)+effratio*sfdiff);
amavalue:=a1+scaledsfsqr*(close-a1);
end