ChandelierExit

Download script
Author: MQLService
ChandelierExit

This script is designed as a visual trading tool that helps market participants identify potential trend reversals and price exhaustion points. It functions by tracking the "swing" of price action and creating dynamic boundaries to signal when a move might be losing momentum.

How the Logic Works

The tool operates based on three primary components: Price Extremes, Market Volatility, and Trend Direction.

1. Identifying Highs and Lows Instead of looking at every single price tick, the script scans a specific window of recent history (defined by the "Range" setting). It identifies the highest peak and the lowest valley within that timeframe. This helps filter out minor market "noise" and focuses on significant price movements.

2. Calculating Volatility Spacing The tool uses a volatility measurement (known as ATR) to determine how far away the trend lines should sit from the actual price. By multiplying this measurement, the script creates a "buffer zone."

  • For a downward move, it subtracts this value from the recent highs.
  • For an upward move, it adds this value to the recent lows.

3. Trend Tracking and Switching The core intelligence of the script lies in its ability to switch between "Bullish" and "Bearish" states:

  • During an Upward Trend: The script focuses on a trailing ceiling. If the price closes below this specific ceiling, it recognizes a potential breakdown and flips the logic to track a trailing floor instead.
  • During a Downward Trend: The script focuses on a trailing floor. If the price closes above this floor, it recognizes a potential breakout and flips the logic to track a new ceiling.

Summary for the User

Essentially, this tool acts like a "safety net" that follows the price. When the market is moving strongly in one direction, the lines stay wide enough to allow the trend to breathe. However, once the price breaches these dynamically calculated boundaries, the script signals a shift in momentum, helping traders visualize when a trend has likely exhausted itself and may be ready to reverse.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
ChandelierExit
//+------------------------------------------------------------------+
//|                                               ChandelierExit.mq4 |
//|                                                       MQLService |
//|                                           scripts@mqlservice.com |
//+------------------------------------------------------------------+
#property copyright "MQLService"
#property link      "scripts@mqlservice.com"

#property indicator_chart_window
#property indicator_buffers 4
//#property indicator_color1 Blue
//#property indicator_color2 Red
#property indicator_color3 Orange
#property indicator_color4 Magenta
//---- input parameters
extern int       Range=15;
extern int       Shift=1;
extern int       ATRPeriod=14;
extern int       MultipleATR=4;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int direction=1;
double ATRvalue;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   //SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   //SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexEmptyValue(3,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) counted_bars=0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=limit; i>=0; i--)
      {
         ATRvalue=iATR(NULL,0,ATRPeriod,0)*MultipleATR;
         ExtMapBuffer1[i]=High[Highest(NULL,0,MODE_HIGH,Range,i+Shift)]-ATRvalue;
         ExtMapBuffer2[i]=Low[Lowest(NULL,0,MODE_LOW,Range,i+Shift)]+ATRvalue;
         if(direction==1)
           { 
            if(Close[i+1]<ExtMapBuffer1[i+1])
               {
                  direction=-1;
                  ExtMapBuffer3[i]=ExtMapBuffer2[i];
               }
            else
                  ExtMapBuffer3[i]=ExtMapBuffer1[i];   
           }
         if(direction==-1)
           { 
            if(Close[i+1]>ExtMapBuffer2[i+1])
               {
                  direction=1;
                  ExtMapBuffer4[i]=ExtMapBuffer1[i];
               }
            else
                  ExtMapBuffer4[i]=ExtMapBuffer2[i];   
           }
      }   
   return(0);
  }
//+------------------------------------------------------------------+

Comments