【解説】【MQL5 community】 Triple Exponential Average (三重指数平均): 相場の小刻みな波を取り除く機能と、 先行指標とした設計であるという2点が特徴。 先行指標として、他の売買タイミングを計る指標と連携して利用すれば、 ダマシを軽減することもできるでしょう。 また、TRIXと価格との拡散は相場の転換点を見分ける重要な指標ともなります。
プラスの数値は『買われ過ぎ』、または相場のトレンドに勢いがあることを示しています。 マイナスの数値は『売られ過ぎ』、または相場のトレンドが軟調になっていること示します。
【計算法】
1)指数移動平均の作成。
EMA1(i) = EMA(Price, N, i)
■Price(i) : current price;
■N : EMA period;
■EMA1(i) : current value of the Exponential Moving Average.
2)指数平均の指数平均を作成(二重指数平均)
EMA2(i) = EMA(EMA1, N, i).
3)二重指数平均の指数平均を作成(三重指数平均)
EMA3(i) = EMA(EMA2, N, i);
これから
TRIX(i) = (EMA3(i) - EMA3(i - 1))/ EMA3(i-1)
【シグナル】
買いシグナル
TRIXが0を上抜いた時に、「買い」、 価格が継続して底を形成している場合、指標が先行して上向いた時に、「買い」
売りシグナル
TRIX が0を割り込んだ時に、「売り」 価格が継続して天井を形成している場合、指標が先行して下向いた時に、「売り」
//+------------------------------------------------------------------+
//|                                                         TRIX.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 Average"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_width1  1
#property indicator_label1  "TRIX"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int                InpPeriodEMA=14;               // EMA period
//--- indicator buffers
double                  TRIX_Buffer[];
double                  EMA[];
double                  SecondEMA[];
double                  ThirdEMA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,TRIX_Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,EMA,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,SecondEMA,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,ThirdEMA,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,3*InpPeriodEMA-3);
//--- name for index label
   PlotIndexSetString(0,PLOT_LABEL,"TRIX("+string(InpPeriodEMA)+")");
//--- name for indicator label
   IndicatorSetString(INDICATOR_SHORTNAME,"TRIX("+string(InpPeriodEMA)+")");
//--- indicator digits
   IndicatorSetInteger(INDICATOR_DIGITS,5);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Triple Exponential 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=3*(InpPeriodEMA-1);;
      for(int i=0;i<limit;i++)
         TRIX_Buffer[0]=EMPTY_VALUE;
     }
   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,SecondEMA);
//--- calculate EMA on EMA array on EMA array
   ExponentialMAOnBuffer(rates_total,prev_calculated,2*InpPeriodEMA-2,InpPeriodEMA,SecondEMA,ThirdEMA);
//--- calculate TRIX
   for(int i=limit;i<rates_total;i++)
     {
      if(ThirdEMA[i-1]!=0.0)
         TRIX_Buffer[i]=(ThirdEMA[i]-ThirdEMA[i-1])/ThirdEMA[i-1];
      else
         TRIX_Buffer[i]=0.0;
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
【表示結果】
 
 
Back to Meta Trader

 








