HMA_vUnKnown

Download script
HMA_vUnKnown

This technical tool is designed to provide traders with a smoother and more responsive way to track price trends on a trading chart. It utilizes a specialized mathematical approach called the Hull Moving Average (HMA), which aims to eliminate the "lag" typically found in standard moving averages while maintaining a fluid visual line.

How the Logic Works

Instead of simply averaging past prices in a straight line, this script processes market data through a multi-layered calculation:

1. Weighted Price Comparison The logic begins by looking at two different sets of data simultaneously. It calculates a weighted average of the recent price movements at two different scales (half of your chosen period and the full period). By subtracting one from the other and multiplying it by a constant factor, the script identifies the core momentum of the market. This specific calculation helps strip away minor "noise" and focuses on the underlying direction of the price.

2. Smoothing the Momentum Once that initial momentum is identified, the tool performs a second layer of smoothing. It takes the results of the first calculation and runs them through another weighted average. This secondary pass rounds out the line, ensuring that the final visual output is not jagged or erratic, but rather a smooth curve that follows the price closely.

3. Visual Result The end result for the user is a single blue line on the chart. Because of this double-calculation process, the line reacts much faster to sudden price changes than a traditional moving average would, yet it remains stable enough to be used as a reliable signal for identifying current market trends.

Key Features for the User

  • Reduced Delay: By using a weighted approach rather than a simple average, the indicator stays closer to the actual "live" price.
  • Customizable Period: Users can adjust the HMA_Period setting to make the line more sensitive (shorter period) or more stable (longer period) depending on their specific trading style.
  • Clean Visualization: The tool is designed to automatically calculate where it should begin appearing on your chart, ensuring that the visual data remains clean and relevant to the current price action.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
HMA_vUnKnown
//+------------------------------------------------------------------+
//|                                                 HMA_vUnKnown.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"

//---- indicator settings

#property  indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  Blue

//#property  indicator_color2 White

//---- indicator parameters

extern int HMA_Period=20;

//---- indicator buffers

double     ind_buffer0[];
double     ind_buffer1[];

int        draw_begin0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {

//---- indicator buffers mapping

   IndicatorBuffers(2);
   if(!SetIndexBuffer(0,ind_buffer0) && !SetIndexBuffer(1,ind_buffer1))
      Print("cannot set indicator buffers!");
//   ArraySetAsSeries(ind_buffer1,true);

//---- drawing settings
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   
   draw_begin0=HMA_Period+MathFloor(MathSqrt(HMA_Period));
   SetIndexDrawBegin(0,draw_begin0);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);

//---- name for DataWindow and indicator subwindow label

   IndicatorShortName("HMA("+HMA_Period+")");
   SetIndexLabel(0,"Hull Moving Average");

//---- initialization done
   return(0);
  }

//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+

int start()
  {
   int limit,i;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<1)
     {
      for(i=1;i<=draw_begin0;i++) ind_buffer0[Bars-i]=0;
      for(i=1;i<=HMA_Period;i++) ind_buffer1[Bars-i]=0;
     }
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- MA difference counted in the 1-st buffer
   for(i=0; i<limit; i++)
    {  
      double Exp = 2;
      double firstprice = iMA(NULL,0,MathFloor(HMA_Period/2),0,MODE_LWMA,PRICE_CLOSE,i);
      double secondprice = iMA(NULL,0,HMA_Period,0,MODE_LWMA,PRICE_CLOSE,i);
      
      ind_buffer1[i] = (Exp*firstprice)-secondprice;
    }
//---- HMA counted in the 0-th buffer
   for(i=0; i<limit; i++)
    {
      ind_buffer0[i]=iMAOnArray(ind_buffer1,0,MathFloor(MathSqrt(HMA_Period)),0,MODE_LWMA,i);
    }
//---- done
   return(0);
  }

Comments