nonlagdotalert

Download script
Author: Copyright � 2006-07, TrendLaboratory
nonlagdotalert

The NonLagDOT script is a specialized technical analysis tool designed to identify market trends with high precision while minimizing the typical "lag" (the delay between price movement and indicator reaction) found in standard moving averages. It provides traders with a visual roadmap of market direction by smoothing out price fluctuations without losing the responsiveness needed for timely decision-making.

Core Logic and Functionality

1. Advanced Smoothing Mechanism Unlike basic moving averages that simply average recent prices, this script utilizes a sophisticated mathematical approach to calculate a "Non-Lag" line. It applies a weighting system based on trigonometric functions (specifically cosine waves). This allows the indicator to prioritize price data in a way that captures the underlying trend curve more accurately, helping to filter out "noise" while remaining sensitive to actual shifts in momentum.

2. Trend Detection and Visualization The script continuously evaluates the relationship between the current calculated moving average and the previous period's value. Based on this comparison, it categorizes the market into two distinct states:

  • Uptrend: When the indicator shows a positive progression, it marks the trend as "Up" (visually represented in Aqua).
  • Downtrend: When the indicator shows a negative progression, it marks the trend as "Down" (visually represented in HotPink).

The script also features a "ColorBarBack" logic, which helps visually bridge transitions between these states, ensuring that the shift from an upward move to a downward move is clearly defined on the chart.

3. Precision Filtering and Customization To ensure the signals are reliable and not triggered by minor, insignificant price wiggles, the script includes several user-adjustable parameters:

  • Filter: This acts as a sensitivity threshold. It prevents the indicator from flipping its trend direction unless the price movement exceeds a specific magnitude.
  • Deviation: Allows for a slight adjustment in the calculation to tailor the indicator's responsiveness to different market types (e.g., high volatility vs. steady trends).
  • Length: Determines the historical window used to calculate the trend, allowing users to switch between looking at short-term fluctuations or long-term structural moves.

4. Real-Time Alerts The script is equipped with an automated notification system. It monitors for "crossovers"—the specific moments when the trend flips from down to up (or vice versa). When these critical turning points occur, the script can trigger:

  • Visual Alerts: On-screen messages providing the symbol and timeframe.
  • Audio Alerts: Sound files that play immediately upon a trend change.
  • Logical Safeguards: The alert system is designed to trigger only once per trend shift, ensuring the trader isn't overwhelmed with repetitive notifications during a single sustained move.

Summary for the Trader

In essence, NonLagDOT acts as a "smart" filter. It analyzes price data using a weighted mathematical model to produce a smooth line that tells you which way the market is currently heading. By combining this smoothing with specific filters and real-time alerts, it aims to highlight clear entry and exit points while ignoring the minor distractions of daily market volatility.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alerts
9 Views
0 Downloads
0 Favorites
nonlagdotalert
//+------------------------------------------------------------------+
//|                                                    NonLagDOT.mq4 |
//|                             Copyright © 2006-07, TrendLaboratory |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                   E-mail: igorad2003@yahoo.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006-07, TrendLaboratory"
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_width1 2
#property indicator_color2 Aqua
#property indicator_width2 2
#property indicator_color3 HotPink
#property indicator_width3 2


//---- input parameters
extern int     Price          = 0;
extern int     Length         = 30;
extern int     Displace       = 0;
extern int     Filter         = 0;
extern int     Color          = 1;
extern int     ColorBarBack   = 0;
extern double  Deviation      = 0;         
extern int     SoundAlertMode = 1;  
double Cycle =  4;

//---- indicator buffers
double MABuffer[];
double UpBuffer[];
double DnBuffer[];
double price[];
double trend[];

bool   UpTrendAlert=false, DownTrendAlert=false;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   int ft=0;
   string short_name;
//---- indicator line
   IndicatorBuffers(5);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,MABuffer);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,UpBuffer);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2,DnBuffer);
   SetIndexBuffer(3,price);
   SetIndexBuffer(4,trend);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);
   SetIndexArrow(2,159);
   SetIndexArrow(3,159);
//---- name for DataWindow and indicator subwindow label
   short_name="NonLagDot("+Length+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"NLD");
   SetIndexLabel(1,"Up");
   SetIndexLabel(2,"Dn");
//----
   SetIndexShift(0,Displace);
   SetIndexShift(1,Displace);
   SetIndexShift(2,Displace);
   
   SetIndexDrawBegin(0,Length*Cycle+Length);
   SetIndexDrawBegin(1,Length*Cycle+Length);
   SetIndexDrawBegin(2,Length*Cycle+Length);
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| NonLagMA_v4                                                     |
//+------------------------------------------------------------------+
int start()
{
   int    i,shift, counted_bars=IndicatorCounted(),limit;
   double alfa, beta, t, Sum, Weight, step,g;
   double pi = 3.1415926535;    
   
   double Coeff =  3*pi;
   int Phase = Length-1;
   double Len = Length*Cycle + Phase;  
   
   if ( counted_bars > 0 )  limit=Bars-counted_bars;
   if ( counted_bars < 0 )  return(0);
   if ( counted_bars ==0 )  limit=Bars-Len-1; 
   if ( counted_bars < 1 ) 
   for(i=1;i<Length*Cycle+Length;i++) 
   {
   MABuffer[Bars-i]=0;    
   UpBuffer[Bars-i]=0;  
   DnBuffer[Bars-i]=0;  
   }
   
   for(shift=limit;shift>=0;shift--) 
   {	
   Weight=0; Sum=0; t=0;
       
      for (i=0;i<=Len-1;i++)
	   { 
      g = 1.0/(Coeff*t+1);   
      if (t <= 0.5 ) g = 1;
      beta = MathCos(pi*t);
      alfa = g * beta;
      //if (shift>=1) price[i] = iMA(NULL,0,Per,Displace,Mode,Price,shift+i); 
      //else 
      price[i] = iMA(NULL,0,1,0,MODE_SMA,Price,shift+i); 
      Sum += alfa*price[i];
      Weight += alfa;
      if ( t < 1 ) t += 1.0/(Phase-1); 
      else if ( t < Len-1 )  t += (2*Cycle-1)/(Cycle*Length-1);
      }

	if (Weight > 0) MABuffer[shift] = (1.0+Deviation/100)*Sum/Weight;
   
      if (Filter>0)
      {
      if( MathAbs(MABuffer[shift]-MABuffer[shift+1]) < Filter*Point ) MABuffer[shift]=MABuffer[shift+1];
      }
      
      if (Color>0)
      {
      trend[shift]=trend[shift+1];
      if (MABuffer[shift]-MABuffer[shift+1] > Filter*Point) trend[shift]= 1; 
      if (MABuffer[shift+1]-MABuffer[shift] > Filter*Point) trend[shift]=-1; 
         if (trend[shift]>0)
         {  
         UpBuffer[shift] = MABuffer[shift];
         if (trend[shift+ColorBarBack]<0) UpBuffer[shift+ColorBarBack]=MABuffer[shift+ColorBarBack];
         DnBuffer[shift] = EMPTY_VALUE;
         if (SoundAlertMode>0 && trend[shift+1]<0 && shift==0) PlaySound("alert2.wav");
         }
         if (trend[shift]<0) 
         {
         DnBuffer[shift] = MABuffer[shift];
         if (trend[shift+ColorBarBack]>0) DnBuffer[shift+ColorBarBack]=MABuffer[shift+ColorBarBack];
         UpBuffer[shift] = EMPTY_VALUE;
         if (SoundAlertMode>0 && trend[shift+1]>0 && shift==0) PlaySound("alert2.wav");
         }
      }
   }
//----------   
   string Message;
   
   if ( trend[2]<0 && trend[1]>0 && Volume[0]>1 && !UpTrendAlert)
	{
	Message = "Nonlagdot Alert: "+Symbol()+" M"+Period()+": GOING UP";
	if ( SoundAlertMode>0 ) Alert (Message); 
	UpTrendAlert=true; DownTrendAlert=false;
	} 
	 	  
	if ( trend[2]>0 && trend[1]<0 && Volume[0]>1 && !DownTrendAlert)
	{
	Message = "Nonlagdot Alert: "+Symbol()+" M"+Period()+": GOING DOWN";
	if ( SoundAlertMode>0 ) Alert (Message); 
	DownTrendAlert=true; UpTrendAlert=false;
	} 	         
//----
	return(0);	
}

Comments