Author: Copyright � 2007, None
Hull_HAMA

This tool is designed to provide traders with a visual representation of market trends by combining two distinct technical analysis concepts: the Hull Moving Average (HMA) and Heikin Ashi price dynamics. Instead of looking at standard price movements, which can be volatile and "noisy," this script smooths out the data to help identify the underlying direction of the market more clearly.

Core Logic Overview

The script operates by processing four key pieces of price information—the High, Low, Open, and Close prices—through a multi-step calculation:

1. Smoothing the Foundation (Hull Logic) The tool first takes the raw price data and applies a weighted moving average. It uses a specific mathematical formula that weights recent prices more heavily while still maintaining a smooth curve. This ensures that the indicator reacts quickly to new market changes without the jagged, erratic movements seen in traditional averages.

2. Synthesizing Heikin Ashi Dynamics Once the price data is smoothed, the script applies "Heikin Ashi" logic. Heikin Ashi is a type of charting technique where the "Open" and "Close" prices are averaged to create a more balanced view of price action. By integrating this with the smoothed Hull data, the script creates a synchronized flow that emphasizes the momentum of the trend.

3. Determining Trend Boundaries The script generates four distinct data points (buffers) to display on your chart:

  • Highs and Lows: It identifies the upper and lower boundaries of the price movement based on the smoothed averages.
  • Balanced Open/Close: It calculates a neutralized "Open" price by averaging previous values, which helps in identifying where the trend is originating from.

Visual Interpretation

The final output provides you with a clear visual path:

  • It highlights the Highs and Lows of the smoothed trend, allowing you to see the outer limits of current price momentum.
  • It displays the Open/Close values, which helps in identifying whether the current price "body" is moving upward or downward relative to its recent history.

Summary for the User

In plain terms, this script acts as a trend filter. It strips away the minor fluctuations of the market and replaces them with a fluid, smoothed representation of price movement. By combining the speed of the Hull Moving Average with the stability of Heikin Ashi prices, it aims to show you the "true" direction of the trend, making it easier to identify whether the market is in a sustained bullish or bearish phase.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Hull_HAMA
//+------------------------------------------------------------------+
//|                                              Hull_O_H_L_C.mq4 HA |
//|                                           Copyright © 2007, None |
//|Hull_HAMA                             Planet.Earth.Redistribution |
//+------------------------------------------------------------------+
//mod 2008 fxtsd  ki 
#property copyright "Copyright © 2007, None"
#property link      "Planet.Earth.Redistribution"
//----
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 OrangeRed
#property indicator_color2 RoyalBlue
#property indicator_color3 Red
#property indicator_color4 DodgerBlue
//---- parameters
extern int MaMethod =3;  //0-3
extern int MaPeriod  =14;
extern int DrawType =2;  //0-2
extern int OpCl_Width= 2;
extern int ShowBars  =1200;
extern string  notes_ =  "MaMethod: SMA0 EMA1 SMMA2 LWMA3; DrawType: 0line 1section 2Histo";

//---- 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,"Hull_HA("+MaPeriod+")Hi ");
   //
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,EMPTY_VALUE);
//   SetIndexDrawBegin(1,MaPeriod);
   SetIndexStyle(1,DrawType,STYLE_SOLID,1);
   SetIndexLabel(1,"Hull_HA("+MaPeriod+")Lo");
   //
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexEmptyValue(2,EMPTY_VALUE);
//   SetIndexDrawBegin(2,MaPeriod);
   SetIndexStyle(2,DrawType,STYLE_SOLID,OpCl_Width);
   SetIndexLabel(2,"Hull_HA("+MaPeriod+")OpCl");
   //
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexEmptyValue(3,EMPTY_VALUE);
 //  SetIndexDrawBegin(3,MaPeriod);
   SetIndexStyle(3,DrawType,STYLE_SOLID,OpCl_Width);
   SetIndexLabel(3,"Hull_HA("+MaPeriod+")ClOp");
//---- 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);
   if(Bars<=MathPow(MaPeriod,2)) return(0);
   int   CountedBars=IndicatorCounted();
//---- check for possible errors
   if (CountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (CountedBars>0) CountedBars--;
   //int pos=Bars-ExtCountedBars-2;
   int pos,limit;
   //if (pos>=(Bars-ExtCountedBars-2)) pos=Bars-ExtCountedBars-2;
    limit=Bars-CountedBars;
    limit = MathMin(limit, ShowBars+MathPow(MaPeriod,2));

   for (pos=limit;pos>=0;pos--)
  { 
  //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--;
  }
//----

    for (int i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-ShowBars);   

   return(0);
  }
//+------------------------------------------------------------------+

Comments