HMA-High

The Hull Moving Average (HMA) is a sophisticated technical analysis tool designed to provide traders with a smoother representation of price action while minimizing the "lag" typically associated with standard moving averages. In simple terms, it aims to show you the current trend more clearly and responsively than traditional methods.

Core Logic and Mechanism

The script achieves its smooth yet responsive movement through a multi-layered calculation process. Instead of calculating a single average in one step, it breaks the logic down into two distinct phases:

1. The Weighted Difference Calculation First, the tool analyzes price highs over two different timeframes simultaneously. It calculates a weighted moving average for a shorter period (half of your chosen setting) and another for the full period. By doubling the shorter average and subtracting the longer one, the script creates a "difference" value. This step is crucial because it effectively captures the momentum and velocity of price changes, highlighting how quickly the market is moving in a specific direction.

2. The Smoothing Pass The raw data generated from the first step can often be jumpy or volatile. To fix this, the script performs a second calculation on those difference values. It applies another weighted moving average to "smooth out" the noise. This final pass ensures that the resulting line on your chart is fluid and easy to read, removing unnecessary market "flickers" while retaining the speed of the initial calculation.

Key User Benefits

  • Reduced Lag: Unlike standard moving averages that often trail significantly behind the current price, this logic attempts to stay as close to the actual price action as possible.
  • Trend Clarity: By smoothing out minor fluctuations, it allows traders to identify the primary direction of the market more easily.
  • Customizable Sensitivity: The "HMA_Period" setting allows you to balance the trade-off between smoothness and responsiveness; a lower number reacts faster to price changes, while a higher number provides a more stable, long-term trend view.

Visual Representation

On your trading chart, this logic manifests as a solid blue line. Its primary purpose is to act as a dynamic guide: when the line moves upward, it indicates bullish momentum; when it trends downward, it signals bearish sentiment. Because of its unique mathematical construction, it is particularly effective at identifying turning points in the market.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
HMA-High
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                          HMA.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  Blue

//---- indicator parameters
extern int HMA_Period=20;
//---- indicator buffers
double     ind_buffer0[];
double     ind_buffer1[];

int        draw_begin0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   IndicatorBuffers(2);
   if(!SetIndexBuffer(0,ind_buffer0) && !SetIndexBuffer(1,ind_buffer1))
      Print("cannot set indicator buffers!");
//   ArraySetAsSeries(ind_buffer1,true);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
   draw_begin0=HMA_Period+MathFloor(MathSqrt(HMA_Period));
   SetIndexDrawBegin(0,draw_begin0);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("HMA("+HMA_Period+")");
   SetIndexLabel(0,"Hull Moving Average");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit,i;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<1)
     {
      for(i=1;i<=draw_begin0;i++) ind_buffer0[Bars-i]=0;
      for(i=1;i<=HMA_Period;i++) ind_buffer1[Bars-i]=0;
     }
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- MA difference counted in the 1-st buffer
   for(i=0; i<limit; i++)
      ind_buffer1[i]=iMA(NULL,0,MathFloor(HMA_Period/2),0,MODE_LWMA,PRICE_HIGH,i)*2-
                     iMA(NULL,0,HMA_Period,0,MODE_LWMA,PRICE_HIGH,i);
//---- HMA counted in the 0-th buffer
   for(i=0; i<limit; i++)
      ind_buffer0[i]=iMAOnArray(ind_buffer1,0,MathFloor(MathSqrt(HMA_Period)),0,MODE_LWMA,i);
//---- done
   return(0);
  }

Comments