This tool is designed to transform the way you visualize price action on your trading charts by applying the Heiken Ashi methodology. Instead of looking at standard candlesticks, which can often be noisy and provide cluttered information, this script processes raw market data to generate a smoother, more streamlined representation of price trends.
How the Logic Works
The core functionality of this script revolves around filtering out "market noise" to highlight the underlying direction of the price movement. Here is the step-by-step logic used by the script:
- Data Collection: The script continuously monitors the four primary pillars of market data: the Opening price, the Closing price, the Highest point reached (High), and the Lowest point reached (Low) for every historical bar on your chart.
- Price Comparison: For every specific moment in time, the script compares the opening and closing prices. It looks to determine if the momentum was bullish (closing higher than it opened) or bearish (closing lower than it opened).
- Trend Smoothing: Rather than simply plotting the raw high and low prices, the script reassigns these values based on the momentum detected. If the price is moving upward, it prioritizes the lower bounds to create a steady visual flow; if the price is moving downward, it prioritizes the upper bounds.
- Visual Mapping: Finally, the script maps these calculated values onto your chart using four distinct buffers. This results in a histogram-style display where the colors and heights of the bars represent the strength and direction of the trend more clearly than standard pricing charts.
Key Takeaways for Traders
The primary objective of this logic is clarity. By recalculating the price boundaries based on trend momentum, the script helps traders:
- Identify the prevailing trend with less visual distraction.
- Easily distinguish between periods of expansion (strong movement) and contraction (consolidation).
- Maintain a cleaner perspective on price history by focusing on the "smoothed" trend rather than every minor fluctuation in the middle of a candle.
//+------------------------------------------------------------------+
//| Heiken Ashi.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
//| For Heiken Ashi we recommend next chart settings ( press F8 or |
//| select on menu 'Charts'->'Properties...'): |
//| - On 'Color' Tab select 'Black' for 'Line Graph' |
//| - On 'Common' Tab disable 'Chart on Foreground' checkbox and |
//| select 'Line Chart' radiobutton |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 RoyalBlue
#property indicator_color3 Red
#property indicator_color4 RoyalBlue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3);
SetIndexBuffer(3, ExtMapBuffer4);
//----
SetIndexDrawBegin(0,5);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexBuffer(3,ExtMapBuffer4);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double haOpen, haHigh, haLow, haClose;
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-1;
while(pos>=0)
{
haOpen=Open[pos];
haClose=Close[pos];
haHigh=High[pos];
haLow=Low[pos];
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);
}
//+------------------------------------------------------------------+
Comments