ZeroLag_MACD_OsMA
Download scriptThis tool is designed as a specialized technical analysis indicator for trading platforms, specifically created to provide traders with a more responsive and "lag-free" perspective on market momentum. While traditional indicators often suffer from a delay between a price movement and the indicator's reaction, this script utilizes a unique mathematical approach to tighten that connection.
Core Logic and Components
The indicator functions by processing three primary layers of data:
1. The ZeroLag Momentum Engine At its foundation, the script takes standard Exponential Moving Averages (EMA)—which are used to smooth out price fluctuations—and applies a "ZeroLag" calculation. Instead of simply following the trend, it compares current values against their moving averages and adjusts the data points to neutralize the inherent delay found in standard smoothing techniques. This allows the indicator to react more quickly to sudden shifts in market direction.
2. The MACD Foundation By applying this ZeroLag logic to both a "Fast" and a "Slow" timeframe, the script generates a unique version of the MACD (Moving Average Convergence Divergence). It calculates the difference between these two reactive averages. This serves as the primary visualization of momentum, showing whether the market is accelerating or decelerating in real-time.
3. The Signal and Osma Layers To further refine the data for the user, the script adds two additional layers:
- Signal Line: A smoothed version of the ZeroLag MACD that helps identify potential turning points by highlighting where momentum is beginning to change its trajectory.
- Osma (Oscillator): This is a final calculation that measures the distance between the MACD and the Signal line, multiplied by a specific factor. It acts as a visual oscillator, making it easier for traders to see the strength of a trend and identify "overextended" market conditions.
Visual Representation
The indicator outputs three distinct visual elements in a separate window:
- A Histogram representing the primary ZeroLag MACD momentum.
- A Signal Line to track the smooth trend of that momentum.
- An Osma Oscillator, which provides an exaggerated view of the relationship between the two, highlighting the intensity of current price movements.
In summary, this tool is designed for traders who require high-precision momentum data, aiming to strip away the "lag" typically associated with moving averages while providing a multi-layered view of market strength and trend direction.
//+------------------------------------------------------------------+
//| ZeroLag MACD.mq4 |
//| RD |
//| marynarz15@wp.pl |
//+------------------------------------------------------------------+
//mod2008fxtsd + osma
#property copyright "RD"
#property link "marynarz15@wp.pl"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Purple
#property indicator_color2 RoyalBlue
#property indicator_color3 Orange
#property indicator_width1 2
//---- input parameters
extern int FastEMA=12;
extern int SlowEMA=24;
extern int SignalEMA=9;
extern double OsmaMultiplier=3.5;
//---- buffers
double MACDBuffer[];
double SignalBuffer[];
double FastEMABuffer[];
double SlowEMABuffer[];
double SignalEMABuffer[];
double OsmaBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(6);
SetIndexBuffer(1,MACDBuffer);
SetIndexBuffer(2,SignalBuffer);
SetIndexBuffer(5,FastEMABuffer);
SetIndexBuffer(3,SlowEMABuffer);
SetIndexBuffer(4,SignalEMABuffer);
SetIndexBuffer(0,OsmaBuffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexDrawBegin(0,SlowEMA);
SetIndexDrawBegin(1,SlowEMA);
SetIndexDrawBegin(2,SlowEMA);
IndicatorShortName("ZLag MACD Osma("+FastEMA+","+SlowEMA+","+SignalEMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"Osma");
//----
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;
OsmaBuffer[i]=(MACDBuffer[i]-SignalBuffer[i])*OsmaMultiplier;
}
return(0);
}
//+------------------------------------------------------------------+
Comments