诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

均线类指标 HMA_v07

HMA_v07指标主图创建特定算法的均线。

HMA_v07指标图表:HMA_v07指标

HMA_v07指标源码:

//+------------------------------------------------------------------+
//|                                                      HMA_v07.mq4 |
//+------------------------------------------------------------------+
#property  copyright ""
#property  link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red

input int _maPeriod=14;

double _hmaW[];
double _hmaR[];
double _wma[];

void OnInit(void)
  {
	IndicatorBuffers(3);

	SetIndexBuffer(0, _hmaW);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID,2);
   
	SetIndexBuffer(1, _hmaR);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID,2);
	SetIndexBuffer(2, _wma);
	Comment("www.125808047.com");
   }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int pos;
   
	int fullPeriod =                    _maPeriod;
	int halfPeriod =                    _maPeriod/2;
	int sqrtPeriod = floor(sqrt(_maPeriod*1.00));
   
   double fullMA;
   double halfMA;
   
   double pastMA;
   double prevMA;
   double currMA;
   
   for(pos=200; pos>=0; pos--) 
     {
      fullMA=iMA(Symbol(), 0, fullPeriod, 0, MODE_LWMA, PRICE_OPEN, pos);
      halfMA=iMA(Symbol(), 0, halfPeriod, 0, MODE_LWMA, PRICE_OPEN, pos);
      _wma[pos]=(2*halfMA)-fullMA;
     }
   for(pos=200; pos>=0; pos--) 
     {
      prevMA=iMAOnArray(_wma,0,sqrtPeriod,0,MODE_LWMA,pos+2);
      prevMA=iMAOnArray(_wma,0,sqrtPeriod,0,MODE_LWMA,pos+1);
      currMA=iMAOnArray(_wma,0,sqrtPeriod,0,MODE_LWMA,pos);
      if(prevMA<currMA)
        {
         _hmaW[pos]=currMA;
        }
       else
        {
         _hmaR[pos]=currMA;
        }

      if(pastMA>prevMA<currMA)
        {
         _hmaR[pos+1]=prevMA;
        }
      if(pastMA<prevMA>currMA)
        {
         _hmaW[pos+1]=prevMA;
        }
     }
  return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 均线类指标 HMA_v07
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