TP_HeikenAshi
Download scriptThis indicator is designed to provide traders with a smoothed, visual representation of market price action by utilizing a specialized variation of the Heiken Ashi charting method. Rather than displaying standard candlestick data, which can often be "noisy" due to minor price fluctuations, this script calculates custom values to help identify the underlying trend more clearly.
Core Logic and Calculation
The primary objective of the script is to create a more stable trend visualization. It achieves this through several distinct layers of logic:
- Custom Average Price Calculation: Instead of relying on standard opening or closing prices, the script calculates a modified "Open" value. It does this by taking an average of price data across multiple previous time periods. By blending these historical averages, the indicator filters out immediate market volatility to show a more consistent flow of price movement.
- Dynamic Price Mapping: For every bar on the chart, the script determines the "High" and "Low" points based on the relationship between the calculated open and close prices. If the current price action is moving upward (where the closing value is higher than the opening value), the indicator maps the data to reflect a bullish sentiment; if it is moving downward, it maps the data to show a bearish sentiment.
- Dual-Layer Visual Representation: The script produces four distinct data streams that are rendered as histograms on your chart:
- Primary Trend Indicators: These use thin lines to provide a foundational view of the price range.
- Secondary Trend Indicators: These use thicker lines to emphasize the current price levels (specifically the open and close points) derived from the smoothing formula.
Visual Outcome for the Trader
The result is a visual tool that highlights the momentum of the market. By using these calculated averages instead of raw price data, the indicator helps traders distinguish between temporary price "spikes" and sustained trend changes. The use of red and white colors, combined with varying line thicknesses, allows you to quickly identify whether the current market sentiment is leaning towards a move up or down, providing a clearer picture of the prevailing direction.
//+------------------------------------------------------------------+
//| TP_HeikenAshi.mq4 |
//| Ron Mauldin |
//| http://fx41.com |
//+------------------------------------------------------------------+
#property copyright "Ron Mauldin"
#property link "http://fx41.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 White
#property indicator_color3 Red
#property indicator_color4 White
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
//----
color color1 = Red;
color color2 = White;
color color3 = Red;
color color4 = White;
//---- buffers
double haDN1[];
double haUP1[];
double haDN2[];
double haUP2[];
int init(){
SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, color1);
SetIndexBuffer(0, haDN1);//Red
SetIndexDrawBegin(0,10);
SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, color2);
SetIndexBuffer(1, haUP1);//White
SetIndexDrawBegin(1,10);
SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, color3);
SetIndexBuffer(2, haDN2);//Red
SetIndexDrawBegin(2,10);
SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, color4);
SetIndexBuffer(3, haUP2);//White
SetIndexDrawBegin(3,10);
return(0);
}
int deinit(){return(0);}
int start(){
double haOpen, haHigh, haLow, haClose;
int counted_bars = IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
int limit = (Bars - 1 - counted_bars);
for(int bar = limit; bar >= 0; bar--){
//haOpen=(haDN2[bar+1]+haUP2[bar+1])/2; This standard HA was replaced by a 4 period HA
haOpen=((((((Open[bar+3]+High[bar+3]+Low[bar+3]+Close[bar+3])/4)+((Open[bar+2]+High[bar+2]+Low[bar+2]+Close[bar+2])/4))/2)+((Open[bar+1]+High[bar+1]+Low[bar+1]+Close[bar+1])/4))/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){
haDN1[bar]=haLow;
haUP1[bar]=haHigh;
}else{
haDN1[bar]=haHigh;
haUP1[bar]=haLow;
}
haDN2[bar]=haOpen;
haUP2[bar]=haClose;
}
return(0);
}
Comments