Heiken_Ashi_Mod_Matt
Download scriptThis script is designed to transform standard price charts into a specialized visual format known as Heiken Ashi. Unlike traditional candlestick charts, which show the exact price action for each specific time period, Heikin Ashi candles are calculated to provide a smoothed, "averaging" view of market trends. This makes it significantly easier for traders to identify the underlying momentum and direction of the market by filtering out minor price fluctuations or "noise."
How the Logic Works
The script operates by mathematically reconstructing the price data on your screen using the following logic:
1. Smoothing the Price Data Instead of simply plotting the high, low, open, and close prices of a single moment, the script calculates a new set of values. It determines the "Open" and "Close" of the Heiken Ashi candles by averaging price points from previous periods. This creates a continuous flow where each new candle is visually linked to its predecessor, allowing for a more cohesive view of whether the market is moving upward or downward.
2. Dynamic Price Range Calculation The script looks at the highest and lowest prices reached during a period. It then compares these against the newly calculated "Average Open" and "Average Close." By finding the maximum and minimum between these values, the script ensures that the visual "wick" (the thin line above or below the candle body) accurately reflects the true volatility of the price while remaining consistent with the smoothed trend.
3. Visual Trend Identification The script uses a conditional logic to determine the color and body size of the candles:
- Bullish Movement: If the calculated average closing price is higher than the opening price, the script identifies this as an upward trend.
- Bearish Movement: If the average closing price is lower than the opening price, it identifies a downward trend.
4. Real-Time Rendering The tool automatically scans through your chart history and updates the visual data point by point. It ensures that as new market data arrives, the Heiken Ashi candles are recalculated instantly, providing a real-time updated view of the market's "true" direction based on these smoothed averages.
Summary for the User
By using this script, you are moving away from the "choppy" nature of standard price bars and toward a visualization that emphasizes trend persistence. It is specifically designed to help you see the "big picture"—making it easier to spot when a trend is strengthening, weakening, or potentially reversing.
//+------------------------------------------------------------------+
//| 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, Red);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, RoyalBlue);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM, 0, 1, Red);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM, 0, 1, RoyalBlue);
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=(ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2;
haClose=(Open[pos]+High[pos]+Low[pos]+Close[pos])/4;
haHigh=MathMax(High[pos], MathMax(haOpen, haClose));
haLow=MathMin(Low[pos], MathMin(haOpen, haClose));
if (haOpen<haClose)
{
ExtMapBuffer1[pos]=haClose;
ExtMapBuffer2[pos]=haOpen;
}
else
{
ExtMapBuffer1[pos]=haOpen;
ExtMapBuffer2[pos]=haClose;
}
ExtMapBuffer3[pos]=haOpen;
ExtMapBuffer4[pos]=haClose;
pos--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments