HMA_v05
Download scriptThis indicator is designed to provide visual signals on a trading chart by identifying shifts in price momentum. It utilizes a specialized calculation known as the Hull Moving Average (HMA), which is engineered to reduce the "lag" typically found in standard moving averages while maintaining a smooth line for analysis.
How the Logic Works
1. The Foundation: Weighted Averaging Instead of simply looking at the average price over a set period, the script calculates two different types of weighted averages simultaneously:
- A "fast" average based on half of your chosen time period.
- A "slow" average based on the full time period.
2. Creating the Momentum Signal The script multiplies the "fast" average by two and subtracts the "slow" average from it. This mathematical step is designed to isolate the most recent price actions, effectively highlighting the immediate trend of the market while filtering out minor fluctuations.
3. Smoothing the Data To ensure the signals aren't triggered by random noise, the script applies a final smoothing layer. It takes the square root of your chosen period to determine how much to "soften" the data. This ensures that the resulting trend line is stable and readable.
4. Visual Execution (The Arrows) The indicator constantly compares the current value of this smoothed calculation against its previous value:
- Upward Trend: If the current value is higher than the previous value, the script recognizes upward momentum and places a green arrow on your chart.
- Downward Trend: If the current value is lower than the previous value, the script recognizes downward momentum and places a red arrow on your chart.
Summary for the User
The primary goal of this script is to provide a clear, visual "map" of price direction. By processing the data through multiple layers of weighted averages, it attempts to give you a smoother, faster view of whether the market is currently leaning upward or downward compared to where it was just moments before.
//-----------------------
// HMA modified by Ron
//-----------------------
#property link "http://www.justdata.com.au/Journals/AlanHull/hull_ma.htm"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- External parameters
extern int _maPeriod=14;
extern int BarsToDraw=200;
//---- indicator buffers
double _hmaG[];
double _hmaR[];
double _wma[];
int init()
{
// 233 up arrow
// 234 down arrow
// 159 big dot
// 158 little dot
// 168 open square
// 120 box with X
//---- indicator buffers memory
IndicatorBuffers(3);
//---- indicator buffers mapping
SetIndexBuffer(0, _hmaG);
SetIndexEmptyValue(0, 0.0);
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexBuffer(1, _hmaR);
SetIndexEmptyValue(1, 0.0);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(2, _wma);
}
int deinit()
{
}
int start()
{
int pos;
int period = _maPeriod;
int halfPeriod = _maPeriod/2;
int sqrtPeriod = MathFloor(MathSqrt(period*1.00));
double halfMA;
double fullMA;
double GorR;
double prevGorR;
/*
MetaStock Formula
period:=Input("Period",1,200,20) ;
sqrtperiod:=Input("Square Root of Period",1,20,4);
Mov(2*(Mov(C,period/2,W))-Mov(C,period,W),sqrtperiod,W);
SuperCharts Formula
Input: period (Default value 20)
waverage(2*waverage(close,period/2)-waverage(close,period), SquareRoot(Period))
*/
for(pos=BarsToDraw; pos>=0; pos--)
{
fullMA=iMA(Symbol(), 0, period, 0, MODE_LWMA, PRICE_CLOSE, pos);
halfMA=iMA(Symbol(), 0, halfPeriod, 0, MODE_LWMA, PRICE_CLOSE, pos);
_wma[pos]=(2*halfMA)-fullMA;
}
prevGorR=iMAOnArray(_wma,0,sqrtPeriod,0,MODE_LWMA,1);
GorR=iMAOnArray(_wma,0,sqrtPeriod,0,MODE_LWMA,0);
if (prevGorR<GorR)
{
Print("UP_ARROW ",prevGorR," ",GorR);
_hmaG[pos]=GorR;
_hmaR[pos]=EMPTY_VALUE;
}
else
{
Print("DN_ARROW ",prevGorR," ",GorR);
_hmaG[pos]=EMPTY_VALUE;
_hmaR[pos]=GorR;
}
}
Comments