有您的持续关注
我们会做得更好

均线的另类优化指标 TMA



TMA 指标的计算:

  • 1. 在移动均线的周期上加 1。
  • 2. 所接收的总和除以 2。
  • 3. 如果结果被为分数, 则舍入到一个整数。
  • 4. 计算收盘价的周期简单均线, 取其上 3 个点。
  • 5. 再次使用已计算的 4 点简单均线高取 3 点的数值。

TMA 指标图表效果:TMA 指标TMA 指标MQL4源码:

//+------------------------------------------------------------------+
//|                                                          TMA.mq4 |
//|                                                     Matias Romeo |
//|                                    mailto:matias.romeo@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Matias Romeo"
#property link      "mailto:matias.romeo@gmail.com"
//----
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Green
//Input parameters
extern int       Periods=30;
extern int       ApplyTo=0;
//Indicator buffers
double tma[];
//Global variables
int    weights[];
double divisor;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,tma);
//----
   IndicatorShortName("TMA("+Periods+")");
//Calculate weigths
   ArrayResize(weights,Periods);
   double dPeriods=Periods;
   int to=MathCeil(dPeriods/2.0);
//----
   for(int i=0; i<to; i++)
     {
      weights[i]           =i+1;
      weights[Periods-1-i] =i+1;
     }
   divisor=0.0;
   for(int j=0; j<Periods; j++)
      divisor+=weights[j];
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
  Comment("www.125808047.com");
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+Periods;

   for(int i=limit-1; i>=0; i--)
     {
      double tma_val=0.0;
      for(int j=0; j<Periods; j++)
        {
         double price=getPrice(ApplyTo,i+Periods-j);
         tma_val+=price*weights[j];
        }
      tma[i]=tma_val/divisor;
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double getPrice(int priceType,int index)
  {
   double price=0.0;
//----
   switch(priceType)
     {
      case PRICE_OPEN    : price=Open[index];
      break;
      case PRICE_HIGH    : price=High[index];
      break;
      case PRICE_LOW     : price=Low[index];
      break;
      case PRICE_MEDIAN  : price=(High[index]+Low[index])/2.0;
      break;
      case PRICE_TYPICAL : price=(High[index]+Low[index]+Close[index])/3.0;
      break;
      case PRICE_WEIGHTED: price=(High[index]+Low[index]+2*Close[index])/4.0;
      break;
      case PRICE_CLOSE   :
         default            : price=Close[index];
         break;
     }
   return(price);
  }
//+------------------------------------------------------------------+
如您喜欢此文章请点下面分享按钮↴峰汇在线 » 均线的另类优化指标 TMA
上一篇:
下一篇:
分享到:更多 ()