HeikenAshiZoneTrade

Download script
Author: Duke3D (Modify by Walter Choy)
HeikenAshiZoneTrade

The Heiken Ashi ZoneTrade script is a specialized visual tool designed for MetaTrader 4 that simplifies the interpretation of market trends by blending two distinct analytical methods. Rather than relying on raw price action, which can be "noisy" and erratic, this script filters the data to provide a clearer picture of market momentum and direction.

Core Logic Overview

The tool functions by synthesizing three main components: Heiken Ashi dynamics (a smoothing technique for price bars), Awesome Oscillator (AO) trends, and Average Channels (AC) movements. The goal is to identify the dominant "zone" of the market—whether it is trending strongly in one direction or experiencing a period of indecision.

How the Analysis Works

The script evaluates every price bar on your chart by checking three specific conditions:

  1. Trend Momentum (AO & AC): It compares the current values of the Awesome Oscillator and Average Channels against their previous values to determine if they are rising or falling.
  2. Price Smoothing: It calculates a synthetic "Open" and "Close" price for each bar using Heiken Ashi logic, which reduces market volatility and helps highlight the underlying trend.
  3. Visual Categorization: Based on whether these indicators are moving in harmony (both up, both down) or in opposition (one up, one down), the script assigns a color and "zone" to the candle:
  • Strong Bullish Trend: When both primary indicators align upward, the chart displays vibrant blue bars. This signifies strong buying pressure.
  • Strong Bearish Trend: When both primary indicators align downward, the chart displays red bars. This signifies strong selling pressure.
  • Neutral/Indecision Zone: When the indicators provide conflicting signals (one up while the other is down), the script paints the area in gray. This visually alerts the user to a period of market consolidation or high uncertainty where a clear trend has not yet established.

User Experience

For the trader, this creates a visual "heatmap" of the market:

  • Blue Zones: Suggest a favorable environment for long positions (buying).
  • Red Zones: Suggest a favorable environment for short positions (selling).
  • Gray Zones: Serve as a warning to stay on the sidelines or exercise caution, as the market is currently without a clear direction.

By converting complex mathematical calculations into simple color-coded zones, the script allows for faster decision-making and a more intuitive understanding of market psychology.

Indicators Used
Bill Williams Accelerator/Decelerator oscillatorBill Williams Awesome oscillator
Miscellaneous
Implements a curve of type %1
20 Views
0 Downloads
0 Favorites
HeikenAshiZoneTrade
//+------------------------------------------------------------------+
//|                                        Heiken Ashi ZoneTrade.mq4 |
//|                                                           Duke3D |
//|                                             duke3datomic@mail.ru |
//|                                            Modify by Walter Choy |
//+------------------------------------------------------------------+
#property copyright "Duke3D (Modify by Walter Choy)"
#property link      "duke3datomic@mail.ru"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 RoyalBlue
#property indicator_color2 Red
#property indicator_color3 Gray
#property indicator_color4 Gray
#property indicator_color5 RoyalBlue
#property indicator_color6 Red
#property indicator_color7 Gray
#property indicator_color8 Gray

#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 1
#property indicator_width8 1

extern color BlueZone         = RoyalBlue;          // ???? ???????? ????
extern color RedZone          = Red;            // ???? ??????? ????
extern color GreyZone         = Gray;           // ???? ????? ????

double AC_0;
double AC_1;
double AO_0;
double AO_1;

string name;

extern int BodyWidth          = 3;              // ?????? ???? ?????
extern int ShadowWidth        = 1;              // ?????? ???? ?????

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
//----

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, BodyWidth, BlueZone);
   SetIndexBuffer(0, ExtMapBuffer1);

   SetIndexStyle(1,DRAW_HISTOGRAM, 0, BodyWidth, RedZone);
   SetIndexBuffer(1, ExtMapBuffer2);
   
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, BodyWidth, GreyZone);
   SetIndexBuffer(2, ExtMapBuffer3);

   SetIndexStyle(3,DRAW_HISTOGRAM, 0, BodyWidth, GreyZone);
   SetIndexBuffer(3, ExtMapBuffer4);

   SetIndexStyle(4,DRAW_HISTOGRAM, 0, ShadowWidth, BlueZone);
   SetIndexBuffer(4, ExtMapBuffer5);
   
   SetIndexStyle(5,DRAW_HISTOGRAM, 0, ShadowWidth, RedZone);
   SetIndexBuffer(5, ExtMapBuffer6);

   SetIndexStyle(6,DRAW_HISTOGRAM, 0, ShadowWidth, GreyZone);
   SetIndexBuffer(6, ExtMapBuffer7);
   
   SetIndexStyle(7,DRAW_HISTOGRAM, 0, ShadowWidth, GreyZone);
   SetIndexBuffer(7, ExtMapBuffer8);

   SetIndexEmptyValue(0, 0.0);
   SetIndexEmptyValue(1, 0.0);
   SetIndexEmptyValue(2, 0.0);
   SetIndexEmptyValue(3, 0.0);
   SetIndexEmptyValue(4, 0.0);
   SetIndexEmptyValue(5, 0.0);
   SetIndexEmptyValue(6, 0.0);
   SetIndexEmptyValue(7, 0.0);

   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   SetIndexDrawBegin(2,10);
   SetIndexDrawBegin(3,10);
   SetIndexDrawBegin(4,10);
   SetIndexDrawBegin(5,10);
   SetIndexDrawBegin(6,10);
   SetIndexDrawBegin(7,10);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int i, limit;
   double ZTOpen, ZTHigh, ZTLow, ZTClose;
 
   if(counted_bars > 0) counted_bars--;
   i = Bars - counted_bars - 1;
   
   while(i>=0)
      {
      ZTOpen=(ExtMapBuffer1[i+1]+ExtMapBuffer2[i+1]+ExtMapBuffer3[i+1]+ExtMapBuffer4[i+1])/2;
      ZTClose=(Open[i]+High[i]+Low[i]+Close[i])/4;
      ZTHigh=MathMax(High[i], MathMax(ZTOpen, ZTClose));
      ZTLow=MathMin(Low[i], MathMin(ZTOpen, ZTClose));
//===================================================================================================================      
      if(IndAC(i)==1 && IndAO(i)==1)            // ??????? ???? 
        {
        if(ZTOpen>ZTClose)                    // bear
          {
           ExtMapBuffer1[i] = ZTOpen;
           ExtMapBuffer2[i] = ZTClose;
          }
        if(ZTOpen<ZTClose)                    // bull
          {
           ExtMapBuffer1[i] = ZTClose;
           ExtMapBuffer2[i] = ZTOpen;
          }
          
        ExtMapBuffer5[i] = ZTHigh;
        ExtMapBuffer6[i] = ZTLow;
        
        ExtMapBuffer3[i] = 0.0;
        ExtMapBuffer4[i] = 0.0;
        ExtMapBuffer7[i] = 0.0;
        ExtMapBuffer8[i] = 0.0;
        } 
//===================================================================================================================  
      if(IndAC(i)==2 && IndAO(i)==2)            // ??????? ???? 
        {
        if(ZTOpen>ZTClose)                    // bear
          {
           ExtMapBuffer1[i] = ZTClose;
           ExtMapBuffer2[i] = ZTOpen;
          }
        if(ZTOpen<ZTClose)                    // bull
          {
           ExtMapBuffer1[i] = ZTOpen;
           ExtMapBuffer2[i] = ZTClose;
          }
        ExtMapBuffer5[i] = ZTLow;
        ExtMapBuffer6[i] = ZTHigh;
        
        ExtMapBuffer3[i] = 0.0;
        ExtMapBuffer4[i] = 0.0;
        ExtMapBuffer7[i] = 0.0;
        ExtMapBuffer8[i] = 0.0;
        } 
//===================================================================================================================
      if(IndAC(i)==1 && IndAO(i)==2)            // ????? ????
        {
        if(ZTOpen>ZTClose)                    // bear
          {
           ExtMapBuffer3[i] = ZTOpen;
           ExtMapBuffer4[i] = ZTClose;
          }
        if(ZTOpen<ZTClose)                    // bull
          {
           ExtMapBuffer3[i] = ZTClose;
           ExtMapBuffer4[i] = ZTOpen;
          }
        ExtMapBuffer7[i] = ZTHigh;
        ExtMapBuffer8[i] = ZTLow;
        
        ExtMapBuffer1[i] = 0.0;
        ExtMapBuffer2[i] = 0.0;
        ExtMapBuffer5[i] = 0.0;
        ExtMapBuffer6[i] = 0.0;
        }
//===================================================================================================================
      if(IndAC(i)==2 && IndAO(i)==1)            // ????? ????
        {
        if(ZTOpen>ZTClose)                    // bear
          {
           ExtMapBuffer3[i] = ZTClose;
           ExtMapBuffer4[i] = ZTOpen;
          }
        if(ZTOpen<ZTClose)                    // bull
          {
           ExtMapBuffer3[i] = ZTOpen;
           ExtMapBuffer4[i] = ZTClose;
          }
        ExtMapBuffer7[i] = ZTLow;
        ExtMapBuffer8[i] = ZTHigh;

        ExtMapBuffer1[i] = 0.0;
        ExtMapBuffer2[i] = 0.0;
        ExtMapBuffer5[i] = 0.0;
        ExtMapBuffer6[i] = 0.0;
        }
      i--;
      }
//===================================================================================================================     
  return(0);
  }
//===================================================================================================================     
int IndAC(int Shift)
   {
   int DirectionAC = 1;
   AC_0 = iAC(Symbol(),0,Shift);
   AC_1 = iAC(Symbol(),0,Shift+1);
   if(AC_0>AC_1) {DirectionAC = 1;}               // ??????? ???
   if(AC_0<AC_1) {DirectionAC = 2;}               // ??????? ???
   return(DirectionAC);
   }
//===================================================================================================================     
int IndAO(int Shift)
   {
   int DirectionAO = 1;
   AO_0 = iAO(Symbol(),0,Shift);
   AO_1 = iAO(Symbol(),0,Shift+1);
   if(AO_0>AO_1) {DirectionAO = 1;}               // ??????? ???
   if(AO_0<AO_1) {DirectionAO = 2;}               // ??????? ???
   return(DirectionAO);
   }
//===================================================================================================================

Comments