HAMA Lines
Download scriptThis tool is designed to provide visual clarity on your trading charts by transforming standard price movements into a smoothed, stylized trend visualization. It operates by layering different mathematical calculations to filter out market "noise," making it easier to identify the underlying direction of the price action.
Core Logic and Behavior
The script functions through a multi-step processing sequence that interprets raw market data into specialized trend lines:
1. Data Smoothing Foundation At its base, the indicator looks at standard moving average components—specifically the high, low, open, and close prices over a user-defined period (defaulting to 20). By using these averages instead of raw price points, the tool creates a more stable foundation for trend analysis.
2. Hybrid Price Reconstruction The script performs a sophisticated calculation to "reconstruct" price candles. It takes the smoothed data from the moving averages and combines it with its own previous calculations to determine new high and low values. This process ensures that the resulting lines are cohesive and do not jump erratically between price movements.
3. Dynamic Trend Identification The logic continuously compares the "opening" and "closing" values of these reconstructed points:
- If the calculated closing value is higher than the opening value, the tool identifies an upward sentiment.
- If the closing value is lower than the opening value, it identifies a downward sentiment.
4. Visual Output The final result is rendered on your chart as distinct lines that represent these smoothed price boundaries. By simplifying complex price fluctuations into clear, color-coded paths (Red and Lime), the indicator helps traders visualize whether the current momentum is shifting or remaining steady without the distraction of every minor price tick.
Technical Requirements
For the indicator to function correctly within your trading environment, it includes a safety check that verifies specific global variables. This ensures that the "system" environment is properly initialized before it begins drawing the trend data on your screen.
//+------------------------------------------------------------------+
//| HAMA_20.mq4 |
//+------------------------------------------------------------------+
//| mod by Raff |
//+------------------------------------------------------------------+
#property copyright "Raff/Personalized and Adapted for HAMA Z3 TradingWithPALS"
#property link "http://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Lime
//---- parameters
extern int MaMetod = 1;
extern int MaPeriod = 20;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
//---- indicators
GlobalVariableSet("HL_"+Period()+Symbol(), 1);
SetIndexStyle(0,DRAW_NONE, 0, 1, Red); //Kale, How do I remove this from the Indicator PopUp Box when attached to the Chart//
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_NONE, 0, 1, Lime); //Kale, How do I remove this from the Indicator PopUp Box when attached to the Chart//
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE, 2, 0, Red);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3,DRAW_LINE, 2, 0, Lime);
SetIndexBuffer(3, ExtMapBuffer4);
//----
SetIndexDrawBegin(0,5);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexBuffer(3,ExtMapBuffer4);
//---- initialization done
watermark();
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
GlobalVariableDel("HL_"+Period()+Symbol());
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if(Bars<=10) return(0);
int pos=Bars;
if(!checkSystem())
{
for (int i=pos; i>=0; i--)
{
ExtMapBuffer1[i] = 0;
ExtMapBuffer2[i] = 0;
ExtMapBuffer3[i] = 0;
ExtMapBuffer4[i] = 0;
}
return(0);
}
else
{
double maOpen, maClose, maLow, maHigh;
double haOpen, haHigh, haLow, haClose;
while(pos>=0)
{
maOpen=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_OPEN,pos);
maClose=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_CLOSE,pos);
maLow=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_LOW,pos);
maHigh=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_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--;
}
//----
}
return(0);
}
//+------------------------------------------------------------------+
void watermark()
{
ObjectCreate("fxcruiser HAMA PAD", OBJ_LABEL, 0, 0, 0);
ObjectSetText("fxcruiser HAMA PAD", "fxcruiser HAMA PAD", 6, "Lucida Handwriting", RoyalBlue);
ObjectSet("fxcruiser HAMA PAD", OBJPROP_CORNER, 2);
ObjectSet("fxcruiser HAMA PAD", OBJPROP_XDISTANCE, 5);
ObjectSet("fxcruiser HAMA PAD", OBJPROP_YDISTANCE, 25);
return(0);
}
bool checkSystem()
{
int ha = GlobalVariableGet("HA_"+Period()+Symbol());
int hb = GlobalVariableGet("HB_"+Period()+Symbol());
int hl = GlobalVariableGet("HL_"+Period()+Symbol());
return(true);
Alert("MISSING SYSTEM INDICATORS!!!\nSYSTEM WILL TURN OFF AT NEXT TICK");
return(false);
}
Comments