HPT - Heiken Ashi Smoothed Bar

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
HPT - Heiken Ashi Smoothed Bar

This technical script is designed to function as a visual signaling tool for traders, specifically aimed at simplifying the interpretation of market trends. By utilizing a specialized smoothing technique known as "Heiken Ashi," the indicator filters out minor market noise to provide clearer signals on price momentum.

Core Functionality

The script analyzes historical price data and translates complex movements into three distinct types of visual markers (arrows). Instead of overwhelming the user with constant data, it categorizes the current market state into one of three categories:

  • Bearish Momentum: When the script detects a sustained downward trend where both the current and previous smoothed price points indicate a decline, it triggers a downward signal.
  • Bullish Momentum: Conversely, when the script identifies a consistent upward trend across consecutive smoothed data points, it generates an upward signal.
  • Neutral/Indecision (Doji): If the market is neither showing a clear upward nor downward trend—often signifying a period of consolidation or uncertainty—the script marks this as a neutral state.

How It Works Behind the Scenes

The logic relies on a secondary "Smoothed Heiken Ashi" calculation. Rather than looking at raw, jagged price ticks, it retrieves pre-processed values that represent a more stable average of the market's direction.

The script then performs a sequential check:

  1. It looks at the current smoothed opening and closing prices.
  2. It compares them against the previous period's smoothed values.
  3. Based on whether these values are increasing or decreasing in a consistent manner, it places a marker at the top of the indicator window to alert the trader to the prevailing sentiment.

Visual Presentation

To ensure clarity for the user, the script is designed to appear in a separate window from the main price chart. This prevents the visual markers from cluttering the price action while providing a dedicated space for trend identification. The indicators are standardized at a specific level (50) on the scale, ensuring they appear as clean, consistent icons that represent the strength and direction of the market move.

Miscellaneous
Implements a curve of type %1
3 Views
0 Downloads
0 Favorites
HPT - Heiken Ashi Smoothed Bar
//+------------------------------------------------------------------+
//|                                                  Heiken Ashi.mq4 |
//|                      Copyright c 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_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_color3 Yellow
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_minimum 0.0
#property indicator_maximum 50.5

//---- parameters
extern int MaMetod =2;
extern int MaPeriod=6;
extern int MaMetod2 =3;
extern int MaPeriod2=2;
//---- buffers
double haDOJI[];
double haDN[];
double haUP[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0, haDN);
   SetIndexArrow(0, 167);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1, haUP);
   SetIndexArrow(1, 167);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2, haDOJI);
   SetIndexArrow(2, 167);
//---- indicator buffers mapping
   SetIndexBuffer(0,haDN);
   SetIndexBuffer(1,haUP);
   SetIndexBuffer(2,haDOJI);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom 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)
     {
      double haOpen   = iCustom(NULL,0,"HPT - Heiken Ashi Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,pos) ;
      double haClose  = iCustom(NULL,0,"HPT - Heiken Ashi Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,pos) ;
      double haOpen1  = iCustom(NULL,0,"HPT - Heiken Ashi Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,0,pos) ;
      double haClose1 = iCustom(NULL,0,"HPT - Heiken Ashi Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,1,pos) ;
      haUP[pos]=EMPTY_VALUE;
      haDN[pos]=EMPTY_VALUE;
      haDOJI[pos]=EMPTY_VALUE;

      if (haOpen>haClose&&haOpen1>haClose1) 
      {
         haDN[pos]=50;
      }
      else if (haOpen<haClose&&haOpen1<haClose1)
      {
         haUP[pos]=50;
      }
      else
      {
         haDOJI[pos]=50;
      }
      
 	   pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments