EldersSafeZone_v2

Download script
Author: Cubesteak
EldersSafeZone_v2

The Elder's Safe Zone is a technical analysis tool designed to help traders identify potential support and resistance levels while filtering out market noise. Its primary goal is to project a dynamic "safe zone" or trailing boundary based on historical price volatility and trend direction.

How the Logic Works

The script operates by constantly analyzing two main components of the market: the current trend (momentum) and recent price fluctuations (volatility). Here is a breakdown of the logic used to determine the position of the line:

1. Trend Identification

The tool uses an Exponential Moving Average (EMA) to determine the general direction of the market.

  • Uptrend: When the current average is rising, the script looks for "safe" zones below the current price.
  • Downtrend: When the current average is falling, the script looks for "safe" zones above the current price.

2. Volatility Measurement

To calculate how far away these "safe zones" should be, the script performs a look-back analysis on recent price action. It identifies specific instances where the price moved significantly (highs or lows) over a set number of previous bars. By measuring these movements and averaging them, it establishes a baseline for how much the market is currently "swinging."

3. Dynamic Projection

Once the trend and volatility are established, the script calculates the Safe Stop level:

  • In an Uptrend, it takes the current closing price and subtracts a value based on the average volatility multiplied by a user-defined factor.
  • In a Downtrend, it takes the current closing price and adds a value based on that same volatility calculation.

4. Stability Filtering (The "Safe" Logic)

One of the most important features of this script is its "memory." To prevent the indicator line from jumping erratically during minor price flickers, it incorporates a stability check:

  • The script compares the newly calculated value with the previous one.
  • If the new calculation suggests a move that contradicts the established trend (e.g., the price starts dropping while the trend is still technically up), the script "holds" the previous level rather than jumping to the new one.
  • This ensures that the line remains smooth and only moves in a way that confirms the prevailing market structure.

Summary for the Trader

Essentially, this tool acts as a dynamic floor or ceiling. It looks at how much the market has been "shaking" lately and projects a line that represents a significant structural level. By following this line, traders can better visualize where a trend might be exhausted or where a safe entry/exit point might exist, providing a visual buffer between the current price and potential reversal zones.

6 Views
1 Downloads
0 Favorites
EldersSafeZone_v2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                             Elders Safe Zone.mq4 |
//|                                                        Cubesteak |
//|                                                www.cubesteak.net |
//+------------------------------------------------------------------+
#property copyright "Cubesteak"
#property link      "www.cubesteak.net"

#property  indicator_buffers 1
#property indicator_color1 Aquamarine

#property indicator_chart_window

extern int LookBack = 10;
extern int StopFactor = 3;
extern int EMALength = 13;
extern color LineColor = Aquamarine;

double ExtBuffer[]; 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
   SetIndexBuffer(0,ExtBuffer);
   SetIndexStyle(0,DRAW_LINE,2,1,LineColor);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double SafeStop=0;
   int    counted_bars=IndicatorCounted();
   int limit = Bars - LookBack - 3;
   
   for (int shift = limit;shift>=0;shift--)
   {
   
      double EMA0 = iMA(Symbol(),0,EMALength,0,MODE_EMA,0,shift);
      double EMA1 = iMA(Symbol(),0,EMALength,0,MODE_EMA,0,shift+1);
      double EMA2 = iMA(Symbol(),0,EMALength,0,MODE_EMA,0,shift+2);
      double PreSafeStop = ExtBuffer[shift+1];
      double Pen = 0;
      int Counter = 0;
   
      if (EMA0 > EMA1)
      {
         for (int value1 = 0;value1<=LookBack; value1++)
         {
            if (Low[shift+value1] < Low[shift+value1+1])
            {
               Pen = Low[shift+value1+1] - Low[shift+value1] + Pen;
               Counter = Counter + 1; 
            }
         }
         if (Counter != 0) SafeStop = Close[shift] - (StopFactor * (Pen/Counter));
         else SafeStop = Close[shift] - (StopFactor * Pen);
         if ((SafeStop < PreSafeStop) && (EMA1 > EMA2)) SafeStop = PreSafeStop;
      }

      if (EMA0 < EMA1)
      {
         for (value1 = 0;value1<=LookBack; value1++)
         {
            if (High[shift+value1] > High[shift+value1+1])
            {
               Pen = High[shift+value1] - High[shift+value1+1] + Pen;
               Counter = Counter + 1;
            }
         }
         if (Counter != 0) SafeStop = Close[shift] + (StopFactor * (Pen/Counter));
	      else SafeStop = Close[shift] + (StopFactor * Pen);
	      if ((SafeStop > PreSafeStop) && (EMA1 < EMA2)) SafeStop = PreSafeStop;
      }
      PreSafeStop = SafeStop;
   	ExtBuffer[shift] = SafeStop;
   }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments