PureBytes Links
Trading Reference Links
|
I am trying to write the Elder SafeZone stop from his book. I have
written a version below, but would like to make the lookback period
variable. Can someone help modify my code?
thanks
Elder SafeZone
1) If today's low is lower than yesterday measure downside
penetration otherwise 0
DnPen = IIf(Ref(L,-1)>L, Ref(L,-1)-L,0);
2) Choose lookback period and sum all downside penetrations during
that period. Would like to make this variable.
zSum = DnPen + Ref(DnPen,-1)+Ref(DnPen,-2)+Ref(DnPen,-3)+Ref(DnPen,-4)
+
Ref(DnPen,-5)+Ref(DnPen,-6)+Ref(DnPen,-7)+Ref(DnPen,-8)
+
Ref(DnPen,-9);
3) Mark each bar that penetrates below the previous bar.
PenYN =IIf(L <Ref(L,-1),1,0);
4) Count the number of downside penetrations during the lookback
period. Would like to be equal to lookback period defined in step 2.
DnNumb = PenYN + Ref(PenYN ,-1)+Ref(PenYN ,-2)+Ref(PenYN ,-3)+Ref
(PenYN ,-4)+
Ref(PenYN ,-5)+Ref(PenYN ,-6)+Ref(PenYN ,-7)+Ref
(PenYN ,-8)+
Ref(PenYN ,-9);
5)Find average downside penetration during lookback period.
DnAvg = zSum/DnNumb;
6)Place stop at multiple of yesterday's average downside penetration
below yesterday's low and subtract the result from yesterday's low to
obtain today's stop. (I think since I am using EOD - I should use
today's low and DnAvg?)
LongStop = L -2*DnAvg;
7)Refine formula to prevent from lowering stops in uptrends. If
formula tells us to lower stop, leave at previous day's level. Elder
programs the SafeZone in Excel in his book. For this step, he uses
MAX(J14:J16). He says that this will prevent the stop from declining
for 3 days, by which time the uptrend resumes or the stop is hit.
LMax = Max(LongStop, Ref(LongStop,-1));
LMax = Max(LMax, Ref(LongStop,-2));
Entire AFL
DnPen = IIf(Ref(L,-1)>L, Ref(L,-1)-L,0);
zSum = DnPen + Ref(DnPen,-1)+Ref(DnPen,-2)+Ref(DnPen,-3)+Ref(DnPen,-4)
+
Ref(DnPen,-5)+Ref(DnPen,-6)+Ref(DnPen,-7)+Ref(DnPen,-8)
+
Ref(DnPen,-9);
PenYN =IIf(L <Ref(L,-1),1,0);
DnNumb = PenYN + Ref(PenYN ,-1)+Ref(PenYN ,-2)+Ref(PenYN ,-3)+Ref
(PenYN ,-4)+
Ref(PenYN ,-5)+Ref(PenYN ,-6)+Ref(PenYN ,-7)+Ref
(PenYN ,-8)+
Ref(PenYN ,-9);
DnAvg = zSum/DnNumb;
LongStop = L -2*DnAvg;
LMax = Max(LongStop, Ref(LongStop,-1));
LMax = Max(LMax, Ref(LongStop,-2));
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/O10svD/Me7FAA/AG3JAA/GHeqlB/TM
---------------------------------------------------------------------~->
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
|