ZerolagStochs_

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
ZerolagStochs_

This script is a custom technical analysis tool designed for the MetaTrader platform. Its primary purpose is to provide traders with a more responsive and fluid trend visualization compared to standard oscillators. It achieves this by combining multiple layers of data into a single, cohesive "Zero Lag" calculation.

Core Logic Overview

The indicator operates on a principle of multi-layered aggregation. Rather than relying on a single momentum value—which can often be noisy or delayed—this script calculates five different versions of the Stochastic Oscillator simultaneously.

Each of these five layers is configured with different parameters:

  • Varied Timeframes: Each layer uses its own specific "K" and "D" periods (ranging from fast/short-term to slow/long-term).
  • Weighting Factors: Every layer is multiplied by a unique mathematical factor. This ensures that while the script looks at both short-term and long-term trends, it gives appropriate relative importance to each one.

By summing these five weighted layers together, the script creates a comprehensive "Fast Trend" value. This approach helps filter out minor market noise while remaining sensitive enough to capture significant price movements quickly.

Smoothing and Trend Tracking

The script then processes this aggregated data into two distinct visual lines:

  1. Fast Trend Line: This represents the immediate combined momentum of the five layers described above. It is designed to show the current "heartbeat" of the market trend.
  2. Low Trend Line (Smoothed Trend): This is a sophisticated moving average of the Fast Trend. Instead of a standard average that might lag significantly behind price, it uses a specific smoothing constant. This creates a "memory" effect where the current value is blended with a portion of the previous value.

How it behaves on a chart

  • Reduced Lag: By combining multiple different time horizons into one calculation, the script aims to provide a "Zero Lag" feel, meaning the indicator reacts faster to price changes than many traditional indicators.
  • Trend Clarity: The interaction between the Fast Trend and the Low Trend line helps traders identify the direction of the market. When these lines move in harmony, they signal a strong trend; when they diverge or flatten, they may suggest a loss of momentum or a potential reversal.
  • Data Stability: The script includes internal logic to ensure it only begins drawing once enough historical data has been collected to calculate its longest period accurately, preventing "choppy" or inaccurate readings at the very beginning of a chart.
Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
ZerolagStochs_
// Ðåäàêòèðîâàíèå è èñïðàâëåíèÿ 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
//----+ +----------------------------+
//---- ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ  |
//----+ +----------------------------+
extern int    Slowing = 3;
extern int    MA_Method = MODE_SMA;
extern int    smoothing = 15;
//----
extern double Factor1 = 0.05;
extern int    Kperiod1 = 8;
extern int    Dperiod1 = 3;
//----
extern double Factor2 = 0.10;
extern int    Kperiod2 = 21;
extern int    Dperiod2 = 5;
//----
extern double Factor3 = 0.16;
extern int    Kperiod3 = 34;
extern int    Dperiod3 = 8;
//----
extern double Factor4 = 0.26;
extern int    Kperiod4 = 55;
extern int    Dperiod4 = 13;
//----
extern double Factor5 = 0.43;
extern int    Kperiod5 = 89;
extern int    Dperiod5 = 21;
//---- Îáúÿâëåíèå  èíäèêàòîðíûõ áóôåðîâ
double FastTrendBuffer[];
double LowTrendBuffer[];
//---- Îáúÿâëåíèå öåëûõ êîíñòàíò
int StartBar;
//---- Îáúÿâëåíèå êîíñòàíò ñ ïëàâàþùåé òî÷êîé
double smoothConst;
//+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 = Factor1 * iStochastic(symbol, timeframe, Kperiod1, Dperiod1, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
   Stoch2 = Factor2 * iStochastic(symbol, timeframe, Kperiod2, Dperiod2, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
   Stoch3 = Factor3 * iStochastic(symbol, timeframe, Kperiod3, Dperiod3, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
   Stoch4 = Factor4 * iStochastic(symbol, timeframe, Kperiod4, Dperiod4, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
   Stoch5 = Factor5 * iStochastic(symbol, timeframe, Kperiod5, Dperiod5, SLOWING, MA_MODE, NULL, LINE_MODE, bar);
   //----
   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");
   //---- Èíèöèàëèçàöèÿ êîíñòàíò
   smoothConst = (smoothing - 1.0) / smoothing;
   //---- 
   int PeriodBuffer[5]; 
   //---- Ðàñ÷¸ò ñòàðòîâîãî áàðà
   PeriodBuffer[0] = Kperiod1 + Dperiod1; 
   PeriodBuffer[1] = Kperiod2 + Dperiod2; 
   PeriodBuffer[2] = Kperiod3 + Dperiod3; 
   PeriodBuffer[3] = Kperiod4 + Dperiod4; 
   PeriodBuffer[4] = Kperiod5 + Dperiod5;
   //----
   StartBar = ArrayMaximum(PeriodBuffer, WHOLE_ARRAY, 0) + 1;
   //---- óñòàíîâêà íîìåðà áàðà, 
           //íà÷èíàÿ ñ êîòîðîãî áóäåò îòðèñîâûâàòüñÿ èíäèêàòîð 
   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, MA_Method, MODE_MAIN, Slowing, MaxBar + 1);
     LowTrendBuffer[MaxBar + 1] = FastTrend / smoothing;
    } 
    
   //---+ ÎÑÍÎÂÍÎÉ ÖÈÊË ÐÀÑרÒÀ ÈÍÄÈÊÀÒÎÐÀ
   for (bar = limit; bar>= 0; bar--)
	 {
     FastTrend = ZerolagStochs(Symbol(), 0, MA_Method, MODE_MAIN, Slowing, bar);
     //----
     LowTrend = FastTrend / smoothing + LowTrendBuffer[bar + 1] * smoothConst;
     //----
     FastTrendBuffer[bar] = FastTrend;
	  LowTrendBuffer [bar] = LowTrend;   
	 }
	//---+
	return(0);
//---+
  }
//+X----------------------------------------------------------------X+

Comments