Hull_HAMA_m
Download scriptThis technical indicator is designed to provide a smoothed visual representation of market price movements by combining two advanced mathematical concepts: the Hull Moving Average (HMA) and Heikin-Ashi logic.
The primary goal of this script is to filter out "market noise" and provide a clearer view of the trend than standard moving averages, which often lag behind actual price action. Here is a breakdown of how the logic functions:
Data Processing Core
The indicator starts by calculating several standard moving averages simultaneously for different types of price data (Open, High, Low, and Close). Instead of using a single fixed timeframe, it uses a dynamic calculation method where it takes half of the requested period and doubles it against the full period. This specific mathematical structure is what gives it "Hull" characteristics—it attempts to reduce the delay typically found in traditional indicators while maintaining a smooth curve.
Heikin-Ashi Integration
Once those averages are calculated, the script applies Heikin-Ashi logic. Unlike standard charts where each bar represents independent price action, Heikin-Ashi averages out the data:
- Opening Price: It calculates an average of the previous period's open and close prices to create a stable starting point.
- Closing Price: It takes the average of the current high, low, open, and close.
Visual Output Logic
The script then synthesizes this data into four distinct visual components displayed on your chart:
- Highs and Lows: The indicator identifies the highest and lowest points of the calculated price range. Depending on whether the trend is currently moving upward or downward (based on whether the "Open" is higher or lower than the "Close"), it swaps these values to ensure the visual representation correctly reflects the momentum.
- Opening/Closing Values: It tracks the smoothed open and close prices independently.
User Experience & Customization
The logic is built to be flexible for different trading styles through several adjustable parameters:
- Moving Average Method: Users can choose between different smoothing types (such as Simple, Exponential, Smoothed, or Linear Weighted).
- Period: This defines how much historical data the indicator looks at to determine the current trend.
- Draw Type: The visual style can be toggled between a standard line, a shaded section, or a histogram style, allowing you to choose the visual format that best suits your screen layout.
In summary, this script acts as a "smoothed" lens for price action. It takes raw, erratic market data and processes it through a multi-layered averaging system to help traders identify the underlying trend more clearly.
//+------------------------------------------------------------------+
//| Hull_O_H_L_C.mq4 HA |
//| Copyright © 2007, None |
//|Hull_HAMA_m Planet.Earth.Redistribution |
//+------------------------------------------------------------------+
//mod 2008 fxtsd ki
#property copyright "Copyright © 2007, None"
#property link "Planet.Earth.Redistribution"
//----
#property indicator_chart_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);
//----
haOpen=(ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2;
haClose=(maOpen+maHigh+maLow+maClose)/4;
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;
}
ExtMapBuffer3[pos]=haOpen;
ExtMapBuffer4[pos]=haClose;
// pos--;
}
//----
for (int i=0;i<indicator_buffers;i++) SetIndexDrawBegin(i,Bars-ShowBars);
return(0);
}
//+------------------------------------------------------------------+
Comments