Hull_O_H_L_C_v2

Author: Copyright � 2007, None
Hull_O_H_L_C_v2

This script is a custom technical analysis tool designed to visualize specific price trends on a trading chart. It works by blending two distinct mathematical concepts: the Hull Moving Average (HMA) and Heikin Ashi dynamics. Instead of showing you standard price bars, it creates a smoothed representation of market momentum to help identify trends more clearly.

How the Logic Works

The tool processes your price data through three primary stages to generate its visual output:

1. Advanced Smoothing (Hull Logic) The script first takes four different types of price data—the Open, High, Low, and Close prices—and applies a weighted calculation to them. It uses a "double-weighted" formula: it calculates a moving average of a shorter period and compares it against a longer one. This specific math is designed to reduce the "lag" typically found in standard moving averages, allowing the indicator to react faster to price changes while still maintaining a smooth appearance.

2. Price Integration (Heikin Ashi Logic) Once the smoothed values are calculated, the script applies logic similar to Heikin Ashi candles. It seeks to find the true "center" of the price movement. It looks at the highest and lowest points reached during a period and compares them against the opening and closing prices. This helps filter out "market noise" (random, jagged price movements) and focuses on the overall direction of the trend.

3. Dynamic Trend Rendering Finally, the script uses these calculations to plot four distinct data lines on your chart. These lines are derived from:

  • The smoothed high and low points of the current price action.
  • A calculated "average" opening price based on previous data.
  • A balanced closing price derived from the average of all four price points (High, Low, Open, and Close).

Summary for the User

In plain terms, this script acts as a filter. It takes the chaotic movement of raw market prices and "distills" them into a smoother path. By combining the speed of the Hull Moving Average with the trend-clarity of Heikin Ashi logic, it aims to provide a clearer view of whether the market is moving upward or downward, making it easier to spot sustained trends without being distracted by minor price fluctuations.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Hull_O_H_L_C_v2
//+------------------------------------------------------------------+
//|                                                 Hull_O_H_L_C.mq4 |
//|                                           Copyright © 2007, None |
//|                                      Planet.Earth.Redistribution |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, None"
#property link      "Planet.Earth.Redistribution"
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
//---- parameters
extern int MaMethod =1;
extern int MaPeriod  =60;
extern int DrawType =2;
extern int OpCl_Width= 2;
extern int ShowBars  =250;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double maOpen, maClose, maLow, maHigh;
double haOpen, haHigh, haLow, haClose;
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexDrawBegin(0,MaPeriod);
   SetIndexStyle(0,DrawType,STYLE_SOLID,1);
   SetIndexLabel(0," Mode 0 ");
   //
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,EMPTY_VALUE);
   SetIndexDrawBegin(1,MaPeriod);
   SetIndexStyle(1,DrawType,STYLE_SOLID,1);
   SetIndexLabel(1," Mode 1 ");
   //
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexEmptyValue(2,EMPTY_VALUE);
   SetIndexDrawBegin(2,MaPeriod);
   SetIndexStyle(2,DrawType,STYLE_SOLID,OpCl_Width);
   SetIndexLabel(2," Mode 2 ");
   //
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexEmptyValue(3,EMPTY_VALUE);
   SetIndexDrawBegin(3,MaPeriod);
   SetIndexStyle(3,DrawType,STYLE_SOLID,OpCl_Width);
   SetIndexLabel(3," Mode 3 ");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
   //int pos=Bars-ExtCountedBars-2;
   int pos=ShowBars;
   if (pos>=(Bars-ExtCountedBars-2)) pos=Bars-ExtCountedBars-2;
   while(pos>=0)
     {
      maOpen =iMA(Symbol(),0,MathFloor(MaPeriod/2),0,MaMethod,PRICE_OPEN ,pos)*2-iMA(Symbol(),0,MaPeriod,0,MaMethod,PRICE_OPEN ,pos);
      maClose=iMA(Symbol(),0,MathFloor(MaPeriod/2),0,MaMethod,PRICE_CLOSE,pos)*2-iMA(Symbol(),0,MaPeriod,0,MaMethod,PRICE_CLOSE,pos);
      maLow  =iMA(Symbol(),0,MathFloor(MaPeriod/2),0,MaMethod,PRICE_LOW  ,pos)*2-iMA(Symbol(),0,MaPeriod,0,MaMethod,PRICE_LOW  ,pos);
      maHigh =iMA(Symbol(),0,MathFloor(MaPeriod/2),0,MaMethod,PRICE_HIGH ,pos)*2-iMA(Symbol(),0,MaPeriod,0,MaMethod,PRICE_HIGH ,pos);
//----
      haHigh=MathMax(maHigh, MathMax(haOpen, haClose));
      haLow=MathMin(maLow, MathMin(haOpen, haClose));
      if (haOpen<haClose)
        {
         ExtMapBuffer1[pos]=haLow;
         ExtMapBuffer2[pos]=haHigh;
        }
      else
        {
         ExtMapBuffer1[pos]=haHigh;
         ExtMapBuffer2[pos]=haLow;
        }
      haOpen=(ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2;
      ExtMapBuffer3[pos]=haOpen;
      haClose=(maOpen+maHigh+maLow+maClose)/4;
      ExtMapBuffer4[pos]=haClose;
      pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments