MACD HISTO_001
Download scriptThis tool is designed to provide a visual representation of market momentum by analyzing the relationship between different price averages. It simplifies complex price movements into a clear, color-coded histogram that helps traders identify the strength and direction of a trend at a glance.
How the Logic Works
The script operates through a three-step calculation process to determine the final visual output:
1. Calculating the Trend Gap The tool first looks at two different types of moving averages: a "fast" average (which reacts quickly to recent price changes) and a "slow" average (which tracks the broader, longer-term trend). By subtracting the slow average from the fast average, the script identifies the gap between short-term momentum and long-term direction.
2. Identifying the Signal Line To smooth out the data and filter out "market noise," the script then performs a secondary calculation. It takes the results from the first step and applies another moving average to them. This creates a "signal" line, which serves as a baseline to help distinguish between minor price fluctuations and significant trend shifts.
3. Generating the Visual Histogram The final visual output is determined by comparing the initial Trend Gap against the Signal Line. The script calculates the difference between these two values:
- Positive Momentum: If the Trend Gap is higher than the Signal Line, the value is plotted as a positive figure (visualized in green). This typically suggests bullish strength.
- Negative Momentum: If the Trend Gap falls below the Signal Line, the value is plotted as a negative figure (visualized in red). This typically suggests bearish pressure.
Summary for the User
Instead of just looking at raw price candles, this indicator allows you to see "momentum." By using different colors and heights on the histogram, it highlights whether the current market move is gaining strength or losing steam, helping you stay aligned with the dominant trend.
//+------------------------------------------------------------------+
//| MACD HISTO.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_width1 3
#property indicator_width2 3
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double ind_Buffer1[];
double ind_Buffer2[];
double ind_buffer3a[];
double ind_buffer3b[];
double ind_buffer4[];
double ind_buffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(6);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexDrawBegin(0,SignalSMA);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexDrawBegin(1,SignalSMA);
/*SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,ind_Buffer1);
SetIndexStyle(5,DRAW_LINE);
SetIndexBuffer(5,ind_Buffer2);*/
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 5 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer3a) &&
!SetIndexBuffer(1,ind_buffer3b) &&
!SetIndexBuffer(2,ind_buffer4) &&
!SetIndexBuffer(3,ind_buffer5) &&
!SetIndexBuffer(4,ind_Buffer1) &&
!SetIndexBuffer(5,ind_Buffer2))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD HISTOGRAM");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ind_buffer4[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)
-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd additional buffer
for(i=0; i<limit; i++)
ind_buffer5[i]=iMAOnArray(ind_buffer4,Bars,SignalSMA,0,MODE_EMA,i);
//---- main loop
double value=0;
for(i=0; i<limit; i++)
{
ind_buffer3a[i]=0.0;
ind_buffer3b[i]=0.0;
value=ind_buffer4[i]-ind_buffer5[i];
if (value>0) ind_buffer3a[i]=value;
if (value<0) ind_buffer3b[i]=value;
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments