ZeroLag_MACD-OsMA(AM)
Download scriptThe ZeroLag MACD-OsMA is a specialized technical analysis tool designed to provide traders with a more responsive view of market momentum. It combines elements of the Moving Average Convergence Divergence (MACD) and the Oscillator of Moving Averages (OsMA) while applying a "ZeroLag" logic to minimize the delay typically found in standard trend-following indicators.
Core Functionality
The script works by processing two primary data streams based on user-defined "Fast," "Slow," and "Signal" periods. It calculates these values to determine the speed and direction of price movement. Unlike standard indicators that can sometimes appear to lag behind current market action, this tool focuses on identifying immediate shifts in momentum.
Key Visual Components
The indicator populates a separate window with several distinct visual elements to help identify different market dynamics:
- Momentum Histograms: The tool displays visual bars that represent the strength of price movements. By comparing current values against previous ones, it highlights whether the "momentum" is increasing or decreasing in real-time.
- Trend Directionality: The script distinguishes between upward and downward movements. It uses a logic gate to determine if the current momentum is gaining or losing steam, reflecting this as specific histogram colors (Teal for upward movement, Red for downward movement).
- Acceleration Tracking: Beyond just showing where the price is going, the tool calculates the difference between various moving averages. This allows it to track acceleration—essentially showing how quickly the market is speeding up or slowing down.
How It Works for the Trader
- Data Processing: The script pulls data from a "ZeroLag" foundation, which filters out noise while keeping the signal as close to the live price action as possible.
- Directional Filtering: It constantly monitors the change between the current bar and the previous bar. If the momentum turns negative or shows a slowdown, the visual representation shifts accordingly.
- Dual Layer Analysis: By providing both a standard momentum view and an "accelerator" view (the difference between two sets of data), it gives users a clearer picture of whether a trend is healthy and continuing or exhausting and ready to reverse.
In summary, this tool is designed for traders who need to see market shifts quickly. It translates complex moving average mathematics into a color-coded visual map that highlights both the current direction of the trend and the underlying speed of that movement.
//+------------------------------------------------------------------+
//| ZeroLag MACD-OsMA(AM).mq4 |
//| Andrey Matvievskiy |
//| |
//+------------------------------------------------------------------+
#property copyright "Andrey Matvievskiy"
#property link ""
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Teal
#property indicator_color4 Red
#property indicator_color5 Teal
#property indicator_color6 Red
#property indicator_color7 Black
extern int FastEMA = 12;
extern int SlowEMA = 24;
extern int SignalEMA = 9;
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
double ExtBuffer4[];
double ExtBuffer5[];
double ExtBuffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(7);
//---- drawing settings
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_NONE);
SetIndexStyle(2,DRAW_HISTOGRAM,0,2);
SetIndexStyle(3,DRAW_HISTOGRAM,0,2);
SetIndexStyle(4,DRAW_HISTOGRAM,0,1);
SetIndexStyle(5,DRAW_HISTOGRAM,0,1);
SetIndexStyle(6,DRAW_NONE);
IndicatorDigits(Digits+2);
//---- 4 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,ExtBuffer3);
SetIndexBuffer(4,ExtBuffer4);
SetIndexBuffer(5,ExtBuffer5);
SetIndexBuffer(6,ExtBuffer6);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("ZeroLag MACD-OsMA(AM)("+FastEMA+","+SlowEMA+","+SignalEMA+")");
SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev1,current1,prev2,current2;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
ExtBuffer0[i]=iCustom(NULL,0,"ZeroLag_MACD",FastEMA,SlowEMA,SignalEMA,0,i);
for(i=0; i<limit; i++)
ExtBuffer1[i]=iCustom(NULL,0,"ZeroLag_MACD",FastEMA,SlowEMA,SignalEMA,1,i);
bool up1=true;
bool up2=true;
for(i=limit-1; i>=0; i--)
{
current1=ExtBuffer0[i];
prev1=ExtBuffer0[i+1];
if(current1>prev1) up1=true;
if(current1<prev1) up1=false;
if(!up1)
{
ExtBuffer5[i]=current1;
ExtBuffer4[i]=0.0;
}
else
{
ExtBuffer4[i]=current1;
ExtBuffer5[i]=0.0;
}
current2=ExtBuffer0[i]-ExtBuffer1[i];
prev2=ExtBuffer0[i+1]-ExtBuffer1[i+1];
if(current2>prev2) up2=true;
if(current2<prev2) up2=false;
if(!up2)
{
ExtBuffer3[i]=current2;
ExtBuffer2[i]=0.0;
}
else
{
ExtBuffer2[i]=current2;
ExtBuffer3[i]=0.0;
}
ExtBuffer6[i]=current2;
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments