ZeroLag MACD_005

Download script
Author: RD
ZeroLag MACD_005

This tool is a specialized technical analysis indicator designed to help traders identify market momentum while minimizing the "lag" often associated with traditional moving averages. By utilizing a "ZeroLag" calculation method, it aims to provide a more responsive view of price action compared to standard indicators.

Core Logic Overview

The script functions by processing three distinct layers of data to generate two visual components: a histogram and a signal line.

1. The Foundation: Exponential Moving Averages (EMA) The tool begins by tracking two primary trends using the Fast and Slow Exponential Moving Averages. Unlike simple averages, these give more weight to recent price data, allowing the indicator to react more quickly to current market shifts.

2. The "ZeroLag" Enhancement Standard indicators often show signals after a move has already happened. This script corrects for that delay by applying a unique mathematical adjustment:

  • It calculates a standard EMA of the existing Fast and Slow averages.
  • It then compares the current values against these calculated averages to determine the difference.
  • By subtracting the moving average from twice the current value, the tool effectively "cancels out" much of the smoothing delay, creating a more immediate representation of the price momentum.

3. Generating the MACD Histogram The primary visual output—the histogram—is created by measuring the gap between the adjusted Fast trend and the adjusted Slow trend.

  • When the Fast trend is significantly higher than the Slow trend, it indicates upward momentum.
  • When the Fast trend falls below the Slow trend, it indicates downward momentum.

4. The Signal Line To provide a smoother reference point for these movements, the script performs an additional pass of calculations. It applies a final smoothing process to the MACD data itself. This results in a secondary "Signal Line," which traders use to identify potential turning points or crossovers where the momentum might be shifting from one direction to another.

Summary for Traders

In practical terms, this indicator provides a refined view of market velocity. It takes standard trend-following logic and optimizes it to stay as close to real-time price action as possible, offering a clearer picture of whether the market is accelerating in an upward or downward direction with less "historical weight" holding the signal back.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
17 Views
0 Downloads
0 Favorites
ZeroLag MACD_005
//+------------------------------------------------------------------+
//|                                                 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 RoyalBlue
#property indicator_color2 Gold
//---- 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