ChandelierStops_v1.1





//+------------------------------------------------------------------+
//|                                         ChandelierStops_v1.1.mq4 |
//|                               Copyright © 2006-07, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006-07, 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
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#property indicator_width4 1
//---- input parameters
extern int     Length=15;
extern int     ATRperiod=14;
extern double  Kv=4;
extern int     Shift=1;
extern int     AlertMode=0;
//---- indicator buffers
double UpBuffer[];
double DnBuffer[];
double UpSignal[];
double DnSignal[];
double smin[];
double smax[];
double trend[];

bool   UpTrendAlert=false, DownTrendAlert=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(7);
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
   SetIndexBuffer(2,UpSignal);
   SetIndexBuffer(3,DnSignal);
   SetIndexBuffer(4,smin);
   SetIndexBuffer(5,smax);
   SetIndexBuffer(6,trend);
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(2,108);
   SetIndexArrow(3,108);
//---- name for DataWindow and indicator subwindow label
   short_name="ChandelierStops("+Length+","+ATRperiod+","+DoubleToStr(Kv,3)+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"UpTrend");
   SetIndexLabel(1,"DnTrend");
   SetIndexLabel(2,"UpSignal");
   SetIndexLabel(3,"DnSignal");
//----
   SetIndexDrawBegin(0,Length);
   SetIndexDrawBegin(1,Length);
   SetIndexDrawBegin(2,Length);
   SetIndexDrawBegin(3,Length);

//----
   return(0);
  }

//+------------------------------------------------------------------+
//| ChandelierStops_v1.1                                                     |
//+------------------------------------------------------------------+
int start()
  {
   
   int shift,limit, counted_bars=IndicatorCounted();
   
   if ( counted_bars > 0 )  limit=Bars-counted_bars;
   if ( counted_bars < 0 )  return(0);
   if ( counted_bars ==0 )  limit=Bars-Length-1; 
     
	for(shift=limit;shift>=0;shift--) 
   {	
   smin[shift] = High[Highest(NULL,0,MODE_HIGH,Length,shift+Shift)] - Kv*iATR(NULL,0,ATRperiod,shift+Shift); 
	smax[shift] = Low[Lowest(NULL,0,MODE_LOW,Length,shift+Shift)] + Kv*iATR(NULL,0,ATRperiod,shift+Shift);
	
	  trend[shift]=trend[shift+1];
	  if ( Close[shift] > smax[shift+1] ) trend[shift] =  1;
	  if ( Close[shift] < smin[shift+1] ) trend[shift] = -1;
	
	  if ( trend[shift] >0 ) 
	  {
	  if( smin[shift]<smin[shift+1] ) smin[shift]=smin[shift+1];
	  UpBuffer[shift]=smin[shift];
	  if(trend[shift+1]!= trend[shift]) UpSignal[shift]=UpBuffer[shift];
	  else UpSignal[shift]=EMPTY_VALUE;
	  DnBuffer[shift] = EMPTY_VALUE;
	  }
	  if ( trend[shift] <0 ) 
	  {
	  if( smax[shift]>smax[shift+1] ) smax[shift]=smax[shift+1];
	  DnBuffer[shift] = smax[shift];
	  if(trend[shift+1]!= trend[shift]) DnSignal[shift]=DnBuffer[shift];
	  else DnSignal[shift]=EMPTY_VALUE;
	  UpBuffer[shift]=EMPTY_VALUE;
	  }
	
	}
//----------   
   string Message;
   
   if ( trend[2]<0 && trend[1]>0 && Volume[0]>1 && !UpTrendAlert)
	{
	Message = " "+Symbol()+" M"+Period()+": Signal for BUY";
	if ( AlertMode>0 ) Alert (Message); 
	UpTrendAlert=true; DownTrendAlert=false;
	} 
	 	  
	if ( trend[2]>0 && trend[1]<0 && Volume[0]>1 && !DownTrendAlert)
	{
	Message = " "+Symbol()+" M"+Period()+": Signal for SELL";
	if ( AlertMode>0 ) Alert (Message); 
	DownTrendAlert=true; UpTrendAlert=false;
	} 	         
//----	
	
	
	
	return(0);	
 }





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains close prices for each bar
Series array that contains tick volumes of each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_ARROW

Indicators Used:

Indicator of the average true range


Custom Indicators Used:

Order Management characteristics:

Other Features: