SafeZone – Read Elder’s “Come into my Trading Room” Page 173 onwards before using it.

The code below allows you to add a custom indicator called “SafeZone” to your advanced charts. You need to copy this code and paste it in as a new indicator. For help, please watch this video

——————————————————-

REM This is supposed to replicate the calculations needed for the SafeZone Stop
REM Read Elders Come into my Trading Room Page 173 onwards before using it.
REM It does NOT produce the Protected figure, my system lets you see what the alternatives are.

REM To add the variables and LBP use the Variable Optimisation and Add etc
REM Set s by inserting the following: s, Set own scaling factor,Float,>0,2
REM Set LBP by inserting the following: LBP,Look Back Period,Integer,>0,10
REM Otherwise edit the two lines below to s=2 and LBP=10.

REM The position of StopLossPlacement on the Price chart depends on the trend.
REM If in Uptrend then Stop Loss is below the price action and vice versa.

REM If Trend is flat then it is called an Uptrend by default and the Stop Loss will have been hit long ago

REM s=(s)
REM LBP=(LBP)
s=2
LBP=10

Uptrend=0
Downtrend=0

TrendTester= ExponentialAverage[22](close)
if TrendTester[0]>=TrendTester[LBP] then
Uptrend=1
else
Downtrend=1
endif

if Uptrend=1 then
if low[0]<low[1] then
DepthOfLow=low[1]-low[0]
CountAsDeeperLow=1
else
DepthOfLow=0
CountAsDeeperLow=0
endif

TotalDepth=summation[LBP](DepthOfLow)
TotalDeeperLows=summation[LBP](CountAsDeeperLow)
REM Add extra code to deal with situation unforseen by Elder
if TotalDeeperLows>=1 then
AverageDepthOfLows=TotalDepth/TotalDeeperLows
else
AverageDepthOfLows=AverageDepthOfLows[1]
endif
endif
if Downtrend= 1 then
if high[0]>high[1] then
HeightOfUpside=high[0]-high[1]
CountAsHigherHigh=1
else
HeightOfUpside=0
CountAsHigherHigh=0
endif

TotalHeight=summation[LBP](HeightOfUpside)
TotalHigherHighs=summation[LBP](CountAsHigherHigh)
REM Add extra code to deal with situation unforseen by Elder
if TotalHigherHighs>=1 then
AverageHeightOfHighs=TotalHeight/TotalHigherHighs
else
AverageHeightOfHighs=AverageHeightofHighs[1]
endif
endif

if Uptrend=1 then
StopLossPlacement=Low[1]-AverageDepthOfLows[1]*s
else
StopLossPlacement=High[1]+AverageHeightOfHighs[1]*s
endif

Return StopLossPlacement

———————————————