Heiken Ashi_SW

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

This script is designed to provide a visual representation of market trends by calculating and displaying Heikin Ashi data in a dedicated, separate window within the MetaTrader platform. Unlike standard price charts that show raw fluctuations, this tool smooths out market "noise" to help traders identify the underlying direction of price movement more clearly.

Core Logic and Functionality

The script operates by transforming standard price data into four distinct components: Open, High, Low, and Close. Instead of plotting these figures directly from the market, it uses a specific mathematical smoothing logic:

  • Price Smoothing: The script calculates a "synthetic" average for every candle. It determines the opening price by averaging the previous period's data and sets the closing price based on the average of the current period's high, low, open, and close prices.
  • Trend Detection: By comparing these smoothed values against one another, the script identifies whether the current momentum is bullish (upward) or bearish (downward).
  • Visual Representation: The logic translates this momentum into a histogram format:
    • When the calculated "close" is higher than the "open," it signifies upward momentum.
    • When the calculated "close" is lower than the "open," it signifies downward momentum.
  • Data Mapping: The script maintains an internal memory of these smoothed values, ensuring that as new price data arrives, the history remains consistent and fluid for the user to observe.

User Experience Highlights

  • Dedicated Window: Rather than overlaying information directly onto your main price candles (which can sometimes clutter the view), this script is configured to appear in its own independent window at the bottom of your chart.
  • Simplified Analysis: By converting complex price action into a smoothed histogram, the logic aims to make it easier for a trader to see where a trend is strengthening or beginning to exhaust itself.
  • Automated Calculations: The script handles all the heavy lifting of the Heikin Ashi formulas in real-time, updating automatically as the market moves, so you can focus on making trading decisions rather than manual calculations.
Miscellaneous
Implements a curve of type %1
18 Views
0 Downloads
0 Favorites
Heiken Ashi_SW
//+------------------------------------------------------------------+
//|                                               Heiken Ashi_SW.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//|               Modififed by Igorad for display in separate window |
//|                                       "http://www.forex-tsd.com/"|
//+------------------------------------------------------------------+
//| 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_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 3
#property indicator_color2 White
#property indicator_width2 3
#property indicator_maximum 1.05
#property indicator_minimum -0.05
//#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
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   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]=0;
         ExtMapBuffer2[pos]=1;
        } 
      else
        {
         ExtMapBuffer1[pos]=1;
         ExtMapBuffer2[pos]=0;
        } 
      ExtMapBuffer3[pos]=haOpen;
      ExtMapBuffer4[pos]=haClose;
 	   pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments