HMA_v5

This script is designed to display a specialized technical analysis tool on your trading chart known as the Hull Moving Average (HMA). The primary goal of this indicator is to provide traders with a smoother, more responsive trend line compared to standard moving averages, which often lag behind current market price action.

How it Works

The logic behind this script operates in two distinct stages to refine the data before it appears on your screen:

1. Data Weighting and Calculation Instead of simply averaging prices over a set period, the script first performs a calculation that combines two different types of weighted averages. It takes a shorter timeframe average and multiplies it by two, then subtracts a longer timeframe average from that result. By using "Linear Weighted" math (LWMA) as the foundation, the script gives more importance to the most recent price data, allowing it to react more quickly to sudden market shifts while filtering out minor "noise."

2. Smoothing the Curve Once the initial calculation is complete, the script performs a second layer of processing. It takes the results from the first step and applies another smoothing pass based on the square root of your chosen period. This double-layer approach allows the indicator to remain very close to the actual price action (minimizing lag) while still producing a fluid, continuous line that is easy for a trader to follow visually.

Key Features for the User

  • Responsiveness: Because of its unique two-step mathematical logic, this indicator aims to identify trend changes faster than traditional moving averages.
  • Customizable Period: You can adjust the "HMA_Period" setting to determine how much historical data the indicator considers. A lower number makes the line more sensitive to current price movements, while a higher number makes it smoother and better for identifying long-term trends.
  • Visual Clarity: The result is displayed as a solid yellow line on your chart window, making it easy to identify whether the market is currently in an uptrend, a downtrend, or moving sideways.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
HMA_v5
//+------------------------------------------------------------------+
//|                                                          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  Yellow

//---- indicator parameters
extern int HMA_Period=7;
extern int MAshift=0;
//---- 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);
   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),MAshift,MODE_LWMA,PRICE_OPEN,i)*2-
                     iMA(NULL,0,HMA_Period,MAshift,MODE_LWMA,PRICE_OPEN,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