Heiken_Ashi_ZMa

Download script
Author: Copyright � 2006, Forex-TSD.com
Heiken_Ashi_ZMa

This script is designed to provide traders with a specialized visual overlay for the MetaTrader platform. It combines two popular market analysis concepts—Heiken Ashi candles and Zero Lag Moving Averages—to create a smoother, more readable representation of price action.

Core Functionality

The primary purpose of this tool is to filter out "market noise" (small, erratic price fluctuations) and highlight the underlying trend. It achieves this through a multi-step calculation process:

1. Data Sourcing (Zero Lag Moving Averages) Instead of using standard moving averages, which can often lag behind current price action, the script pulls data from a "Zero Lag" moving average. It retrieves four specific pieces of information for each point in time:

  • The Opening Price
  • The Closing Price
  • The High Price
  • The Low Price

2. Heiken Ashi Transformation The script takes that raw moving average data and applies "Heiken Ashi" logic. In standard charting, candles represent the raw price; in Heikin Ashi, candles are recalculated to show an average of previous price movements. This results in a smoother visual flow where:

  • Opening Prices are calculated as the average of the previous candle's open and close.
  • Closing Prices are calculated as the average of the current high, low, open, and close.

3. Dynamic Visual Mapping The script then uses these calculations to plot a histogram on your chart. It determines the direction of the trend by comparing the recalculated opening and closing values:

  • If the closing value is higher than the opening, it interprets the sentiment as bullish (upward) and colors the visual output accordingly.
  • If the closing value is lower than the opening, it interprets the sentiment as bearish (downward).

Summary for the Trader

By combining these two methods, the script creates a "smoothed" price trend. Rather than seeing the jagged peaks and valleys of every tiny trade, you see a flowing histogram that clarifies the current momentum. It helps in identifying whether the market is trending upward or downward by providing a clearer, more stable visual representation of price behavior.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
Heiken_Ashi_ZMa
//+------------------------------------------------------------------+
//|                        Heiken Ashi ZMa.mq4                       |
//+------------------------------------------------------------------+
//____________________________\¦/
//___________________________(ò ó)
//______________________o0o___(_)___o0o__
//___¦_____¦_____¦_____¦_____¦_____¦_____¦
//¦_____¦_____¦_____¦_____¦_____¦_____¦__
//___¦_____¦_____¦_____¦_____¦_____¦_____¦
//¦_____¦_____¦_____¦_____¦_____¦_____¦__
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Green
extern int Lengthzma2 = 50;
extern int Lengthzma3 = 50;
extern int nZLMASmMethod= 1;
extern int nZLMAMethod= 1;
extern int nZLMAShift=0;
extern int nZLMASmShift=0;
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int ExtCountedBars=0;
int init()
  {
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, Red);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, Green);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 2, Red);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 2, Green);
   SetIndexBuffer(3, ExtMapBuffer4);
   SetIndexDrawBegin(0,5);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   return(0);
  }
int start()
  {
   double maOpen, maClose, maLow, maHigh;
   double haOpen, haHigh, haLow, haClose;
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
   if (ExtCountedBars<0) return(-1);
   if (ExtCountedBars>0) ExtCountedBars--;
   int i=Bars-ExtCountedBars-1;
   while(i>=0)
     {
      maOpen=iCustom(Symbol(),0,"ZeroLAG MA",Lengthzma2,0,nZLMAMethod,1,Lengthzma3,0,nZLMASmMethod,0,i);
      maClose=iCustom(Symbol(),0,"ZeroLAG MA",Lengthzma2,0,nZLMAMethod,0,Lengthzma3,0,nZLMASmMethod,0,i);
      maLow=iCustom(Symbol(),0,"ZeroLAG MA",Lengthzma2,0,nZLMAMethod,3,Lengthzma3,0,nZLMASmMethod,0,i);
      maHigh=iCustom(Symbol(),0,"ZeroLAG MA",Lengthzma2,0,nZLMAMethod,2,Lengthzma3,0,nZLMASmMethod,0,i);

      haOpen=(ExtMapBuffer3[i+1]+ExtMapBuffer4[i+1])/2;
      haClose=(maOpen+maHigh+maLow+maClose)/4;
      haHigh=MathMax(maHigh, MathMax(haOpen, haClose));
      haLow=MathMin(maLow, MathMin(haOpen, haClose));
      if (haOpen<haClose) 
        {
         ExtMapBuffer1[i]=haLow;
         ExtMapBuffer2[i]=haHigh;
        } 
      else
        {
         ExtMapBuffer1[i]=haHigh;
         ExtMapBuffer2[i]=haLow;
        } 
      ExtMapBuffer3[i]=haOpen;
      ExtMapBuffer4[i]=haClose;
 	   i--;
     }
   return(0);
  }

Comments