Hull_Moving_Average

Download script
Author: Copyright � 2007 , transport_david , David W Honeywell
Hull_Moving_Average

This tool is designed to provide traders with a specialized visual aid called the Hull Moving Average (HMA). In the world of trading, moving averages are used to smooth out the "noise" of constant price fluctuations to reveal the underlying trend of the market. The Hull Moving Average is particularly popular because it aims to achieve a balance that most standard indicators struggle with: it attempts to follow the price very closely with minimal delay (lag).

How the Logic Works

The script processes market data through a multi-step mathematical sequence to produce its final line on your chart. Instead of simply averaging the last few prices, it uses a layered approach:

  1. Primary Weighting: The script first calculates two separate "Weighted Moving Averages." It looks at the price over your chosen period and compares it against a much shorter, faster-moving average (half of your chosen period).
  2. The Comparison Phase: By doubling the value of the primary average and subtracting the shorter one, the script creates a specific mathematical contrast. This helps "tighten" the data, making the indicator much more responsive to sudden changes in direction compared to a standard moving average.
  3. Final Smoothing: To ensure the resulting line remains smooth and readable (rather than jagged), the script performs one final calculation. It takes that contrasted data and applies a third weighted average based on the square root of your chosen period.

Key Features for the User

  • Reduced Lag: The primary goal of this specific logic is to eliminate the "late" signals often found in traditional indicators. It allows you to see price trends as they happen, rather than after they have already finished moving.
  • Customizable Speed: Through the settings, you can define the Hull_Periods. A lower number will make the line extremely sensitive to every small move, while a higher number will smooth out the data further to show long-term trends.
  • Visual Clarity: The result is a single, fluid line on your chart that acts as a guide. When the line slopes up, it indicates upward momentum; when it slopes down, it indicates downward momentum.

By combining these three layers of math—Weighting, Contrasting, and Smoothing—the script provides a sophisticated way to track market direction with high precision and speed.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Hull_Moving_Average
//+------------------------------------------------------------------+
//|                                          Hull_Moving_Average.mq4 |
//|           Copyright © 2007 , transport_david , David W Honeywell |
//|                                     hellonwheels.trans@gmail.com |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007 , transport_david , David W Honeywell"
#property link      "hellonwheels.trans@gmail.com"

// The formula used can be found at http://www.linnsoft.com/tour/techind/movAvg.htm

// HMA = WMA(2*WMA(PRICE, n) - WMA(PRICE, n/2), sqrt(n))

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 DeepSkyBlue

extern int HUll_Periods = 6, Applied_Price = 0, ShowBars = 10500;

double Hull[];
double Calc[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
   IndicatorBuffers(2);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(0,Hull);
   
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(1,Calc);
   
   SetIndexLabel(0,"Hull_Moving_Average ( "+HUll_Periods+" )");
   
   IndicatorShortName(" Hull_Moving_Average ( "+HUll_Periods+" )");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int shift = ShowBars;
   
   if (ShowBars > Bars) ShowBars = Bars;
   
   // HMA = WMA(2*WMA(PRICE, n) - WMA(PRICE, n/2), sqrt(n))
   
   for ( shift = ShowBars; shift >= 0; shift-- )
    {
      
      double Exp = 2;
      
      double firstwma = iMA(NULL,0,HUll_Periods,0,MODE_LWMA,Applied_Price,shift);
      
      double secondwma = iMA(NULL,0,MathFloor(HUll_Periods/2),0,MODE_LWMA,Applied_Price,shift);
      
      Calc[shift] = (Exp*firstwma)-secondwma;
      
    }
   
   for ( shift = ShowBars; shift >= 0; shift-- )
    {
      
      Hull[shift] = iMAOnArray(Calc,0,MathFloor(MathSqrt(HUll_Periods)),0,MODE_LWMA,shift);
      
    }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments