iAMA 的 fast slow 不是两条均线 我把平方漏了
iAMA 的参数写着 Fast EMA period 和 Slow EMA period,我一直以为它内部跑两条 EMA 再取差,其实这俩只是平滑常数的上下端点,按效率比插值,不是第二次平均价格。更麻烦的是效率比没有 buffer 给,想拿它做过滤只能自己算净位移除以往返总路程。我照官方公式写的一版在震荡里太活,回头才看出来平滑常数忘了平方,那个平方就是专门压中间档的,贴代码你们看是不是这个病
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
double Am[];
input int ER_Period=9;
input int FastEMA=2;
input int SlowEMA=30;
int OnInit()
{
SetIndexBuffer(0,Am,INDICATOR_DATA);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ER_Period+1);
return INIT_SUCCEEDED;
}
int OnCalculate(const int total,const int prev,
const datetime &t[],const double &o[],
const double &h[],const double &l[],const double &c[],
const long &tv[],const long &v[],const int &sp[])
{
if(total<ER_Period+2) return 0;
int start=(prev<=0)?ER_Period+1:prev-1;
if(prev<=0) Am[ER_Period]=c[ER_Period];
double fs=2.0/(FastEMA+1);
double ss=2.0/(SlowEMA+1);
for(int i=start;i<total;i++)
{
double sig=MathAbs(c[i]-c[i-ER_Period]);
double noi=0;
for(int k=1;k<=ER_Period;k++) noi+=MathAbs(c[i-k+1]-c[i-k]);
double er=(noi>0)?sig/noi:0;
double sc=er*(fs-ss)+ss;
Am[i]=Am[i-1]+sc*(c[i]-Am[i-1]);
}
return total;
}全部回复(15)
发表回复
请先登录后再回复。
