Heiken_Ashi4

Author: Copyright � 2004, MetaQuotes Software Corp.
Heiken_Ashi4

This script is designed to generate a specialized type of price chart known as Heiken Ashi directly within your trading platform. Unlike standard candlestick charts, which can sometimes appear "noisy" due to rapid price fluctuations, this tool smooths out the visual data to provide a clearer picture of the underlying market trend.

How the Logic Works

The script works by recalculating the traditional price data (Open, High, Low, and Close) into a new set of "synthetic" values. Instead of showing you raw prices, it follows these logical steps:

  • Smoothing the Opening Price: The starting point for each new bar is calculated by taking the average of the previous bar's opening and closing prices. This helps link the current price action to the previous period's momentum.
  • Calculating the Average Close: The closing price for the current bar is determined by finding the mean value of four components: the current High, Low, Open, and Close. This creates a balanced representation of the price movement during that time frame.
  • Defining Highs and Lows: To ensure the bars remain visually accurate, the script compares the actual market highs and lows against the newly calculated opening and closing points. It selects the highest and lowest values among them to define the boundaries of each bar.
  • Dynamic Color Logic: The script automatically distinguishes between "Bullish" (upward) and "Bearish" (downward) movements. If the calculated closing price is higher than the opening price, it identifies a positive move; if it is lower, it identifies a negative move.

Visual Experience

The final result is a series of smoothed bars that allow you to see whether the market is trending in a specific direction more easily. By removing some of the "jitter" found in standard charts, it helps traders identify the strength and direction of a trend without being distracted by minor price spikes.

Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
Heiken_Ashi4
//+==================================================================+
//|                                                 Heiken AshiR.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_chart_window 
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôôåðîâ
#property indicator_buffers 4 
//---- öâåòà èíäèêàòîðà 
#property indicator_color1 Red  
#property indicator_color2 LimeGreen 
#property indicator_color3 Red
#property indicator_color4 LimeGreen
//---- òîëùèíà èíäèêàòîðíûõ ëèíèé
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3 
#property indicator_width4 3
//---- èíäèêàòîðíûå áóôôåðû
double L_Buffer[];
double H_Buffer[];
double O_Buffer[];
double C_Buffer[];
//---- ïåðåìåííûå ñ ïëàâàþùåé òî÷êîé  
double haOpen, haHigh, haLow, haClose;
//+==================================================================+
//| Heiken AshiR initialization function                             |
//+==================================================================+
int init()
  {
//---- ñòèëü èçîáðàæåíèÿ èíäèêàòîðà
   SetIndexStyle(0,DRAW_HISTOGRAM,0);
   SetIndexStyle(1,DRAW_HISTOGRAM,0);
   SetIndexStyle(2,DRAW_HISTOGRAM,0);
   SetIndexStyle(3,DRAW_HISTOGRAM,0);
//---- óñòàíîâêà íîìåðà áàðà, 
              //íà÷èíàÿ ñ êîòîðîãî áóäåò îòðèñîâûâàòüñÿ èíäèêàòîð  
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   SetIndexDrawBegin(2,10);
   SetIndexDrawBegin(3,10);
//---- 4 èíäèêàòîðíûõ áóôôåðà èñïîëüçîâàíû äëÿ ñ÷¸òà
   SetIndexBuffer(0,L_Buffer);
   SetIndexBuffer(1,H_Buffer);
   SetIndexBuffer(2,O_Buffer);
   SetIndexBuffer(3,C_Buffer);
//---- çàâåðøåíèå èíèöèàëèçàöèè
   return(0);
  }
//+==================================================================+
//| Heiken AshiiR teration function                                  |
//+==================================================================+
int start()
  {
if (Bars<=10) return(0);
//----+ Ââåäåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîäñ÷èòàííûõ áàðîâ
int bar,counted_bars=IndicatorCounted(); 
//---- ïðîâåðêà íà âîçìîæíûå îøèáêè
if (counted_bars<0)return(-1);
//---- ïîñëåäíèé ïîäñ÷èòàííûé áàð äîëæåí áûòü ïåðåñ÷èòàí 
if (counted_bars>0) counted_bars--;
//---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà, 
            //íà÷èíàÿ ñ êîòîðîãî áóäåò ïðîèçåä¸í ïåðåñ÷¸ò íîâûõ áàðîâ
bar=Bars-counted_bars-1;
if (bar>Bars-2)bar=Bars-2;
//----
while(bar>=0)
     {
      haOpen=(O_Buffer[bar+1]+C_Buffer[bar+1])/2;
      haClose=(Open[bar]+High[bar]+Low[bar]+Close[bar])/4;
      haHigh=MathMax(High[bar], MathMax(haOpen, haClose));
      haLow=MathMin(Low[bar], MathMin(haOpen, haClose));
      if (haOpen<haClose) 
        {
         L_Buffer[bar]=haLow;
         H_Buffer[bar]=haHigh;
        } 
      else
        {
         L_Buffer[bar]=haHigh;
         H_Buffer[bar]=haLow;
        } 
      O_Buffer[bar]=haOpen;
      C_Buffer[bar]=haClose;
 	   bar--;
     }
//----
   return(0);
  }
//+-----------------------------------------------------------------+

Comments