Heiken Ashi BG

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
Heiken Ashi BG

This script is designed to transform standard price charts into a specialized visual format known as Heiken Ashi. For traders, this means moving away from traditional candlestick data to a smoothed representation of market momentum.

How the Logic Works

Unlike standard charts that show the raw open, high, low, and close prices for each period, this script calculates "synthetic" price points based on a blend of historical data and current averages. Here is the breakdown of how it processes that information:

1. Smoothing the Price Action The script takes the previous period's results and averages them with the current period's raw data. By combining the high, low, open, and close prices into a single average, it filters out "market noise"—those small, erratic price flickers that can often confuse a trader.

2. Calculating Synthetic Values For every bar on your chart, the script performs three specific calculations:

  • Synthetic Open: It takes the average of the previous bar's high and low values. This helps establish a steady starting point for the current price movement.
  • Synthetic Close: It calculates the average of the current bar's four main data points (Open, High, Low, and Close).
  • Dynamic Extremes: It identifies the highest and lowest points of the period by comparing the actual market highs and lows against the new synthetic open and close values.

3. Visual Representation Once these values are calculated, the script determines how to draw the bars on your screen:

  • If the Synthetic Close is higher than the Synthetic Open, the script interprets this as upward momentum.
  • If the Synthetic Close is lower than the Synthetic Open, it interprets this as downward momentum.

The End Result

By using this logic, the chart provides a much "cleaner" look. Instead of seeing every minor price fluctuation, you see a smoother trend. This makes it significantly easier to identify whether the market is trending up, down, or moving sideways, as the visual bars emphasize the direction of the move rather than just the raw price extremes.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Heiken Ashi BG
//+------------------------------------------------------------------+
//|                                                  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, LightSkyBlue);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, LightPink);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 1, LightSkyBlue);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 1, LightPink);
   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