FX Sniper's Chandelier_v1

Download script
FX Sniper's Chandelier_v1

This script is designed as a dynamic visual tool for traders to manage risk by automatically plotting potential Stop Loss (SL) levels on a price chart. Rather than using a fixed price point, the logic calculates these levels based on market volatility and historical price movement, allowing the "safety net" to adjust as the market moves.

Core Logic Overview

The script operates by monitoring two primary types of market conditions: Long Positions (where you expect prices to rise) and Short Positions (where you expect prices to fall). Depending on your selection, it calculates a protective boundary that follows the price action.

How the Calculation Works

To ensure the Stop Loss isn't too tight or too wide, the script relies on two key mathematical components:

  1. Volatility Measurement: It uses an Average True Range (ATR) calculation. This measures how much the market is "breathing" over a specific period. If the market becomes highly volatile, the stop loss level will naturally widen; if the market calms down, the level may tighten.
  2. Trailing Mechanism: The script doesn't just set a price and leave it. It "trails" the price. As new highs (in a long) or new lows (in a short) are formed, the script evaluates whether the protective boundary needs to move forward to lock in potential profits while still maintaining a buffer based on the current volatility.

Step-by-Step Behavior

For Long Positions (Buying):

  • Initial Setup: When a position is initiated, the script calculates an initial Stop Loss by subtracting a specific percentage of the current volatility from the opening price.
  • Dynamic Tracking: As price action progresses, the script looks at previous highs. If the market creates a new high that exceeds the previous "buffer" zone, the stop loss level moves up automatically. It ensures that the protection level stays above the most recent significant price action, effectively "locking in" gains as the trade moves in your favor.

For Short Positions (Selling):

  • Initial Setup: The script calculates the initial Stop Loss by adding a specific percentage of the volatility to the low price.
  • Dynamic Tracking: It monitors previous lows. If the market drops to a new low that breaks through the existing buffer, the stop loss level moves downward. This ensures that as the price drops (in your favor), your protection level follows it down, maintaining a consistent distance based on market movement.

Summary for the User

Essentially, this tool acts as an automated "trailing stop" assistant. It removes the guesswork of deciding when to move your stop loss manually. By linking the safety level to both the historical highs/lows and the current market volatility, it attempts to provide a mathematically balanced exit point that adapts in real-time to the speed and direction of the market.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
FX Sniper's Chandelier_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/


#property link      ""
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Blue
#property indicator_chart_window


//---- buffers
double Buffer1[];
double Buffer2[];
extern int ATR_Period = 10;
extern double Chandelier_Factor = 1.25;
extern int Entry_Bar = 1;
bool iSL = true;
extern bool LONG = true;
extern double Initial_SL_Factor = 0.75;
int i;
double lprice[],hprice[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);

   SetIndexBuffer(0,Buffer1);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,159);
   SetIndexBuffer(1,Buffer2);
   SetIndexLabel(0,"L Stop");
   SetIndexLabel(1,"S Stop");
   SetIndexBuffer(2,lprice);
   SetIndexBuffer(3,hprice);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
 for (i=Bars;i >=0;i--)
   {
   Buffer1[i] = EMPTY_VALUE;
   Buffer2[i] = EMPTY_VALUE;
 
   }

//----
   return(0);
  }
//====================================================================
int start()
  {
   int    counted_bars=IndicatorCounted();
 
   

if (LONG==true)
//=================================  LONG =============================
{
   if (iSL == true)
   {
   Buffer1[Entry_Bar]= Open[Entry_Bar] - Initial_SL_Factor * iATR(NULL,0,ATR_Period,Entry_Bar);
   iSL = false;
   }

   else
   {
      for( i=Entry_Bar-1;i>=0;i--)
      {
         if (High[i] <= High[i+1])
         Buffer1[i]= Buffer1[i+1];
         else
         {
         if (Buffer1[i+1] >= High[i] - Chandelier_Factor * iATR(NULL,0,ATR_Period,i+1))
            Buffer1[i] = Buffer1[i+1];
         else    
            Buffer1[i]= High[i] - Chandelier_Factor * iATR(NULL,0,ATR_Period,i+1);
         }
      }   
    }
      
     
   
}   
//=================== SHORT ==========================

else
      {
         if (iSL == true)
         {
            Buffer2[Entry_Bar]= Low[Entry_Bar] + Initial_SL_Factor * iATR(NULL,0,ATR_Period,Entry_Bar);
            iSL = false;
         }
         else
         {
            for( i=Entry_Bar-1;i>=0;i--)
            {
               if (Low[i] >= Low[i+1])
               Buffer2[i]= Buffer2[i+1];
               else
               {
                  if(Buffer2[i+1] <= Low[i] + Chandelier_Factor * iATR(NULL,0,ATR_Period,i+1))
                  Buffer2[i]=Buffer2[i+1];
                  else
                  Buffer2[i]= Low[i] + Chandelier_Factor * iATR(NULL,0,ATR_Period,i+1);
               }
            }
         }

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

Comments