当你用SMA时,最后InpFivePeriod的几个K线时,MA5的值为0,程序出错了。
要明白SMA和EMA的算法。
修改下:
//+------------------------------------------------------------------+ for(int i=0; i<limit; i++) { if(i>=rates_total-1 - InpFivePeriod)break; double MA5=iMA(NULL,0,InpFivePeriod,0,MODE_EMA,PRICE_CLOSE,i); ExtFiveBuffer[i]=(Close[i]/MA5-1)*Close[i]/5; } //+------------------------------------------------------------------+
我的问题是:当使用 MODE_EMA 时,指标正常显示,也就是说随K线与时俱进,而当使用 MODE_SMA 时 ,静止了,不与时俱进,不能正常显示。
请教如何才能修正这个问题。先谢。
程序剪贴如下: