Heiken_Ashi_Smoothed_002
Download scriptOverview of the Heiken Ashi Smoothed Indicator
This script is designed to provide a refined and stabilized visual representation of price action on your trading charts. By combining two popular technical analysis concepts—Heiken Ashi candles and Moving Averages—the indicator aims to filter out market "noise" (minor, erratic price fluctuations) to help traders identify clearer trends more easily.
How the Logic Works
The script processes data through a multi-stage calculation to arrive at the final visual output:
1. Initial Data Smoothing
Instead of looking at raw price points (which can be very jagged), the indicator first calculates moving averages for the four primary price components: Open, High, Low, and Close. This creates a smoother foundation of price movement based on user-defined periods and smoothing methods.
2. Heiken Ashi Transformation
The logic then converts these smoothed values into "Heiken Ashi" components. Heiken Ashi is a type of candlestick chart that focuses on the average price of a period rather than the raw price. The script calculates:
- Opening Price: Based on the average of the previous candle's data.
- Closing Price: Calculated as the average of the High, Low, Open, and Close values from the smoothed moving averages.
- High/Low Bounds: Determined by comparing the smoothed highs and lows against the new Heiken Ashi calculations to ensure the "wick" of the candle accurately reflects the price range.
3. Secondary Smoothing Layer
After transforming the data into Heiken Ashi format, the script applies a second layer of moving averages across the results. This is the "Smoothed" part of the indicator. It takes the newly calculated Heiken Ashi values and runs them through another mathematical filter to dampen any remaining volatility.
Visual Representation on the Chart
The final output is displayed as a histogram on your chart:
- Color Coding: The indicator uses distinct colors (Red and Royal Blue) to help differentiate between price movements.
- Trend Identification: By smoothing both the raw price data and the resulting Heiken Ashi candles, the script helps highlight the prevailing direction of the market. It makes it easier for a trader to see if the momentum is steadily moving upward or downward without being distracted by the small, rapid "zigs" and "zags" of live trading.
Summary for Traders
Essentially, this script acts as a "filter." It takes raw market data, rounds off the sharp edges using moving averages, converts it into a trend-focused Heiken Ashi format, and then smooths it once more. The goal is to provide a visual aid that highlights the underlying trend of the market with minimal distraction from temporary price spikes.
//+------------------------------------------------------------------+
//| Heiken Ashi Smoothed.mq4 |
//+------------------------------------------------------------------+
//| mod by Raff |
//+------------------------------------------------------------------+
#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 RoyalBlue
#property indicator_color3 Red
#property indicator_color4 RoyalBlue
//---- parameters
extern int MaMetod = 2;
extern int MaPeriod = 6;
extern int MaMetod2 = 3;
extern int MaPeriod2 = 2;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, Red);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, RoyalBlue);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, Red);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, RoyalBlue);
SetIndexBuffer(3, ExtMapBuffer4);
//----
SetIndexDrawBegin(0,5);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexBuffer(6,ExtMapBuffer7);
SetIndexBuffer(7,ExtMapBuffer8);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double maOpen, maClose, maLow, maHigh;
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;
int pos2=pos;
while(pos>=0)
{
maOpen=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_OPEN,pos);
maClose=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_CLOSE,pos);
maLow=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_LOW,pos);
maHigh=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_HIGH,pos);
haOpen=(ExtMapBuffer5[pos+1]+ExtMapBuffer6[pos+1])/2;
haClose=(maOpen+maHigh+maLow+maClose)/4;
haHigh=MathMax(maHigh, MathMax(haOpen, haClose));
haLow=MathMin(maLow, MathMin(haOpen, haClose));
if (haOpen<haClose)
{
ExtMapBuffer7[pos]=haLow;
ExtMapBuffer8[pos]=haHigh;
}
else
{
ExtMapBuffer7[pos]=haHigh;
ExtMapBuffer8[pos]=haLow;
}
ExtMapBuffer5[pos]=haOpen;
ExtMapBuffer6[pos]=haClose;
pos--;
}
int i;
for(i=0; i<pos2; i++) ExtMapBuffer1[i]=iMAOnArray(ExtMapBuffer7,Bars,MaPeriod2,0,MaMetod2,i);
for(i=0; i<pos2; i++) ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer8,Bars,MaPeriod2,0,MaMetod2,i);
for(i=0; i<pos2; i++) ExtMapBuffer3[i]=iMAOnArray(ExtMapBuffer5,Bars,MaPeriod2,0,MaMetod2,i);
for(i=0; i<pos2; i++) ExtMapBuffer4[i]=iMAOnArray(ExtMapBuffer6,Bars,MaPeriod2,0,MaMetod2,i);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments