StockFetcher Forums · General Discussion · Stop Loss Formula<< 1 2 >>Post Follow-up
five40
23 posts
msg #59629
Ignore five40
2/11/2008 6:27:06 PM

Has anyone here used Dr Elders "SafeZone" in Stock Fetcher?

The formula gives an guide of where to set a stop loss to avoid market noise. It's based on average downside penetration over the last X days. He lays out the formula for building this in an excel spreadsheet in the book "Come into my Trading Room".

I have done this in excel and I really like the results.

On the AmiBroker site I found the formula below but I have not been able to convert it to Stock Fetcher. (lots of IF statements).

Trailing stop method
Formula:

_SECTION_BEGIN("Elder safe Zone Long + short");

L1=Ref(L,-1);
H1=Ref(H,-1);
Pd=Param("Period",10,1,50,1);
DnPen=IIf(L
UpPen=IIf(H>H1,H-H1,0);
DnPenSum=Sum(DnPen,Pd);
UpPenSum=Sum(UpPen,Pd);
DnPenCount=Sum(L
UpPenCount=Sum(H>H1,Pd);
AvgDnPen=IIf(DnPenCount>0,DnPenSum/DnPenCount,0.01);
AvgUpPen=IIf(UpPenCount>0,UpPenSum/UpPenCount,0.01);
AvgDnPenMult=Param("Multiplier",2,1,4,0.1);
AvgUpPenMult=Param("Multiplier",2,1,4,0.1);
DaysInTrade=Param("Days in trade",1,1,50,1);
StopLong=L-(AvgDnPen*AvgDnPenMult);
StopShort=H+(AvgUpPen*AvgUpPenMult);
SafeZoneStopLong=HHV(StopLong,DaysInTrade);
SafeZoneStopShort=LLV(StopShort,DaysInTrade);
MilieuCorps = (C+O)/2;
Plot( C, "Close", ParamColor("Couleur ", colorBlack ), styleNoTitle |
ParamStyle("Style") | styleCandle|styleThick);
ShortStop=BeginValue(C);
LongStop=BeginValue(C);
i=1;
for (i=1;i < BarCount; i++)
{
if (SafeZoneStopShort[i] >= SafeZoneStopShort[i-1] && ShortStop[i-1] <= H[i])
ShortStop[i] = SafeZoneStopShort[i] ;
if (SafeZoneStopShort[i] >= SafeZoneStopShort[i-1] && ShortStop[i-1] > H[i])
ShortStop[i] = ShortStop[i-1];
if (SafeZoneStopShort[i] < SafeZoneStopShort[i-1] && ShortStop[i-1] <= H[i])
ShortStop[i] = SafeZoneStopShort[i] ;
if (SafeZoneStopShort[i] < SafeZoneStopShort[i-1] && ShortStop[i-1] > H[i])
ShortStop[i] = ShortStop[i-1];
if (IsEmpty(SafeZoneStopShort[i]))
ShortStop[i] = SafeZoneStopShort[i] ;
if (ShortStop[i] >= SafeZoneStopShort[i])
ShortStop[i] = SafeZoneStopShort[i] ;

if (SafeZoneStopLong[i] <= SafeZoneStopLong[i-1] && LongStop[i-1] >= L[i])
LongStop[i] = SafeZoneStopLong[i] ;
if (SafeZoneStopLong[i] <= SafeZoneStopLong[i-1] && LongStop[i-1] < L[i])
LongStop[i] = LongStop[i-1];
if (SafeZoneStopLong[i] > SafeZoneStopLong[i-1] && LongStop[i-1] >= L[i])
LongStop[i] = SafeZoneStopLong[i] ;
if (SafeZoneStopLong[i] > SafeZoneStopLong[i-1] && LongStop[i-1] < L[i])
LongStop[i] = LongStop[i-1];
if (IsEmpty(SafeZoneStopLong[i]))
LongStop[i] = SafeZoneStopLong[i] ;
if (LongStop[i] <= SafeZoneStopLong[i])
LongStop[i] = SafeZoneStopLong[i] ;

}


PlotShapes(IIf(ShortStop>Ref(ShortStop,-1), shapeHollowSmallDownTriangle,
shapeNone), colorRed, 0, ShortStop, Offset=-15);
PlotShapes(IIf(LongStop
shapeNone), colorGreen, 0, LongStop, Offset=-15);
Plot(SafeZoneStopShort,"Safe Zone Short", ParamColor("Couleur Safe Zone Short",
colorRed ),ParamStyle("Style Safe Zone Short",styleDots|styleNoLine) );
Plot(SafeZoneStopLong,"Safe zone Long", ParamColor("Couleur Stop Long",
colorGreen ),ParamStyle("Safe zone Long",styleDots|styleNoLine) );
Plot(ShortStop,"Stop Short",
IIf(ShortStop>Ref(ShortStop,-1),colorCustom1,colorBlue),ParamStyle("Style Stop
Short",styleLine|styleLine) );
Plot(LongStop,"Stop Long",
IIf(LongStop
Long",styleLine|styleLine) );


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
Close %g (%.1f%%)n - Elder SafeZone long-Short pour trades aprčs le
"+Date()+"n {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Title= Title
+"nc56Periode: c56"
+WriteVal(Pd,1.0)
+"c56 - Multiplicateur Long : c56"
+WriteVal(AvgDnPenMult,1.1)
+"c56 - Multiplicateur Short : c56"
+WriteVal(AvgUpPenMult,1.1)
+"c56 - Jour en position(inclus): c56"
+WriteVal(DaysInTrade,1.0)
+"nc56Milieu corps : c56"
+WriteVal(MilieuCorps,1.2 )
+": c56 - N barre : "
+WriteVal(BarIndex(),1);
_SECTION_END();

BEVIL1
14 posts
msg #59638
Ignore BEVIL1
2/11/2008 11:33:10 PM

No I haven't but I'd be interested in the Excel spreadsheet. Would you be kind enough to share it?


five40
23 posts
msg #59652
Ignore five40
2/12/2008 6:52:50 PM

I'm not sure how to attach a file? Anyone?

nikoschopen
2,824 posts
msg #59653
Ignore nikoschopen
modified
2/12/2008 10:37:53 PM

SafeZone Stops - Long & Short:

Fetcher[
/*SafeZone Stops - Uptrend*/

set{Diff1, low 1 day ago - low}
set{Pen1, count(sign(Diff1) equals 1,1)}
set{DnPen, Pen1 * Diff1}
set{DnSum, sum(DnPen,10)}
set{DnNumb, sum(Pen1,10)}
set{DnAvg, DnSum / DnNumb}
set{DnMult, DnAvg * 2}
set{Short_Stop, low 1 day ago - DnMult}
set{Uptrend, max(Short_Stop, Short_Stop 2 days ago)}

/*SafeZone Stops - Downtrend*/

set{Diff2, high - high 1 day ago}
set{Pen2, count(sign(Diff2) equals 1,1)}
set{UpPen, Pen2 * Diff2}
set{UpSum, sum(UpPen,10)}
set{UpNumb, sum(Pen2,10)}
set{UpAvg, UpSum / UpNumb}
set{UpMult, UpAvg * 2}
set{Long_Stop, High + UpMult}
set{Downtrend, min(Long_Stop, Long_Stop 2 days ago)}

draw Uptrend on plot close
draw Downtrend on plot close

add column separator
add column DnPen
add column DnSum
add column Pen1{Pen Y/N}
add column DnNumb
add column DnAvg
add column Short_Stop
add column separator
add column Uptrend{Protected}
add column separator
add column UpPen
add column UpSum
add column Pen2{Pen Y/N}
add column UpNumb
add column UpAvg
add column Long_Stop
add column separator
add column Downtrend{Protected}
add column separator
]




chetron
2,817 posts
msg #59659
Ignore chetron
2/13/2008 12:03:55 PM

FOR THE STANDARD FOLKS....

PUT ON YOUR THINKING CAPS.

Fetcher[

/*SafeZone Stops - Uptrend*/

set{Diff1, low 1 day ago - low}
set{Pen1, count(sign(Diff1) equals 1,1)}
set{DnPen, Pen1 * Diff1}
set{DnSum, sum(DnPen,10)}
set{DnNumb, sum(Pen1,10)}
set{DnAvg, DnSum / DnNumb}
set{DnMult, DnAvg * 2}
set{Short_Stop, low 1 day ago - DnMult}
SET{VAR3,SHORT_STOP 2 DAY AGO}
/*
set{Uptrend, max(Short_Stop,Short_Stop 2 day ago)}
*/
/*SafeZone Stops - Downtrend*/

set{Diff2, high - high 1 day ago}
set{Pen2, count(sign(Diff2) equals 1,1)}
set{UpPen, Pen2 * Diff2}
set{UpSum, sum(UpPen,10)}
set{UpNumb, sum(Pen2,10)}
set{UpAvg, UpSum / UpNumb}
set{UpMult, UpAvg * 2}
set{Long_Stop, High + UpMult}
SET{VAR4,LONG_STOP 2 DAY AGO}

/*
set{Downtrend, min(Long_Stop, Long_Stop 2 days ago)}
*/

add column separator
add column DnPen
add column DnSum
add column Pen1{Pen Y/N}
add column DnNumb
add column DnAvg
add column Short_Stop
ADD COLUMN VAR3
add column separator
add column UpPen
add column UpSum
add column Pen2{Pen Y/N}
add column UpNumb
add column UpAvg
add column Long_Stop
add column VAR4
add column separator

]



nikoschopen
2,824 posts
msg #59660
Ignore nikoschopen
modified
2/13/2008 12:59:29 PM

Chetron,

The two formulas

set{Uptrend, max(Short_Stop,Short_Stop 2 day ago)}
and
set{Downtrend, min(Long_Stop, Long_Stop 2 days ago)}

are the "SafeZone" as defined by Alexander Elder in his book Come Into My Trading Room. If you leave the most fundamental matter out of the equation, it ain't what it supposed to be. Or is it?



chetron
2,817 posts
msg #59663
Ignore chetron
modified
2/13/2008 2:01:29 PM

hi niko,
how i understood your code was that the up and down trend value is low / highest of 2 values. so i added the variables and columns, var3 and var4 so you could eyeball the min max value, SHORT_STOP V. VAR3 AND LONG_STOP V. VAR4, and you would be able to figure out what the uptrend / downtrend values were, hoping that would still be useful.





five40
23 posts
msg #59724
Ignore five40
2/16/2008 12:49:47 PM

Niko and Chetron-

Thank you very much for working this out!

Unfortunately, I can't see it without upgrading. I get this error:
"Your StockFetcher filter exceeds filter performance restrictions."

Niko- can you tell me, does your filter plot the safezone onto the cart?

nikoschopen
2,824 posts
msg #59725
Ignore nikoschopen
modified
2/16/2008 3:32:03 PM

What you see is what you get and I do suggest that you upgrade to the Advanced subscription.



five40
23 posts
msg #59832
Ignore five40
2/20/2008 9:21:45 PM

Niko-

I upgraded. Good tip, well worth it.

NOTE: I made a change to your filter, I changed UPTREND to this:

set{Uptrend, max(Short_Stop, Short_Stop 2 days ago, Short_Stop 1 days ago)}

It now matches my spreadsheet and the book.

Question- How do I change the color of the uptrend plot line in SF 2.0?



StockFetcher Forums · General Discussion · Stop Loss Formula<< 1 2 >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2016 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus