LabTrend1_v1

Download script
Author: Copyright � 2006, Forex-TSD.com
LabTrend1_v1

Logic Overview: LabTrend1 Indicator

The LabTrend1 script is a trend-following technical analysis tool designed to help traders identify the prevailing direction of the market by monitoring price breakouts and channel movements. It translates complex price action into visual signals, helping users distinguish between active trends and periods of consolidation.

Core Mechanics

The logic operates by constructing a dynamic "Price Channel" based on historical data. Here is how the system processes information:

1. Price Channel Construction The script constantly scans a specific number of recent bars to identify the highest highs and lowest lows. It uses these points to establish a boundary (a channel). The width of this channel is governed by a "Risk" factor, which allows users to adjust how sensitive the indicator is to price fluctuations.

2. Trend Detection via Breakouts The indicator determines the current market trend based on where the closing price sits in relation to these boundaries:

  • Bullish Trend: Triggered when the closing price breaks above the upper boundary of the channel.
  • Bearish Trend: Triggered when the closing price breaks below the lower boundary of the channel.

3. Signal Generation Once a trend is established, the script looks for specific "entry" moments to provide visual signals:

  • Trend Reversal Signals: The tool identifies the exact point where the trend flips (e.g., from bearish to bullish). It places an arrow on the chart to alert the trader to this shift.
  • Dynamic Buffering: To ensure accuracy, the script uses a "buffer" system that remembers the previous state of the market. This prevents the indicator from flickering or sending multiple signals during a single continuous move.

4. Visual Aids and Color Coding To make the data easier to read at a glance, the script offers two primary visual components:

  • Trend Signals: Distinct markers (arrows) that appear when a trend change is confirmed.
  • Color Bars (Optional): This feature highlights the active trend by drawing solid bars on the chart. These bars only appear when the price maintains momentum relative to the channel boundaries, providing a clear visual "heat map" of the current market direction.

Summary for the User

In simple terms, this script acts as a filter for market noise. It defines a "territory" for the price to move in; if the price breaks out of that territory, the indicator flags a new trend. It then provides visual confirmation—through arrows and color-coded bars—to help you see where the trend started, how strong it is currently, and when it might be changing direction.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
LabTrend1_v1
//+------------------------------------------------------------------+
//|                                                 LabTrend1_v1.mq4 |
//|                                  Copyright © 2006, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red

//---- input parameters

extern double Risk=3;         //channel narrowing factor (1..10)  
extern int Signal=1;          //Display signals mode
extern int ColorBar=1;        //Display color bars mode: 0-no,1-yes 
extern int TimeFrame=0;       //TimeFrame in min
extern int BarsNumber=1000;
//---- indicator buffers
double UpTrendSignal[];
double DownTrendSignal[];
double UpTrendBar[];
double DownTrendBar[];
double UpTrendBuffer[];
double DownTrendBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(6); 
   SetIndexBuffer(0,UpTrendSignal);
   SetIndexBuffer(1,DownTrendSignal);
   SetIndexBuffer(2,UpTrendBar);
   SetIndexBuffer(3,DownTrendBar);
   SetIndexBuffer(4,UpTrendBuffer);
   SetIndexBuffer(5,DownTrendBuffer);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexArrow(0,108);
   SetIndexArrow(1,108);
//---- name for DataWindow and indicator subwindow label
   short_name="LabTrend1("+Risk+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"UpTrend Signal");
   SetIndexLabel(1,"DownTrend Signal");
   SetIndexLabel(2,"UpTrend Bar");
   SetIndexLabel(3,"DownTrend Bar");
