This script is a specialized technical analysis tool designed for the MetaTrader platform. It functions as a momentum indicator that combines multiple layers of market data to provide a smoother, more responsive view of price trends. Instead of relying on a single calculation, it uses a sophisticated multi-layered approach to filter out "market noise" while attempting to maintain real-time accuracy.
Core Logic and Methodology
1. Multi-Layered Stochastic Integration The primary logic of the script is built upon the aggregation of five different Stochastic oscillators simultaneously. Each of these layers looks at price data over varying time horizons (ranging from short-term to long-term periods).
- Each layer is assigned a specific weight.
- By combining these five distinct views into one unified value, the script creates a comprehensive "consensus" of market momentum. This helps in identifying whether the broader trend is gaining strength or losing steam across different timeframes at once.
2. Momentum Smoothing (Zero-Lag Logic) While standard indicators often suffer from "lag"—where the visual data trails significantly behind the actual current price—this script employs a specific smoothing technique. It calculates a primary trend and then applies a recursive smoothing constant. This ensures that the resulting lines on your chart are fluid and easy to read, yet they react quickly to significant price shifts without the erratic jumping often seen in high-sensitivity indicators.
3. Data Visualization The script generates two distinct visual lines on a separate window of the trading platform:
- Fast Trend Line: Represents the immediate, weighted momentum calculated from the combined stochastic layers.
- Low Trend Line: A more stabilized version of the fast trend that incorporates historical data points to provide a smoother trajectory.
Operational Behavior
The script requires a minimum amount of historical data to be present on the chart before it begins to display results. This ensures that the multi-layered calculations have enough "background" information to produce accurate values. Once initialized, it continuously updates both lines in real-time as new price ticks arrive.
Summary for the User
In simple terms, this tool acts as a "sieve." It takes five different perspectives of market momentum, blends them together to create a unified signal, and then smooths that signal out so you can see the underlying trend clearly. It is designed to help traders distinguish between minor price fluctuations and significant shifts in market direction.
// Ðåäàêòèðîâàíèå è èñïðàâëåíèÿ 22.09.2008 Íèêîëàé Êîñèöèí
//+X================================================================X+
//| ZerolagStochs.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+X================================================================X+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "perky_z@yahoo.com"
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüîì îêíå
#property indicator_separate_window
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ
#property indicator_buffers 2
//---- öâåòà èíäèêàòîðà
#property indicator_color1 Blue
#property indicator_color2 Red
//---- Îáúÿâëåíèå èíäèêàòîðíûõ áóôåðîâ
double FastTrendBuffer[];
double LowTrendBuffer[];
//---- Îáúÿâëåíèå öåëûõ êîíñòàíò
int StartBar;
//---- Îáúÿâëåíèå êîíñòàíò ñ ïëàâàþùåé òî÷êîé
double smoothConst, smoothing;
//+X================================================================X+
//| ZerolagStochs() function |
//+X================================================================X+
double ZerolagStochs(string symbol, int timeframe, int MA_MODE, int LINE_MODE, int SLOWING, int bar)
{
//----+
double Stoch1, Stoch2, Stoch3, Stoch4, Stoch5;
//----
Stoch1 = 0.05 * iStochastic(symbol, timeframe, 8, 3, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
Stoch2 = 0.10 * iStochastic(symbol, timeframe, 21, 5, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
Stoch3 = 0.16 * iStochastic(symbol, timeframe, 34, 8, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
Stoch4 = 0.26 * iStochastic(symbol, timeframe, 55, 13, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
Stoch5 = 0.43 * iStochastic(symbol, timeframe, 89, 21, SLOWING, MA_MODE, NULL, LINE_MODE, bar); // StartBar = 89 + 21 + 1;!!!
//----
return(Stoch1 + Stoch2 + Stoch3 + Stoch4 + Stoch5);
//----+
}
//+X================================================================X+
//| ZerolagStochs indicator initialization function |
//+X================================================================X+
int init()
{
//---+
//---- 2 èíäèêàòîðíûõ áóôåðà èñïîëüçîâàíû äëÿ ñ÷¸òà
SetIndexBuffer(0, FastTrendBuffer);
SetIndexBuffer(1, LowTrendBuffer );
//---- îïðåäåëåíèå ñòèëÿ èñïîëíåíèÿ ãðàôèêà
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
//---- Óñòàíîâêà ôîðìàòà òî÷íîñòè îòîáðàæåíèÿ èíäèêàòîðà
IndicatorDigits(Digits);
//---- Èìÿ èíäèêàòîðà â ñóáúîêíå
IndicatorShortName("Zero Lag Stocs_");
//---- Ëýéáû äëÿ èíäèêàòîðíûõ ëèíèé
SetIndexLabel(0, "FastTrendLine");
SetIndexLabel(1, "LowTrendLine");
//---- Èíèöèàëèçàöèÿ êîíñòàíò
smoothing = 15;
StartBar = 89 + 21 + 1;
smoothConst = (smoothing - 1.0) / smoothing;
//---- óñòàíîâêà íîìåðà áàðà,
//íà÷èíàÿ ñ êîòîðîãî áóäåò îòðèñîâûâàòüñÿ èíäèêàòîð
SetIndexDrawBegin(0, StartBar - 1);
SetIndexDrawBegin(1, StartBar);
//---- Çàâåðøåíèå èíèöèàëèçàöèè
return(0);
//---+
}
//+X================================================================X+
//| ZerolagStochs indicator start function |
//+X================================================================X+
int start()
{
//---+
//---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷¸òà
if (Bars < StartBar)
return(0);
//---- Îáúÿâëåíèå ñòàòè÷åñêèõ ïåðåìåííûõ
static bool TrueStart;
//---- Îáúÿâëåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé
double FastTrend, LowTrend;
double Stoch1, Stoch2, Stoch3, Stoch4, Stoch5;
//----+ Îáúÿâëåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîñ÷èòàííûõ áàðîâ
int limit, MaxBar, bar, counted_bars = IndicatorCounted();
//---- ïðîâåðêà íà âîçìîæíûå îøèáêè
if (counted_bars < 0)
return(-1);
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð äîëæåí áûòü ïåðåñ÷èòàí
if (counted_bars > 0)
counted_bars--;
//---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà,
//íà÷èíàÿ ñ êîòîðîãî áóäåò ïðîèçåä¸í ïåðåñ÷¸ò âñåõ áàðîâ
MaxBar = Bars - 1 - StartBar;
//---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà,
//íà÷èíàÿ ñ êîòîðîãî áóäåò ïðîèçåä¸í ïåðåñ÷¸ò òîëüêî íîâûõ áàðîâ
limit = (Bars - 1 - counted_bars);
//---- èíèöèàëèçàöèÿ íóëÿ
if (limit >= MaxBar || !TrueStart)
{
limit = MaxBar;
TrueStart = true;
//----
for (bar = Bars - 1; bar > MaxBar; bar--)
{
FastTrendBuffer[bar] = 0.0;
LowTrendBuffer [bar] = 0.0;
}
FastTrend = ZerolagStochs(Symbol(), 0, MODE_SMA, MODE_MAIN, 3, MaxBar + 1);
LowTrendBuffer[MaxBar + 1] = FastTrend / smoothing;
}
//---+ ÎÑÍÎÂÍÎÉ ÖÈÊË ÐÀÑרÒÀ ÈÍÄÈÊÀÒÎÐÀ
for (bar = limit; bar>= 0; bar--)
{
FastTrend = ZerolagStochs(Symbol(), 0, MODE_SMA, MODE_MAIN, 3, bar);
//----
LowTrend = FastTrend / smoothing + LowTrendBuffer[bar + 1] * smoothConst;
//----
FastTrendBuffer[bar] = FastTrend;
LowTrendBuffer [bar] = LowTrend;
}
//---+
return(0);
//---+
}
//+X----------------------------------------------------------------X+
Comments