可能可以这样实现这个sma函数,还没核对数据 function fSMA(x, n,m) { MAVt[0]=0; for(i=1; i<BarCount; i++) MAVt = (m*x[i-1] + (n-m)*MAVt[i-1]) / n; return MAVt; }
借鉴的类似几个函数 http://www.amibroker.com/guide/afl/afl_view.php?id=18 output = AMA( input, factor ) is equivalent to the following looping code: for( i = 1; i < BarCount; i++ ) { output[ i ] = factor[ i ] * input[ i ] + ( 1 - factor[ i ] ) * output[ i - 1 ]; } http://www.amibroker.com/guide/afl/afl_view.php?id=42 DEMA can also be implemented using new for looping: Len = 20; Plot( DEMA( Close, Len ), "Built-in DEMA", colorRed ); factor = 2 / (Len + 1 ); e1 = e2 = Close[ 0 ]; // initialize for( i = 0; i < BarCount; i++ ) { e1 = factor * Close[ i ] + ( 1 - factor ) * e1; e2 = factor * e1 + ( 1 - factor ) * e2; myDema[ i ] = 2 * e1 - e2; } Plot( myDema, "Dema in loop", colorBlue );