This is an adaptation of Dr. Elder's stop based on the following points

that he emphasizes in his book:

(1) you may use the slope of a 22 day EMA to define the trend

(2) SafeZone is not a mechanical gadget to replace independent thought.

(3) Calculate the stops separately for uptrends and downtrends.

(4) The lookback period should not go back beyond the last important

turning point. If the market has

reversed from down to up two weeks ago, then the SafeZone for the

current long trades should not

look back more than 10 trading days.

(5) An important decision is choosing the coefficient for the SafeZone

stop. He says a coefficient

between 2 and 3 provides a margin of safety, but you must research it

on your own market data.

(6) You can add it to almost any trading system, including Triple Screen.

(7) The excel code that Dr. Elder used in his book kept the stop from

declining for 3 days, by which

time either the uptrend resumes or the stop is hit. This code uses a

period of 5. }

INPUTS:

Price((H+L)/2), MALength(22), Lookback(15), Trend(3), AutoLBck(True),

MultLong(2), MulShort(2);

VARIABLES:

MA(0), Ldiff(0), Lday(0), Sdiff(0), Sday(0), Longsum(0), Shortsum(0) ,

Countlng(0), Countshr(0), Avglow(0),

Avghigh(0), Longstop(0), Shortstp(0), Lstop(0), Sstop(0), ii(0),

LBackTmp(0);

{Determine trend by slope of EMA}

MA = xaverage( Price, MALength );

Condition1 = MA > MA[Trend];

Condition2 = MA < MA[Trend];

{Determine Lookback Period (to prior swing extreme)}

IF LBackTmp<LookBack THEN LBackTmp=LBackTmp+1;

IF Condition1<>Condition1[1] THEN BEGIN

LBackTmp=LookBack;

Value1=MinList(MALength*0.66,LookBack);

IF Condition1 and AutoLBck THEN IF LowestBar(L,Value1)<LookBack THEN

LBackTmp=LowestBar(L,Value1);

IF Condition2 and AutoLBck THEN IF HighestBar(H,Value1)<LookBack THEN

LBackTmp=HighestBar(H,Value1);

END;

{determine and count number of days with:

for longs - lows being lower than prior lows

for shorts - highs being higher than prior highs}

Ldiff = IFF(L[1] > L, L[1] - L, 0); { Difference of lows }

Lday = IFF(L[1] > L, 1, 0); { 1 if this is a "low's" day }

Sdiff = IFF(H[1] < H, H - H[1], 0); { Difference of highs }

Sday = IFF(H[1] < H, 1, 0); { 1 if this is a "high's" day }

{SAFEZONE FOR LONGS}

{Get average of lows lower than prior low}

Longsum = summation(Ldiff, LBackTmp);

Countlng = summation(Lday, LBackTmp);

IF Countlng <> 0 THEN Avglow = Longsum / Countlng;

{Calculate stop at "X" times avglow}

Lstop = LOW - (MultLong * Avglow);

{Prevent stop from being lowered}

Longstop = MAXLIST(Lstop, Lstop[1], Lstop[2], Lstop[3], Lstop[4], Lstop[5]);

{Set Plot}

IF Condition1 THEN BEGIN

PLOT1(Longstop[1], "LSTOP");

IF lastbaronchart THEN BEGIN

Plot1[-1](Longstop, "LSTOP"); {Shows tomorrows stop

on lastbar+1}

Plot3(Longstop, "StopNext"); {Indicates tomorrows

stop: set indicator to point/black}

END;

END;

{SAFEZONE FOR SHORTS}

{Get average of highs higher than prior high}

Shortsum = summation(Sdiff, LBackTmp);

Countshr = summation(Sday, LBackTmp);

IF Countshr <> 0 THEN Avghigh = Shortsum / Countshr;

{Calculate stop at "X" times avghigh}

Sstop = HIGH + (MulShort * Avghigh);

{Prevent stop from rising}

Shortstp = MINLIST(Sstop, Sstop[1], Sstop[2], Sstop[3], Sstop[4], Sstop[5]);

{Set Plot}

IF Condition2 THEN BEGIN

PLOT2(Shortstp[1], "SSTOP");

IF lastbaronchart THEN BEGIN

Plot2[-1](Shortstp, "SSTOP"); {Shows tomorrows stop on lastbar+1}

Plot3(Shortstp, "StopNext"); {Indicates tomorrows stop: set

indicator to point/black}

END;

END;

"Final" Alexander Elder's "SafeZone Stop" for Tradestation 4