Heiken Ashi(05SEP05)

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
Heiken Ashi(05SEP05)

This script is designed to transform the standard visual representation of price movements into a specialized charting method known as Heiken Ashi. While standard candlesticks show you the raw "open," "high," "low," and "close" prices for each period, this tool smooths out the market noise to provide a clearer picture of the underlying trend.

How the Logic Works

Instead of relying solely on the erratic price spikes of a single timeframe, the script calculates four new values for every bar on your chart:

  • The Opening Price: It determines the start of a candle by taking the average of the previous candle's opening and closing values. This creates a sense of continuity between periods.
  • The Closing Price: It calculates the end of a candle by finding the average of the current period's four price points (Open, High, Low, and Close).
  • The Highs and Lows: The script then identifies the true boundaries of the candle by comparing the standard high and low prices against the newly calculated open and close values. This ensures that the visual "wick" or body of the candle accurately reflects the full range of price movement.

Visual Representation

Once these calculations are performed, the script renders them as a histogram on your screen. It uses a specific color logic to help you identify market momentum:

  • Bullish Movement: When the calculated closing price is higher than the opening price, the script identifies this as upward momentum.
  • Bearish Movement: Conversely, if the opening price is higher than the closing price, it signals downward pressure.

Practical Benefit for Traders

By using this logic, the resulting chart filters out minor fluctuations that can often lead to "false starts" in trading. It allows you to see the flow of the market more naturally—making it easier to identify whether the current trend is sustained or if a reversal is beginning to form. For the best experience, the script recommends adjusting your chart settings to a "Line Chart" style with a black background to let the red and white indicators stand out clearly.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
Heiken Ashi(05SEP05)
//+------------------------------------------------------------------+
//|                                                  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 White
#property indicator_color3 Red
#property indicator_color4 White
//---- 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, White);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, Red);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, White);
   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);
//---- 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]=haLow;
         ExtMapBuffer2[pos]=haHigh;
        } 
      else
        {
         ExtMapBuffer1[pos]=haHigh;
         ExtMapBuffer2[pos]=haLow;
        } 
      ExtMapBuffer3[pos]=haOpen;
      ExtMapBuffer4[pos]=haClose;
 	   pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments