Hull Trend1

Download script
Hull Trend1

This tool is designed to provide traders with a visual representation of market trends by utilizing the Hull Moving Average (HMA) logic. Unlike standard moving averages that can sometimes lag behind price action, this script focuses on smoothing out price fluctuations while maintaining high sensitivity to recent market changes.

How the Logic Works

The script operates through a multi-step calculation process to determine the current trend direction:

1. Data Processing and Smoothing The indicator begins by calculating a series of weighted moving averages. It takes a portion of the requested period (half of the main period) and compares it against the full period. By subtracting the larger average from twice the smaller one, the script creates a unique data set that highlights the "velocity" or momentum of price movement.

2. Hull Trend Calculation The script then applies a secondary smoothing pass on this processed data. This involves taking the square root of the primary period to determine the final smoothing factor. The result is the "Hull Moving Average"—a curve intended to be much more responsive to sudden price turns than a conventional moving average would be.

3. Trend Identification and Visual Cues The core logic compares the initial processed data against the final Hull Moving Average:

  • Bullish Sentiment: When the initial movement exceeds the smoothed trend line, the script identifies an upward bias.
  • Bearish Sentiment: When the initial movement falls below the smoothed trend line, it identifies a downward bias.

4. Visual Output To make this information easy to read on a chart, the script automatically plots the price highs and lows based on these conditions. It effectively "colors" the trend by highlighting the boundaries of price action; when the trend is up, it focuses on the high-side data, and when the trend turns down, it flips to highlight the low-side data.

Summary for the User

The primary goal of this script is to filter out market "noise." By using the Hull Moving Average logic, it provides a cleaner look at where the price is heading, helping you identify whether the current momentum is leaning toward a breakout or a retracement without the significant delay often found in traditional technical indicators.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
18 Views
0 Downloads
0 Favorites
Hull Trend1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                   Hull Trend.mq4 |
//|                                     Copyright © 2005, adoleh2000 |
//|                                             adoleh2000@yahoo.com |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, adoleh2000."
#property  link      "adoleh2000@yahoo.com"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 4
#property  indicator_color1  Blue
#property  indicator_color2  Red
#property  indicator_color3  EMPTY
#property  indicator_color4  EMPTY



//---- indicator parameters
extern int HMA_Period=20;
extern double Price=PRICE_OPEN;
extern double Displacement=0;
//---- indicator buffers
double ind_buffer0[];
double ind_buffer1[];
double HighBuffer[];
double LowBuffer[];



int        draw_begin0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   //IndicatorBuffers(4);
//   ArraySetAsSeries(ind_buffer1,true);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
   

   SetIndexBuffer(0,HighBuffer);
   SetIndexBuffer(1,LowBuffer);
   SetIndexBuffer(2,ind_buffer0);
   SetIndexBuffer(3,ind_buffer1);



   draw_begin0=HMA_Period+MathFloor(MathSqrt(HMA_Period));

   SetIndexDrawBegin(0,draw_begin0);
   SetIndexDrawBegin(1,draw_begin0);
   SetIndexDrawBegin(2,draw_begin0); 
   SetIndexDrawBegin(3,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,shift;
   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++)
      ind_buffer1[i]=iMA(NULL,0,MathFloor(HMA_Period/2),0,MODE_LWMA,Price,i)*2-iMA(NULL,0,HMA_Period,0,MODE_LWMA,Price,i);
//---- 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+Displacement);
      
      //Comment ("MA=",ind_buffer1[i],"; ","HMA=",ind_buffer0[i]);

for (shift=i; shift>=0;shift--)
{
      if (ind_buffer1[shift] > ind_buffer0[shift]) 
   { 
      HighBuffer[shift]=High[shift];
      LowBuffer[shift]=Low[shift]; 
   }
   
   else

if (ind_buffer1[shift]<  ind_buffer0[shift]) 
   { 
      LowBuffer[shift]=High[shift];
      HighBuffer[shift]=Low[shift];
    }
}
//---- done
   return(0);
  }

Comments