HeikenAshiHistogram
Download scriptThis tool is designed to provide a visual representation of market momentum and trend direction by combining two distinct analytical concepts: the Heiken Ashi price movement and a smoothed moving average calculation.
Core Logic Overview
Instead of showing raw price data, which can often be "noisy" or jumpy, this script filters the market activity to highlight the strength and direction of the current trend. It accomplishes this through three primary logical steps:
1. Identifying Trend Direction (Heiken Ashi Foundation) The script looks at "Heiken Ashi" price data—a specialized type of charting that smooths out price action to reveal trends more clearly. It specifically compares the opening and closing values of these candles:
- If the opening price is higher than the closing price, the logic identifies a bearish (downward) sentiment.
- If the opening price is lower than the closing price, the logic identifies a bullish (upward) sentiment.
2. Measuring Momentum Strength The script doesn't just care about direction; it also measures how much the market is moving. It calculates the "Median" value of each candle and then determines the absolute difference between the current median and the previous one. This difference represents the intensity or volatility of the price movement at that specific moment.
3. Visual Representation The final output is displayed as a histogram in a separate window below your main chart:
- Bullish Momentum: When the market shows upward strength, it highlights the intensity using one color (DodgerBlue).
- Bearish Momentum: When the market shows downward strength, it highlights the intensity using a different color (Red).
- Trend Smoothing: To ensure the visual data is clean and easy to read, the script applies a Moving Average calculation across these momentum values. This helps smooth out minor fluctuations, allowing you to see the broader flow of the market more clearly.
Summary for the User
In simple terms, this indicator acts as a "momentum thermometer." It tells you not just whether the price is going up or down, but how strongly it is moving in that direction. By smoothing out the daily noise, it helps traders visualize whether the current trend is gaining strength, losing steam, or shifting direction.
//+------------------------------------------------------------------+
//| HeikenAshiHistogram.mq4
//| Copyright http://www.pointzero-indicator.com
//+------------------------------------------------------------------+
#property copyright "Copyright © Pointzero-indicator.com"
#property link "http://www.pointzero-indicator.com"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Teal
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#define MaMetod 2
//-------------------------------
// External variables
//-------------------------------
extern int AvPeriod = 6;
//-------------------------------
// Buffers
//-------------------------------
double FextMapBuffer1[];
double FextMapBuffer2[];
double FextMapBuffer3[];
double FextMapBuffer4[];
double FextMapBuffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
// Total buffers
IndicatorBuffers(5);
// Visible buffers
SetIndexStyle(0,DRAW_HISTOGRAM, 0);
SetIndexBuffer(0, FextMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM, 0);
SetIndexBuffer(1, FextMapBuffer2);
SetIndexStyle(3,DRAW_LINE, 0);
SetIndexBuffer(2,FextMapBuffer3);
// Internal
SetIndexBuffer(3,FextMapBuffer4);
SetIndexBuffer(4,FextMapBuffer5);
// My name
IndicatorShortName("Heiken Ashi Histogram");
Comment("Copyright © http://www.pointzero-indicator.com");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
// Start, limit, etc..
int start = 0;
int limit;
int counted_bars = IndicatorCounted();
if(Bars<=10) return(0);
// nothing else to do?
if(counted_bars < 0)
return(-1);
// do not check repeated bars
limit = Bars - 1 - counted_bars;
// 1) Check heiken ashi for past to present
for(int pos = limit; pos >= start; pos--)
{
// Open and close
double open = iCustom(Symbol(), 0, "Heiken Ashi", 2, pos);
double close = iCustom(Symbol(), 0, "Heiken Ashi", 3, pos);
// Median
FextMapBuffer4[pos] = (open + close) / 2;
// Difference
FextMapBuffer5[pos] = MathAbs(FextMapBuffer4[pos] - FextMapBuffer4[pos+1]);
// If bearish
if(open > close)
{
FextMapBuffer2[pos] = FextMapBuffer5[pos];
FextMapBuffer1[pos] = 0;
// If bullish
} else {
FextMapBuffer1[pos] = FextMapBuffer5[pos];
FextMapBuffer2[pos] = 0;
}
}
// Apply average
for(int i=0; i < Bars; i++) FextMapBuffer3[i] = iMAOnArray(FextMapBuffer5, Bars, AvPeriod, 0, MaMetod, i);
return(0);
}
Comments