22 9月 2008

Smoothed Moving Average(SMMA)

Smoothed Moving Average(SMMA)-MetaQuotes
Smoothed Moving Average(SMA)-DanielsTrading

Calculation:

Smoothed Moving Average (SMMA)
The first value of this smoothed moving average is calculated as the
simple moving average (SMA):

SUM1 = SUM(CLOSE, N)

SMMA1 = SUM1/N

The second and succeeding moving averages are calculated according
to this formula:

SMMA(i) = (SUM1-SMMA1+CLOSE(i))/N


Where:
SUM1 — is the total sum of closing prices for N periods;
SMMA1 — is the smoothed moving average of the first bar;
SMMA(i) — is the smoothed moving average of the current bar
(except for the first one);
CLOSE(i) — is the current closing price;
N — is the smoothing period.

這指標在TS內部並無內建指標,但是HTS內建有(SMA),因此在轉
部份HTS程式到TS上的時候會需要自己新增自訂函數,在這裡就直
接把這部份的程式碼直接轉成TS,使用者自己加入就可以了。

  • 函數名稱取名自定,或者同HTS內建名稱:SMA
  • 設定完後要記得按Verify(F3)
TS新增自訂函數

TS程式碼(修改HTS源碼)
Inputs: Price(Numeric), Length(Numeric);
Variables: Summation(0), Counter(0);

If CurrentBar = 1 Then begin
   Summation = 0;
   For Counter = 0 To Length - 1 begin
       Summation = Summation + Price[Counter];
   End;
   SMA = Summation / Length;
end
Else begin
   Summation = Summation[1] - SMA[1] + Price;
   SMA = Summation / Length;
End;

沒有留言:

張貼留言