Elders_Safe_Zone Indicator For MT5
The Elders_Safe_Zone Indicator For MT5 is a trailing stop system. Alexander Elder introduced the indicator through his book, Come Into My Trading Room (2002). Elder designed the Safe Zone to remove the noise component of a price trend, and in the process, avoid having stops taken out by that noise. The indicator utilizes an Exponential Moving Average to define the trend. The directional movement is then calculated through a process that is similar to the Directional Movement System of Welles Wilder. A multiple of between 2 and 3 is applied to determine the trailing stop.
The Elders_Safe_Zone Indicator For MT5 gets overlaid as a Dodger Blue curve on price. It is primarily used to locate trade exit points within a trending market. Long positions should be exited when price dips beneath the Safe Zone stop. Contrarily, exit from short trades as and when price rises above the Safe Zone stop. Unlike some other stop and reverse systems, the Safe Zone does not signal market entries.
Installing the Elders_Safe_Zone Indicator For MT5
After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file Elders Safe Zone .mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.
Parameters of the Elders_Safe_Zone Indicator For MT5
The Elders_Safe_Zone Indicator For MT5 has 3 parameters to configure.
input int LookBack = 10; // LookBack
input int StopFactor = 3; // StopFactor
input int EMALength = 13; // EMALength
Buffers of the Elders_Safe_Zone Indicator For MT5
The Elders_Safe_Zone Indicator For MT5 provides 2 buffers.
SetIndexBuffer(0,ExtBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtMaBuffer,INDICATOR_CALCULATIONS);
Main Parts Of The Code
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- check for data
if(rates_total lt EMALength)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtMaHandle);
if(calculated lt rates_total)
{
Print("Not all data of ExtMaHandle is calculated (",calculated," bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated gt rates_total || prev_calculated lt 0)
to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated gt 0)
to_copy++;
}
//--- get MA buffer
if(IsStopped())
return(0); //Checking for stop flag
if(CopyBuffer(ExtMaHandle,0,0,to_copy,ExtMaBuffer) lt =0)
{
Print("Getting fast EMA is failed! Error",GetLastError());
return(0);
}
//---
int limit;
if(prev_calculated==0)
{
limit=LookBack+1;
ArrayInitialize(ExtBuffer,0.0);
}
else
limit=prev_calculated-1;
double SafeStop=0;
//--- calculate
for(int i=limit;i lt rates_total && !IsStopped();i++) // time[rates_total-1] - gt current time
{
double EMA0=ExtMaBuffer[i];
double EMA1=ExtMaBuffer[i-1];
double EMA2=ExtMaBuffer[i-2];
double PreSafeStop=ExtBuffer[i-1];
double Pen=0;
int Counter=0;
if(EMA0 gt EMA1)
{
for(int value1=0;value1 lt =LookBack; value1++)
{
if(low[i-value1] lt low[i-value1-1])
{
Pen=low[i-value1-1]-low[i-value1]+Pen;
Counter=Counter+1;
}
}
if(Counter!=0)
SafeStop=close[i]-((double)StopFactor*(Pen/(double)Counter));
else
SafeStop=close[i]-((double)StopFactor*Pen);
if((SafeStop lt PreSafeStop) && (EMA1 gt EMA2))
SafeStop=PreSafeStop;
}
if(EMA0 lt EMA1)
{
for(int value1=0;value1 lt =LookBack; value1++)
{
if(high[i-value1] gt high[i-value1-1])
{
Pen=high[i-value1]-high[i-value1-1]+Pen;
Counter=Counter+1;
}
}
if(Counter!=0)
SafeStop=close[i]+((double)StopFactor *(Pen/(double)Counter));
else
SafeStop=close[i]+((double)StopFactor*Pen);
if((SafeStop gt PreSafeStop) && (EMA1 lt EMA2))
SafeStop=PreSafeStop;
}
PreSafeStop=SafeStop;
ExtBuffer[i]=SafeStop;
}
////--- calculate Signal
// SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+