【解説】【MQL5 community】 Triple Exponential Moving Average (三重指数移動平均): 終値の三重移動平均に基づきます。 このインジーターの目的は、短いサイクルを除去することです。 このインジケーターは、指定された期間よりも短いトレンドの終値を示します。 2重指数移動平均(DEMA, Double Exponential Moving Average)と考え方は同じ。
【計算法】
1)DEMA を計算:
2)現在の価格とDEMAとの乖離を計算:
err(i) = 現在の価格 − DEMA(Price, N, ii)
3)TEMAを次のように計算:
TEMA(i) = DEMA(Price, N, i) + EMA(err, N, i)
= DEMA(Price, N, i) + EMA(Price - EMA(Price, N, i), N, i)
= DEMA(Price, N, i) + EMA(Price - DEMA(Price, N, i), N, i)
= 3 * EMA(Price, N, i) - 3 * EMA2(Price, N, i) + EMA3(Price, N, i)
【シグナル】
Moving Average のシグナルと同様で、 ロウソク足が移動平均のラインを上抜けしたら、「買い」、下抜けしたら「売り」。 上昇基調になりそうな(移動平均が右肩上がり)場合のトレンドを把握することができる。
//+------------------------------------------------------------------+ //| TEMA.mq5 | //| Copyright 2010, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2010, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property description "Triple Exponential Moving Average" #include <MovingAverages.mqh> //--- indicator settings #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 DarkBlue #property indicator_width1 1 #property indicator_label1 "TEMA" #property indicator_applied_price PRICE_CLOSE //--- input parameters input int InpPeriodEMA=14; // EMA period input int InpShift=0; // Indicator's shift //--- indicator buffers double TemaBuffer[]; double Ema[]; double EmaOfEma[]; double EmaOfEmaOfEma[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,TemaBuffer,INDICATOR_DATA); SetIndexBuffer(1,Ema,INDICATOR_CALCULATIONS); SetIndexBuffer(2,EmaOfEma,INDICATOR_CALCULATIONS); SetIndexBuffer(3,EmaOfEmaOfEma,INDICATOR_CALCULATIONS); //--- sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,3*InpPeriodEMA-3); //--- sets indicator shift PlotIndexSetInteger(0,PLOT_SHIFT,InpShift); //--- name for indicator label IndicatorSetString(INDICATOR_SHORTNAME,"TEMA("+string(InpPeriodEMA)+")"); //--- name for index label PlotIndexSetString(0,PLOT_LABEL,"TEMA("+string(InpPeriodEMA)+")"); //--- initialization done } //+------------------------------------------------------------------+ //| Triple Exponential Moving Average | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- check for data if(rates_total<3*InpPeriodEMA-3) return(0); //--- int limit; if(prev_calculated==0) limit=0; else limit=prev_calculated-1; //--- calculate EMA ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriodEMA,price,Ema); //--- calculate EMA on EMA array ExponentialMAOnBuffer(rates_total,prev_calculated,InpPeriodEMA-1,InpPeriodEMA,Ema,EmaOfEma); //--- calculate EMA on EMA array on EMA array ExponentialMAOnBuffer(rates_total,prev_calculated,2*InpPeriodEMA-2,InpPeriodEMA,EmaOfEma,EmaOfEmaOfEma); //--- calculate TEMA for(int i=limit;i<rates_total;i++) TemaBuffer[i]=3*Ema[i]-3*EmaOfEma[i]+EmaOfEmaOfEma[i]; //--- OnCalculate done. Return new prev_calculated. return(rates_total); } //+------------------------------------------------------------------+
【表示結果】
Back to Meta Trader