MACD_HULL
Download scriptThis tool is a technical analysis indicator designed to help traders visualize and interpret market momentum by analyzing price trends. Rather than looking at raw price data alone, it processes the information through several layers of mathematical smoothing to filter out "market noise" and highlight the underlying direction of the trend.
Core Logic Overview
The script functions by comparing two distinct moving averages that have been specially modified for faster responsiveness. The logic follows a three-step transformation process:
1. Enhanced Smoothing (Hull Calculation) Instead of using standard moving averages, the script utilizes a "Hull" calculation style. It takes a baseline average and adjusts it to be much more reactive to recent price changes while still remaining smooth. It does this by calculating a weighted difference between a short-term average and a long-term average, effectively reducing the lag typically found in traditional indicators.
2. Dual Trend Comparison The indicator calculates two of these enhanced moving averages simultaneously using different timeframes (user-defined periods):
- Fast Trend: A shorter period used to capture quick price movements.
- Slow Trend: A longer period used to establish the broader market direction.
By subtracting the Slow Trend from the Fast Trend, the script creates a "difference" value. This represents the gap between short-term momentum and long-term positioning.
3. Signal Finalization (The Histogram) To make this data actionable for a trader, the script performs one final calculation:
- It takes the difference calculated in the previous step and applies a third smoothing layer.
- It then subtracts this final smoothed value from the initial difference.
Visual Representation
The resulting data is displayed in three primary ways on your chart:
- Lines: These represent the processed trends, showing the relationship between the different timeframes.
- Histogram: This provides a clear visual of "momentum." When the histogram bars are above the zero line, it suggests bullish momentum; when they fall below, it suggests bearish momentum.
Summary for the Trader
In plain terms, this script identifies how much "pull" a price movement has compared to its historical average. By smoothing out the erratic jumps of the market, it attempts to show you the "true" path of the price. It helps you see not just where the price is now, but how fast and in what direction it is moving relative to its recent past.
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color2 Red
#property indicator_color1 Blue
#property indicator_color3 Green
//---- input parameters
extern int period=100;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE
extern int period2=300;
extern int method2=3; // MODE_SMA
extern int price2=0; // PRICE_CLOSE
extern int period3=50;
extern int method3=1; // MODE_SMA
extern int price3=0; // PRICE_CLOSE
//---- buffers
double FL[];
double FS[];
double OSMA[];
double ExtMapBuffer[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
SetIndexBuffer(0, FL);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(1, FS);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(2, OSMA);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexBuffer(3, ExtMapBuffer);
SetIndexBuffer(4, ExtMapBuffer2);
IndicatorShortName("Hull Moving Average("+period+","+period2+","+period3+")");
return(0);
}
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}
double WMAd(int xd, int pd)
{
return(iMA(NULL, 0, pd, 0, method2, price2, xd));
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
if(counted_bars < 0)
return(-1);
int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;
double vect[];
if(e > Bars)
e = Bars;
ArrayResize(vect, e);
ArraySetAsSeries(vect, true);
for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period);
}
for(x = 0; x < e-period; x++)
{
ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);
}
int xd = 0;
int pd = MathSqrt(period2);
int ed = Bars - counted_bars + period2 + 1;
double vectd[];
if(ed > Bars)
ed = Bars;
ArrayResize(vectd, ed);
ArraySetAsSeries(vectd, true);
for(xd = 0; xd < ed; xd++)
{
vectd[xd] = 2*WMAd(xd, period2/2) - WMAd(xd, period2);
}
for(xd = 0; xd < ed-period2; xd++)
{
ExtMapBuffer2[xd] = iMAOnArray(vectd, 0, pd, 0, method2, xd);
}
int limit;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
{
FL[i] = ExtMapBuffer[i]-ExtMapBuffer2[i];
}
for(int b=0; b<limit; b++)
{
FS[b] = iMAOnArray(FL, 0, period3, 0, method3, b);
}
for(int c=0; c<limit; c++)
{
OSMA[c] =FL[c]-FS[c];
}
return(0);
}
//+------------------------------------------------------------------+
Comments