HMA_v04

This tool is designed to provide a visual representation of price momentum and trend direction on your trading chart. It utilizes a modified version of the Hull Moving Average, which is engineered to identify trends with significantly less "lag" than traditional moving averages while maintaining a smooth visual flow.

How the Logic Works

The script processes market data through a three-step calculation sequence to determine the current trend:

1. Data Smoothing and Weighting Instead of looking at simple averages, the tool begins by calculating two different weighted averages based on your chosen period. One is a "fast" average (half the length of your main period) and the other is a "slow" average (the full period). By doubling the fast average and subtracting the slow average, the script creates a raw value that reacts very quickly to recent price changes.

2. Trend Refinement To ensure the visual output isn't too erratic or "noisy," the script takes that raw result and runs it through a second smoothing pass. This pass is based on the square root of your chosen period. This specific mathematical approach allows the indicator to stay responsive to sudden market movements while filtering out minor price fluctuations that might otherwise cause false signals.

3. Visual Directional Mapping The final output translates these complex calculations into two distinct visual lines on your chart:

  • Green Line: This appears when the calculated trend is moving upward.
  • Red Line: This appears when the calculated trend is moving downward.

User Experience

When viewing the chart, you won't see two competing averages overlapping; instead, the script automatically switches colors based on the direction of the momentum. When the trend turns bullish, the Red line disappears and the Green line takes over. When the trend turns bearish, the Green line disappears and the Red line takes over. This provides a clean, binary visual cue to help you identify the prevailing market direction at a glance.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
HMA_v04
//-----------------------
// 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() 
  {
	//---- indicator buffers memory
	IndicatorBuffers(3);

	//---- indicator buffers mapping
	SetIndexBuffer(0, _hmaG);
   SetIndexEmptyValue(0, 0.0);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID,2);

	SetIndexBuffer(1, _hmaR);
   SetIndexEmptyValue(1, 0.0);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID,2);
	
	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;
     }
     
   for(pos=BarsToDraw; pos>=0; pos--) 
     {
      prevGorR=GorR;      
      GorR=iMAOnArray(_wma,0,sqrtPeriod,0,MODE_LWMA,pos);
      if (prevGorR<GorR)
        {
         _hmaG[pos]=GorR;
         _hmaR[pos]=EMPTY_VALUE;
        }
       else
        {
         _hmaG[pos]=EMPTY_VALUE;
         _hmaR[pos]=GorR;
        }
     }
     
  }



Comments