EldersSafeZone_v1

Download script
Author: Cubesteak
EldersSafeZone_v1

The Elders Safe Zone indicator is designed to provide traders with a visual guide for identifying potential support and resistance levels based on recent price volatility. Rather than relying on simple fixed numbers, the logic dynamically calculates a "Safe Stop" level by analyzing how much the market has fluctuated over a specific period of time.

How the Logic Works

The script operates by monitoring two primary components: the momentum of the price (via an Exponential Moving Average) and the physical range of recent price action. Here is a breakdown of the internal process:

1. Trend Detection The indicator first looks at an Exponential Moving Average (EMA) to determine the current direction of the market. It compares the current average against previous values to see if the trend is moving upward or downward.

2. Volatility Measurement (The "Pen") Depending on which direction the trend is moving, the script scans back through a specific number of recent price candles (the "LookBack" period).

  • In an uptrend, it identifies every instance where the price dropped lower than the previous candle, measuring those downward movements.
  • In a downtrend, it identifies every instance where the price rose higher than the previous candle, measuring those upward spikes.

By totaling these movements and averaging them, the script calculates the "average reach" of the market's volatility.

3. Calculating the Safe Zone Once the average volatility is established, the indicator applies a multiplier (the "Stop Factor"). This allows it to project a safety buffer away from the current price.

  • If the trend is up, it calculates a level below the current price.
  • If the trend is down, it calculates a level above the current price.

4. Smoothing and Continuity To prevent the indicator line from jumping erratically during volatile moments, the script includes a safety check. It ensures that the new "Safe Stop" value does not move backward against the established trend logic. If a calculation would cause the line to move in an illogical direction relative to the previous candle's data, the script retains the previous value. This creates a smoother, more continuous line on your chart.

Summary for Traders

In plain terms, this indicator acts as a dynamic "floor" or "ceiling." It looks at how much the market usually "pulses" over a set period and draws a line representing where the price might find stability based on those movements. It helps traders visualize areas where price might pause or reverse by accounting for the intensity of recent market activity.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
1 Downloads
0 Favorites
EldersSafeZone_v1
//+------------------------------------------------------------------+
//|                                             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