HMA_Russian
Download scriptOverview of the Hull Moving Average (HMA) Indicator
This script is designed to provide traders with a specialized type of moving average known as the Hull Moving Average (HMA). The primary goal of this tool is to create a smooth trend line that responds much faster to recent price changes than traditional moving averages, while still filtering out significant market "noise."
How the Logic Works
To achieve this high level of responsiveness without creating erratic jumps in the data, the indicator processes price information through a multi-step mathematical sequence:
1. Data Weighting and Smoothing The logic begins by calculating weighted moving averages based on user-defined settings (such as the timeframe period and the specific type of price used). Instead of treating all past data points equally, it prioritizes more recent movements to ensure the line stays relevant to current market conditions.
2. Momentum Calculation The script performs a unique calculation where it takes two different weighted averages—one based on a shorter timeframe and one on a longer timeframe—and combines them. By doubling the value of the shorter average and subtracting the longer average, the indicator effectively isolates the "velocity" or momentum of the price. This step is what allows the line to react quickly to sudden trend shifts.
3. Final Smoothing Pass To prevent the momentum calculation from becoming too jagged or volatile (which can happen when you prioritize speed), the script performs a final smoothing pass. It takes the results of the previous step and applies one last moving average based on the square root of the initial period. This "rounds off" the sharp edges of the data, producing a fluid, continuous line.
Key Benefits for the User
- Reduced Lag: Unlike standard moving averages, which often tell you what happened in the past, this logic is engineered to stay closer to the current price action, allowing for potentially earlier entries and exits.
- Trend Clarity: By smoothing out minor fluctuations while maintaining speed, the indicator makes it easier to identify the primary direction of the market at a glance.
- Customization: The script allows you to adjust the "Period," which determines how much historical data is considered. A smaller period makes the line more sensitive and faster, while a larger period makes it smoother and slower.
//+------------------------------------------------------------------+
//| HMA.mq4
//| Copyright © 2006 WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104
//| wizardserg@mail.ru
//+------------------------------------------------------------------+
#property copyright "MT4 release WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104"
#property link "wizardserg@mail.ru"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---- input parameters
extern int period=21;
extern int method=0; // MODE_SMA
extern int price=0; // PRICE_CLOSE
//---- buffers
double ExtMapBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(1);
SetIndexBuffer(0, ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);
IndicatorShortName("Hull Moving Average("+period+")");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
// ???? ????? ?????? ??????
return(0);
}
//+------------------------------------------------------------------+
//| ?????????? ??????? |
//+------------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}
//+------------------------------------------------------------------+
//| 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);
// Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ", WMA(x, period));
}
for(x = 0; x < e-period; x++)
ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);
return(0);
}
//+------------------------------------------------------------------+
Comments