Heiken Ashi-mod

Download script
Author: Copyright � 2004, MetaQuotes Software Corp., -mod by Ibrahim
Heiken Ashi-mod

This specialized trading tool transforms the standard price chart into a Heiken Ashi visualization. Unlike traditional candlestick charts, which show the raw price action of each period, this script applies a specific mathematical smoothing technique to make market trends much easier to identify and analyze.

Core Logic and Functionality

The script works by recalculating the "Open," "High," "Low," and "Close" values for every candle based on a combination of previous data points rather than just the raw price at that exact moment. Here is how it processes that information:

  • Price Smoothing: Instead of showing jagged, erratic movements, the script calculates an averaged "Open" and "Close." By mixing the previous period's average with the current period's high and low extremes, it filters out "market noise."
  • Dynamic Range Calculation: It determines the highest and lowest points of each candle by comparing the actual market highs and lows against the newly calculated smoothed averages. This ensures that even though the data is smoothed, it still stays anchored to the real price boundaries.
  • Visual Indicators: The logic feeds four distinct data streams into your chart:
    1. Heiken Ashi High: The maximum point of the smoothed candle.
    2. Heiken Ashi Low: The minimum point of the smoothed candle.
    3. Heiken Ashi Open: The starting price point of the smoothed candle.
    4. Heiken Ashi Close: The ending price point of the smoothed candle.

How it Benefits the User

By using this logic, the chart produces candles that represent the momentum of the market rather than just the raw price.

  • Trend Clarity: It allows you to see if the market is trending upward or downward more clearly because the "noise" of small, insignificant price fluctuations is minimized.
  • Consistent Coloring: The script uses these values to create visual consistency, helping traders quickly spot shifts in sentiment (for example, seeing a steady change in candle color or size as the trend matures).
  • Enhanced Perspective: Because it calculates the "Open" of the current candle based on the previous candle's average, it creates a more fluid, continuous flow of price action on your screen.
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Heiken Ashi-mod
//+------------------------------------------------------------------+
//|                                                  Heiken Ashi.mq4 |
//|                      Copyright c 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                               |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                              Heiken Ashi-mod.mq4 |
//|                                                       by Ibrahim |
//|                           http://winning-solution.com/?id=baim78 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp., -mod by Ibrahim"
#property link      "http://www.metaquotes.net"
#property link      "http://winning-solution.com/?id=baim78"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3

//----
extern color color1 = Red;
extern color color2 = Blue;
extern color color3 = Red;
extern color color4 = Blue;
//---- 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, color1);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, color2);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, color3);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, color4);
   SetIndexBuffer(3, ExtMapBuffer4);
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   SetIndexDrawBegin(2,10);
   SetIndexDrawBegin(3,10);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
//---- indicator label
	SetIndexLabel(0,"Heiken Ashi - High");
	SetIndexLabel(1,"Heiken Ashi - Low");
	SetIndexLabel(2,"Heiken Ashi - Open");
	SetIndexLabel(3,"Heiken Ashi - Close");
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom 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));
      ExtMapBuffer1[pos]=haHigh;
      ExtMapBuffer2[pos]=haLow;
      ExtMapBuffer3[pos]=haOpen;
      ExtMapBuffer4[pos]=haClose;
 	   pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments