Heiken Ashi 2

Download script
Author: Copyright ?2004, MetaQuotes Software Corp.
Heiken Ashi 2

This script is designed to transform the standard visual representation of financial price action into a specialized charting style known as Heiken Ashi. Unlike traditional candlestick charts, which can sometimes appear noisy or erratic due to minor price fluctuations, this tool smooths out the data to provide a clearer picture of market trends and momentum.

How the Logic Works

The script operates by recalculating the price points of each candle based on a specific mathematical relationship between previous price history and current movement. Here is a breakdown of the logic used:

  • Smoothing the Trend: Instead of showing raw prices, the script calculates a new "Average Open" and "Average Close" for every period. By averaging these values with the preceding candles, the chart filters out "market noise," making it easier for traders to identify if the underlying trend is bullish (upward) or bearish (downward).
  • Dynamic Highs and Lows: The script automatically adjusts the top and bottom boundaries of each candle. It ensures that the high and low points reflect the true extremes of the price movement while remaining consistent with the smoothed open and close values.
  • Visual Distinction: The logic categorizes candles into two distinct types based on the relationship between the calculated open and close prices:
    • If the closing price is higher than the opening price, the script renders the candle in one color (Yellow), signifying upward momentum.
    • If the closing price is lower than the opening price, it renders the candle in another color (Magenta), signifying downward momentum.
  • Continuous Flow: The calculations are designed to be sequential. Each new candle's data depends on the values calculated for the candle immediately preceding it. This creates a seamless visual flow, allowing traders to see the continuity of a trend more effectively than they might on a standard chart.

Purpose for the User

The primary goal of this logic is clarity. By stripping away the volatility of tick-by-tick price changes and replacing them with smoothed, averaged data, the script helps users stay focused on the "big picture." It allows for a more intuitive understanding of market direction, helping to identify when a trend is strengthening or beginning to weaken.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
Heiken Ashi 2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                  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 Yellow
#property indicator_color2 Magenta
#property indicator_color3 Yellow
#property indicator_color4 Magenta
//---- 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, Yellow);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, Magenta);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 2, Yellow);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 2, Magenta);
   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