Author: mladen

This technical indicator is designed to provide a smoothed visual representation of price movement on a trading chart. By analyzing historical data, it aims to filter out market "noise" to help traders identify the underlying trend more clearly.

Core Functionality

The script operates by calculating a specialized moving average known as a Hull Moving Average. Unlike standard moving averages that can be sluggish or lag significantly behind current price action, this specific logic uses a multi-step mathematical approach to achieve a balance between smoothness and responsiveness.

Key Components of the Logic:

  • Customizable Price Input: The tool allows you to choose which specific data point from a candle should be used for its calculations. You can select the standard Closing price, the Opening price, the High or Low points, or various mathematical averages (such as Median, Typical, Weighted, or full Average). This flexibility ensures the indicator can be tuned to different trading styles.

  • Advanced Smoothing Process: The script processes the data through three distinct layers of calculation:

    1. It first looks at a "Half Period" of the data to capture immediate momentum.
    2. It then compares this against a full "Hull Period" to establish a baseline.
    3. Finally, it applies a third smoothing pass to ensure the resulting line is fluid and easy to read visually.
  • Dynamic Color Signaling: One of the most user-friendly features of this script is its integrated color-coding system. Instead of just providing a line, the indicator changes color based on the direction of the price movement:

    • Green: Appears when the current value is rising compared to the previous point, signaling bullish momentum.
    • Orange: Appears when the current value is falling compared to the previous point, signaling bearish momentum.

Summary for Traders

This tool acts as a visual guide for market direction. By providing a smoothed line that shifts colors based on trend changes, it helps you stay aligned with the prevailing market move while minimizing the interference of small, insignificant price fluctuations. It is designed to be highly adaptable, allowing you to adjust the "length" and "power" of the calculation to suit different timeframes or asset types.

12 Views
0 Downloads
0 Favorites
hull_
//------------------------------------------------------------------
#property copyright "mladen"
#property link      "mladen"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_label1  "hull"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  clrLimeGreen,clrOrange
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

//
//
//
//
//

enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average     // Average (high+low+oprn+close)/4
};

input double   HmaLength =   14;     // Hull period
input double   HmaPower  =    1;     // Hull power
input enPrices Price     = pr_close; // Price

double hull[];
double colorInd[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnInit()
{
   SetIndexBuffer(0,hull    ,INDICATOR_DATA); 
   SetIndexBuffer(1,colorInd,INDICATOR_COLOR_INDEX); 
   return(0);
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
{
   //
   //
   //
   //
   //
   
   int HalfPeriod = (int)MathFloor(HmaLength/2);
   int HullPeriod = (int)MathFloor(MathSqrt(HmaLength));
   for (int i=(int)MathMax(prev_calculated-1,1); i<rates_total; i++)
   {
      double price       = getPrice(Price,open,close,high,low,rates_total,i);
             hull[i]     = iLwmp(2.0*iLwmp(price,HalfPeriod,HmaPower,rates_total,i,0)-iLwmp(price,HmaLength,HmaPower,rates_total,i,1),HullPeriod,HmaPower,rates_total,i,2);
             colorInd[i] = colorInd[i-1];
               if (hull[i]>hull[i-1]) colorInd[i] = 0;
               if (hull[i]<hull[i-1]) colorInd[i] = 1;
   }
   return(rates_total);
}


//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------
//
//
//
//
//

double getPrice(enPrices price, const double& open[], const double& close[], const double& high[], const double& low[], int bars, int i)
{
   switch (price)
   {
      case pr_close:     return(close[i]);
      case pr_open:      return(open[i]);
      case pr_high:      return(high[i]);
      case pr_low:       return(low[i]);
      case pr_median:    return((high[i]+low[i])/2.0);
      case pr_typical:   return((high[i]+low[i]+close[i])/3.0);
      case pr_weighted:  return((high[i]+low[i]+close[i]+close[i])/4.0);
      case pr_average:   return((high[i]+low[i]+close[i]+open[i])/4.0);
   }
   return(0);
}

//------------------------------------------------------------------
//                                                                 
//------------------------------------------------------------------
//
//
//
//
//

double workLwmp[][3];
double iLwmp(double price, double period, double power, int bars, int r, int instanceNo=0)
{
   if (ArrayRange(workLwmp,0)!= bars) ArrayResize(workLwmp,bars);
   
   //
   //
   //
   //
   //
   
   workLwmp[r][instanceNo] = price;
      double sumw = MathPow(period,power);
      double sum  = sumw*price;
      for(int k=1; k<period && (r-k)>=0; k++)
      {
         double weight = period-k;
                sumw  += MathPow(weight,power);
                sum   += MathPow(weight,power)*workLwmp[r-k][instanceNo];  
      }             
   return(sum/sumw);
}

Comments