maison6579 發表於 12-11-8 00:21

SafeZone指標

本帖最後由 maison6579 於 12-11-8 00:22 編輯

看到Amibroker版有人貼上SafeZone指標,
上網找了easylanguage版本。
{ Barry Silberman's version of Alexander Elder's "SafeZone Stop" from book"Come Into My Trading Room",page 173.
For Tradestation 2000
Amendments: (1)John Lynch:code for variable lookback period based on prior swing extremes;
            (2)John Lynch:code to indicate stop for next period --- plotted on last bar on chart.
            (3)Gary Fritz:use of TS variable instead of arrays
            (4)Eric Svendsen:Coloured Stop and trend variable

Notes:
A) Set the chart up with one space to the right.Set plot2's chart style type to point and its color to
   your background color if your background is not black (5th line of each Set Plot section).
B) This is an adaptation of Dr. Elder's stop based on the followingpoints 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 turningpoint.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), AutomaticLookBack(True), Multiplelong(2), Multipleshort(2),
ColourShort(red), ColourLong(blue);

VARIABLES:
MA(0),Ldiff(0), Lday(0), Sdiff(0), Sday(0), Longsum(0),Shortsum(0) , Countlong(0), Countshort(0), Avglow(0),
Avghigh(0), Longstop(0), Shortstop(0), Lstop(0), Sstop(0), ii(0), LookBackTemp(0);

{Determine trend by slope of EMA}
MA = xaverage( Price, MALength );
Condition1 = MA > MA;
Condition2 = MA < MA;

{Determine Lookback Period (to prior swing extreme)}
IF LookBackTemp<LookBack THEN LookBackTemp=LookBackTemp+1;
IF Condition1<>Condition1 THEN BEGIN
LookBackTemp=LookBack;
Value1=MinList(MALength*0.66,LookBack);
IF Condition1 and AutomaticLookBack THEN IF LowestBar(L,Value1)<LookBack THEN LookBackTemp=LowestBar(L,Value1);
IF Condition2 and AutomaticLookBack THEN IF HighestBar(H,Value1)<LookBack THEN LookBackTemp=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 > L, L - L, 0);   { Difference of lows }
Lday= IFF(L > L, 1, 0);          { 1 if this is a "low's" day }
Sdiff = IFF(H < H, H - H, 0);   { Difference of highs }
Sday= IFF(H < 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, Lookbacktemp);                     
Countlong = summation(Lday, Lookbacktemp);
IF Countlong <> 0 THEN Avglow = Longsum / Countlong;

{Calculate stop at "X" times avglow}
Lstop = LOW - (Multiplelong * Avglow);   
            
{Prevent stop from being lowered}
Longstop = MAXLIST(Lstop, Lstop, Lstop, Lstop, Lstop, Lstop);

{Set Plot}
IF Condition1 THEN BEGIN
PLOT1(Longstop, "STOP", ColourLong);   
IF lastbaronchart THEN BEGIN
Plot1[-1](Longstop, "STOP", ColourLong);         {Shows tomorrows stop on lastbar+1}
Plot2(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, Lookbacktemp);
Countshort = summation(Sday, Lookbacktemp);
IF Countshort <> 0 THEN Avghigh = Shortsum / Countshort;

{Calculate stop at "X" times avghigh}
Sstop = HIGH + (Multipleshort * Avghigh);

{Prevent stop from rising}
Shortstop = MINLIST(Sstop, Sstop, Sstop, Sstop, Sstop, Sstop);

{Set Plot}
IF Condition2 THEN BEGIN
PLOT1(Shortstop, "STOP", ColourShort);   
IF lastbaronchart THEN BEGIN
Plot1[-1](Shortstop, "STOP", ColourShort);   {Shows tomorrows stop on lastbar+1}
Plot2(Shortstop, "StopNext", Black);         {Indicates tomorrows stop: set indicator to point/black}
END;
END;

moneymaker 發表於 12-11-8 06:29

謝謝分享{:4_196:}...{:4_661:}

coco1234 發表於 12-11-8 10:07

感謝分享
雖然不瞭解這個策略{:4_121:}

daniel 發表於 12-11-8 20:49

感謝板主的分享,能否再提示一下這指標的用法??

Soprano 發表於 12-11-21 19:51

太棒了,先收下來研究,感謝。

kikusui 發表於 12-11-22 10:19

感謝分享   趕緊來研究      

jazzex 發表於 13-1-21 00:35

感謝大大分享
快點來研究一下

jetterchen23 發表於 13-5-6 20:04

謝謝大大分享

先收下用看看   thx

glaxo 發表於 13-5-6 20:12

有誰知道怎麼使用嗎
很炫的樣子

jetterchen23 發表於 13-5-6 21:08

謝謝大大
先收下來試用看看

moshn1011 發表於 13-5-7 21:39

好神奇的感覺~~感謝分享
頁: [1]
查看完整版本: SafeZone指標