HMA_v05_v1
Download scriptThis tool is designed as a visual technical indicator for trading platforms, specifically engineered to identify momentum shifts in price action. It utilizes a specialized mathematical calculation known as the Hull Moving Average (HMA) logic to filter out market "noise" and provide clearer signals on whether the current trend is moving upward or downward.
How the Logic Works
1. Data Smoothing and Weighting Instead of simply looking at the average price over a set period, the script performs a multi-step calculation. It looks at two different timeframes simultaneously: a "half-period" (the shorter term) and a "full period" (the longer term). By doubling the value of the shorter timeframe and subtracting the longer one, the tool creates a highly reactive line that responds quickly to recent price changes while still respecting the broader trend.
2. Square Root Refinement To ensure the indicator doesn't become too erratic or "jumpy," the script applies a final smoothing layer based on the square root of the total period. This helps stabilize the movements, making it easier for a user to see the underlying direction of the market without being distracted by minor fluctuations.
3. Trend Detection (The Signals) The primary function of this script is to compare the current calculated value against its immediately preceding value. It looks for "crossovers" in momentum:
- Upward Momentum: When the current smoothed value is higher than the previous one, the script identifies a bullish shift and places an upward-pointing arrow on the chart.
- Downward Momentum: When the current smoothed value is lower than the previous one, it identifies a bearish shift and places a downward-pointing arrow.
User Experience
For the trader, this means you don't have to manually interpret complex price waves. The script does the heavy lifting by calculating these mathematical offsets in real-time. It essentially acts as a "trend compass," highlighting where the momentum is tilting, allowing for quicker visual identification of potential entry or exit points based on the direction of the arrows.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//-----------------------
// 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