ChandelierStops_v1.1

Download script
Author: Copyright � 2006-07, Forex-TSD.com
ChandelierStops_v1.1

This script is designed to help traders identify and visualize market trends on a price chart. It acts as a "trend-following" tool, meaning its primary goal is to determine whether the current market movement is moving upward or downward and to provide specific markers for when those movements shift.

How the Logic Works

1. Dynamic Price Tracking The script calculates two moving boundaries based on recent price action. It looks back at a specific number of historical candles (defined by the user) to find the highest highs and lowest lows within that period. By combining this data with a volatility measure (which accounts for how much the price is "swinging"), the script creates a ceiling and a floor for the market.

2. Trend Identification The core logic works by comparing the current closing price against these boundaries:

  • Bullish Movement: If the price closes above the upper boundary, the script recognizes an upward trend.
  • Bearish Movement: If the price closes below the lower boundary, the script recognizes a downward trend.

Once a trend is established, the script "locks" into that direction. It continues to track the movement until the price breaks through the opposite boundary significantly enough to trigger a reversal.

3. Visual Signals and Alerts To make this information easy to read at a glance, the script provides several visual elements:

  • Trend Lines: It draws lines on the chart that represent the current "stop" levels. These help traders see where the trend might end.
  • Reversal Markers: When the logic detects a definitive change—moving from an uptrend to a downtrend, or vice versa—the script places specific markers (arrows) on the chart to highlight the exact moment of the shift.
  • Notifications: The script can be configured to send active alerts (pop-ups or sounds). If the price crosses a threshold and confirms a new trend, the script will notify the user immediately, allowing for faster reaction times in fast-moving markets.

Summary of Purpose

Instead of making the trader guess whether a move is real or just "noise," this script uses mathematical boundaries to confirm trends. It simplifies the chart by showing you where the price is currently heading and providing clear visual cues when that direction changes.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
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);	
 }

Comments