//----
   SetIndexDrawBegin(0,9);
   SetIndexDrawBegin(1,9);
   SetIndexDrawBegin(2,9);
   SetIndexDrawBegin(3,9);
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| LabTrend1_v1                                             |
//+------------------------------------------------------------------+
int start()
  {
   
   datetime TimeArray[];
   int    i,shift,trend,y=0;
   double high, low, price, sum, UpBar,DnBar;
   double smax[25000],smin[25000],bsmax[25000],bsmin[25000];
   double LowArray[],HighArray[];
   
   
   int Line=0;                   //Display line mode: 0-no,1-yes  
   int Length=9;          //Price Channel Period
   
   
   for (shift=BarsNumber-1;shift>=0;shift--)
   {
   UpTrendBuffer[shift]=0.0;
   DownTrendBuffer[shift]=0.0;
   UpTrendSignal[shift]=0.0;
   DownTrendSignal[shift]=0.0;
   UpTrendBar[shift]=0.0;
	DownTrendBar[shift]=0.0;
   }
// Draw price channel boards + calculation : Channel middle, half channel width, 
 
   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   ArrayCopySeries(LowArray,MODE_LOW,Symbol(),TimeFrame);     
   ArrayCopySeries(HighArray,MODE_HIGH,Symbol(),TimeFrame);  
   
   for(i=0,y=0;i<BarsNumber;i++)
   {
   if (Time[i]<TimeArray[y]) y++;  
   smin[i]=LowArray[Lowest(NULL,TimeFrame,MODE_LOW,Length,y)]; 
   smax[i]=HighArray[Highest(NULL,TimeFrame,MODE_HIGH,Length,y)];       
   
   }  
     
//
   
   for (shift=BarsNumber-Length-1;shift>=0;shift--)
   {	  
// Calculation channel stop values 
              
     bsmax[shift]=smax[shift]-(smax[shift]-smin[shift])*(33.0-Risk)/100.0;
	  bsmin[shift]=smin[shift]+(smax[shift]-smin[shift])*(33.0-Risk)/100.0;

// Signal area : any conditions to trend determination:     
// 1. Price Channel breakout 
    
     
      if(Close[shift]>bsmax[shift])  trend=1; 
      if(Close[shift]<bsmin[shift])  trend=-1;
    
    
// Correction boards values with existing trend	  		



// Drawing area	  
	  UpBar=bsmax[shift];
	  DnBar=bsmin[shift];
	  	  	 
	  if (trend>0) 
	  {
	     if (Signal==1 && UpTrendBuffer[shift+1]==-1.0)
	     {
	        
	        UpTrendSignal[shift]=Low[shift]-0.5*iATR(NULL,TimeFrame,10,shift);
	        	        
	     }
	     else
	     {
	     UpTrendBuffer[shift]=bsmin[shift];
	     UpTrendSignal[shift]=-1;
	     }
	  if(ColorBar>0)
	        {
	           if(Close[shift]>UpBar)
	           {
	              UpTrendBar[shift]=High[shift];
	              DownTrendBar[shift]=Low[shift];
	           }
	           else
	           {
	              UpTrendBar[shift]=EMPTY_VALUE;
	              DownTrendBar[shift]=EMPTY_VALUE;
	           }
	              
	        }   
	  DownTrendBuffer[shift]=-1.0;
	  }
	  
	  if (trend<0) 
	  {
	  if (Signal==1 && DownTrendBuffer[shift+1]==-1.0)
	     {
	     DownTrendSignal[shift]=High[shift]+0.5*iATR(NULL,TimeFrame,10,shift);
	     }
	     else
	     {
	     DownTrendBuffer[shift]=bsmax[shift];
	     DownTrendSignal[shift]=-1;
	     }
	  if(ColorBar>0)
	        {
	           if(Close[shift]<DnBar)
	           {
	              UpTrendBar[shift]=Low[shift];
	              DownTrendBar[shift]=High[shift];
	           }
	           else
	           {
	              UpTrendBar[shift]=EMPTY_VALUE;
	              DownTrendBar[shift]=EMPTY_VALUE;
	           }      
	        }   
	    UpTrendBuffer[shift]=-1.0;
	    }
	  
	 
   }
   return(0);
  }
//+------------------------------------------------------------------+

Comments