Author: Copyright � 2004, MetaQuotes Software Corp.
Price_v2

This script is designed to transform the standard visual representation of financial price charts into a specialized analytical format known as Heiken Ashi. Unlike standard Japanese candlesticks, which represent raw price action (the exact high, low, open, and close of a specific period), Heiken Ashi candles are calculated using an average of previous price movements. The goal of this logic is to "smooth out" the market noise, making it easier for traders to identify the underlying trend and direction of the market.

How the Logic Works

The script processes each bar on your chart by rearranging and recalculating the price data based on four primary components:

1. Trend Smoothing (Open and Close) Instead of showing the immediate volatility of a single minute or hour, the script looks at the relationship between the opening and closing prices. By comparing these values, it determines whether the current momentum is bullish (upward) or bearish (downward).

2. Dynamic Range Mapping (Highs and Lows) The core logic identifies the boundaries of each price movement:

  • In an Upward Trend: The script prioritizes the lower boundary of the price action to create a cleaner visual flow.
  • In a Downward Trend: The script shifts its focus to the upper boundary.

By constantly switching which high or low point is prioritized based on whether the price closed higher or lower than it opened, the script prevents "wicks" or "shadows" from creating false signals of volatility.

3. Visual Output The result is a series of histograms that provide a clearer narrative of the market:

  • When the trend is consistent, the bars appear uniform, signaling strong momentum.
  • When the trend begins to weaken or flip, the visual shift in the high/low boundaries becomes more apparent before it might be visible on a standard chart.

Summary for Traders

The primary purpose of this script is visual clarity. By filtering out the "jitter" of every minor price fluctuation and focusing on the mean price movement, it allows you to see the "big picture." It is specifically designed to help you stay in a trend longer and identify potential reversals with less distraction from insignificant price spikes.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Price_v2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                  Heiken Ashi.mq4 |
//|                      Copyright © 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 RoyalBlue
#property indicator_color3 Red
#property indicator_color4 RoyalBlue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3);
   SetIndexBuffer(3, ExtMapBuffer4);
//----
   SetIndexDrawBegin(0,5);
//---- 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=Open[pos];
      haClose=Close[pos];
      haHigh=High[pos];
      haLow=Low[pos];
      if (haOpen<haClose) 
        {
         ExtMapBuffer1[pos]=haLow;
         ExtMapBuffer2[pos]=haHigh;
        } 
      else
        {
         ExtMapBuffer1[pos]=haHigh;
         ExtMapBuffer2[pos]=haLow;
        } 
      ExtMapBuffer3[pos]=haOpen;
      ExtMapBuffer4[pos]=haClose;
 	   pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments