ChandelierExit_v1

Download script
Author: MQLService
ChandelierExit_v1

This tool is designed to help traders identify trend reversals and potential exit points by monitoring price action relative to historical volatility. It functions as a dynamic "trailing" boundary that adjusts automatically based on how much the market has been moving recently.

How the Logic Works

The script operates by analyzing three key components of the market:

1. Volatility Measurement Instead of using a fixed point or a static percentage, the tool uses an Average True Range (ATR) calculation. This allows the script to understand the "personality" of the current market—whether it is moving calmly or experiencing wild swings. It multiplies this volatility by a specific factor to create a buffer zone.

2. Dynamic Price Boundaries The script looks back at a set number of recent candles to identify the highest highs and lowest lows.

  • During an upward trend, it calculates a "ceiling" based on these highs minus the volatility buffer.
  • During a downward trend, it calculates a "floor" based on these lows plus the volatility buffer.

3. Trend Detection and Switching The core intelligence of this script lies in its ability to flip between "Bullish" and "Bearish" states. It continuously monitors whether the closing price of a candle has breached these calculated boundaries:

  • Trend Tracking: If the market is in an uptrend, the script keeps track of the "ceiling." If a candle closes significantly below that ceiling, the logic triggers a reversal, signaling that the upward momentum may have broken.
  • Trend Reversal: Conversely, if the market is in a downtrend and a price candle closes above the "floor," the script flips its internal direction, indicating a potential shift back to an uptrend.

Summary for the Trader

In plain terms, this tool acts like a protective trailing stop that breathes with the market. It doesn't just give you a single line; it constantly recalculates where the "edge" of the current move is by looking at recent history and current volatility. When the price finally breaks through these calculated edges, it provides a clear signal that the prevailing trend has likely shifted, helping you decide when to exit a position or look for a new entry.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
ChandelierExit_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                               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