This indicator is designed to enhance the standard Moving Average Convergence Divergence (MACD) by introducing a "ZeroLag" calculation technique. The primary goal of this script is to provide traders with a smoother, more responsive momentum signal that minimizes the typical delays found in standard technical indicators.
Core Logic and Methodology
The script operates through a multi-layered calculation process to refine price data into actionable visual information:
1. Primary Data Processing (Fast and Slow Trends) The tool begins by identifying two different trend speeds using Exponential Moving Averages (EMAs). One represents a "Fast" trend (reacting quickly to recent price changes) and the other a "Slow" trend (tracking the broader, long-term direction).
2. The ZeroLag Transformation This is where the script distinguishes itself from standard MACD versions. Instead of using the raw averages directly, the script applies a mathematical transformation to both the Fast and Slow data. It calculates a specific average of the moving averages and then uses it to "offset" the current price values. This calculation effectively predicts the momentum more accurately by subtracting the smoothed lag from the current value, resulting in a faster response to market turns without creating excessive noise.
3. MACD Calculation Once the ZeroLag versions of the Fast and Slow trends are established, the script calculates the difference between them. This result is displayed as a histogram on your chart. The histogram represents the strength and direction of the current momentum:
- When the fast trend significantly outweighs the slow trend, it indicates strong upward or downward movement.
- The gap between these two signals helps traders identify whether a trend is accelerating or losing steam.
4. Signal Line Smoothing To help traders identify specific entry or exit points, the script takes the resulting MACD histogram and runs it through one final smoothing process. This creates a "Signal Line." By comparing the main histogram to this signal line, users can more easily spot trend reversals—such as when the histogram crosses over the signal line—providing a clearer visual cue for potential trade opportunities.
Summary of Visual Output
- Histogram: Represents the primary ZeroLag momentum difference between the fast and slow trends.
- Signal Line: A secondary smoothed line used to identify turning points and confirm trend shifts.
//+------------------------------------------------------------------+
//| ZeroLag MACD.mq4 |
//| RD |
//| marynarz15@wp.pl |
//+------------------------------------------------------------------+
#property copyright "RD"
#property link "marynarz15@wp.pl"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Orange
//---- input parameters
extern int FastEMA=12;
extern int SlowEMA=24;
extern int SignalEMA=9;
//---- buffers
double MACDBuffer[];
double SignalBuffer[];
double FastEMABuffer[];
double SlowEMABuffer[];
double SignalEMABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(5);
SetIndexBuffer(0,MACDBuffer);
SetIndexBuffer(1,SignalBuffer);
SetIndexBuffer(2,FastEMABuffer);
SetIndexBuffer(3,SlowEMABuffer);
SetIndexBuffer(4,SignalEMABuffer);
SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,2);
SetIndexStyle(1,DRAW_LINE,EMPTY,2);
SetIndexDrawBegin(0,SlowEMA);
SetIndexDrawBegin(1,SlowEMA);
IndicatorShortName("ZeroLag MACD("+FastEMA+","+SlowEMA+","+SignalEMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
double EMA,ZeroLagEMAp,ZeroLagEMAq;
for(int i=0; i<limit; i++)
{
FastEMABuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i);
SlowEMABuffer[i]=iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
}
for(i=0; i<limit; i++)
{
EMA=iMAOnArray(FastEMABuffer,Bars,FastEMA,0,MODE_EMA,i);
ZeroLagEMAp=FastEMABuffer[i]+FastEMABuffer[i]-EMA;
EMA=iMAOnArray(SlowEMABuffer,Bars,SlowEMA,0,MODE_EMA,i);
ZeroLagEMAq=SlowEMABuffer[i]+SlowEMABuffer[i]-EMA;
MACDBuffer[i]=ZeroLagEMAp - ZeroLagEMAq;
}
for(i=0; i<limit; i++)
SignalEMABuffer[i]=iMAOnArray(MACDBuffer,Bars,SignalEMA,0,MODE_EMA,i);
for(i=0; i<limit; i++)
{
EMA=iMAOnArray(SignalEMABuffer,Bars,SignalEMA,0,MODE_EMA,i);
SignalBuffer[i]=SignalEMABuffer[i]+SignalEMABuffer[i]-EMA;
}
return(0);
}
//+------------------------------------------------------------------+
Comments