Cleon Heiken Ashi_v2

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
Cleon Heiken Ashi_v2

This tool is designed to transform the standard way price movements are displayed on a trading chart. While traditional charts show raw, often "noisy" price data, this script converts that information into Heiken Ashi bars, which are intended to provide a smoother, more readable visualization of market trends.

Core Logic and Functionality

The primary purpose of this script is to recalculate the traditional open, high, low, and close prices into a modified format. Instead of simply reflecting the exact price at a specific second, it uses a mathematical blend of previous data to create a continuous flow.

How the transformation works:

  • Trend Smoothing: The logic takes the average of the previous bar's opening and closing values to determine the current bar's starting point. By doing this, it filters out minor price fluctuations that can often lead to "false signals" in standard charts.
  • Price Averaging: The closing price of each new bar is calculated by taking the average of four components: the current high, low, open, and close. This creates a balanced representation of the price action over that specific period.
  • Dynamic Highs and Lows: The script ensures that the highest and lowest points of each bar are always logically consistent with the new averaged prices. It compares the actual market highs and lows against the newly calculated values to ensure the bars accurately encompass the entire range of movement.

Visual Representation

To make this data easy for a human to interpret, the script organizes these calculations into four distinct layers:

  1. The Body: The "Open" and "Close" values are plotted to create the main body of the bar. The color and direction of this body help traders instantly identify if the market is in an uptrend or a downtrend.
  2. The Wicks: The "High" and "Low" values are plotted as thin lines (wicks) extending from the body. These show the extremes of the price movement while keeping the focus on the overall trend.

User Experience

For the person viewing the chart, this script removes the "jitter" of standard candlesticks. By smoothing out the price history, it allows for a clearer view of the momentum. It simplifies the visual environment so that you can see where the market is heading more clearly, making it easier to identify sustained trends rather than getting distracted by momentary price spikes.

13 Views
0 Downloads
0 Favorites
Cleon Heiken Ashi_v2
//+------------------------------------------------------------------+
//|                                                  Heiken Ashi.mq4 |
//|                      Copyright c 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Coral
#property indicator_color2 DeepSkyBlue
#property indicator_color3 HotPink
#property indicator_color4 DodgerBlue

//---- buffers
   double
      ExtMapBuffer1[],
      ExtMapBuffer2[],
      ExtMapBuffer3[],
      ExtMapBuffer4[];
      
//---- vars
   int
      ExtCountedBars=0;

int init() {

   //---- indicators
   SetIndexStyle  (0, DRAW_HISTOGRAM, 0, 1, Coral);
   SetIndexBuffer (0, ExtMapBuffer1);
   SetIndexLabel  (0, "HA Max / Min");
   SetIndexStyle  (1, DRAW_HISTOGRAM, 0, 1, DeepSkyBlue);
   SetIndexBuffer (1, ExtMapBuffer2);
   SetIndexLabel  (1, "HA Max / Min");
   SetIndexStyle  (2, DRAW_HISTOGRAM, 0, 4, HotPink);
   SetIndexBuffer (2, ExtMapBuffer3);
   SetIndexLabel  (2, "HA Open");
   SetIndexStyle  (3, DRAW_HISTOGRAM, 0, 4, DodgerBlue);
   SetIndexBuffer (3, ExtMapBuffer4);
   SetIndexLabel  (3, "HA Close");
   
   //----
   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);
   
   IndicatorDigits(Digits);
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   
   double
      haOpen,
      haHigh,
      haLow,
      haClose;

   int
      pos = Bars - ExtCountedBars - 1;

   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--;
   }

   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