//+------------------------------------------------------------------+
//|                                                          HMA.mq4 |
//|                                                           ������ |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "������"
#property link      ""

#property indicator_chart_window 
#property indicator_buffers 1
#property indicator_color1 LightBlue
#property indicator_width1 2
//---- input parameters 
extern int       period=180; 
int       method=3;                         // MODE_SMA 
int       price=0;                          // PRICE_CLOSE 
//---- buffers
double HMABuffer[];
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
  {
//----
  SetIndexBuffer(0,HMABuffer); 
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
  SetIndexLabel(0,"HMA("+period+")");  
  IndicatorShortName("HMA("+period+")");
//----
  return(0); 
  } 

//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit() 
  {
  return(0); 
  }
//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
int start() 
  {
//---- 
  int counted_bars=IndicatorCounted();
  if(counted_bars<0)return(-1);
  int limit=Bars-counted_bars+period+1; 
  if(limit>Bars)limit=Bars;
   
  double vect[];    
  ArrayResize(vect,limit); 
  ArraySetAsSeries(vect,true);
  for(int x=0;x<limit;x++) 
    {
    vect[x]=iMA(NULL,0,period/2,0,method,price,x)*2-iMA(NULL,0,period,0,method,price,x);
    }
  int p=MathSqrt(period); 
  for(x=0;x<limit-period;x++)HMABuffer[x]=iMAOnArray(vect,0,p,0,method,x);
//----    
  return(0); 
  } 
//+------------------------------------------------------------------+