請選擇 進入手機版 | 繼續訪問電腦版

COCO研究院

 找回密碼
 註冊
搜索
查看: 5537|回復: 10

[工具] SafeZone指標

[複製鏈接]
發表於 12-11-8 00:21 | 顯示全部樓層 |閱讀模式
本帖最後由 maison6579 於 12-11-8 00:22 編輯

看到Amibroker版有人貼上SafeZone指標,
上網找了easylanguage版本。
  1. [prettyprint]
  2. { Barry Silberman's version of Alexander Elder's "SafeZone Stop" from book  "Come Into My Trading Room",  page 173.
  3.   For Tradestation 2000
  4.   Amendments: (1)  John Lynch:  code for variable lookback period based on prior swing extremes;
  5.               (2)  John Lynch:  code to indicate stop for next period --- plotted on last bar on chart.
  6.               (3)  Gary Fritz:  use of TS variable instead of arrays
  7.               (4)  Eric Svendsen:  Coloured Stop and trend variable
  8.   
  9. Notes:  
  10. A) Set the chart up with one space to the right.  Set plot2's chart style type to point and its color to  
  11.      your background color if your background is not black (5th line of each Set Plot section).
  12. B) This is an adaptation of Dr. Elder's stop based on the following  points that he emphasizes in his book:   
  13. (1)  you may use the slope of a 22 day EMA to define the trend
  14. (2)  SafeZone is not a mechanical gadget to replace independent thought.
  15. (3)  Calculate the stops separately for uptrends and downtrends.
  16. (4)  The lookback period should not go back beyond the last important turning  point.  If the market has      
  17.      reversed from down to up two weeks ago, then the SafeZone for the current long trades should not      
  18.      look back more than 10 trading days.
  19. (5)  An important decision is choosing the coefficient for the SafeZone stop. He says a coefficient     
  20.      between 2 and 3 provides a margin of safety, but you must research it on your own market data.      
  21. (6)  You can add it to almost any trading system, including Triple Screen.
  22. (7)  The excel code that Dr. Elder used in his book kept the stop from declining for 3 days, by which   
  23.      time either the uptrend resumes or the stop is hit.   This code uses a period of 5. }
  24.   
  25.   
  26. INPUTS:
  27. Price((H+L)/2), MALength(22), Lookback(15), Trend(3), AutomaticLookBack(True), Multiplelong(2), Multipleshort(2),  
  28. ColourShort(red), ColourLong(blue);
  29.   
  30. VARIABLES:
  31. MA(0),  Ldiff(0), Lday(0), Sdiff(0), Sday(0), Longsum(0),  Shortsum(0) , Countlong(0), Countshort(0), Avglow(0),  
  32. Avghigh(0), Longstop(0), Shortstop(0), Lstop(0), Sstop(0), ii(0), LookBackTemp(0);
  33.   
  34. {Determine trend by slope of EMA}
  35. MA = xaverage( Price, MALength );
  36. Condition1 = MA > MA[Trend];
  37. Condition2 = MA < MA[Trend];
  38.   
  39. {Determine Lookback Period (to prior swing extreme)}
  40. IF LookBackTemp<LookBack THEN LookBackTemp=LookBackTemp+1;
  41. IF Condition1<>Condition1[1] THEN BEGIN  
  42. LookBackTemp=LookBack;
  43. Value1=MinList(MALength*0.66,LookBack);
  44. IF Condition1 and AutomaticLookBack THEN IF LowestBar(L,Value1)<LookBack THEN LookBackTemp=LowestBar(L,Value1);
  45. IF Condition2 and AutomaticLookBack THEN IF HighestBar(H,Value1)<LookBack THEN LookBackTemp=HighestBar(H,Value1);
  46. END;
  47.   
  48. {determine and count number of days with:
  49.   for longs -  lows being lower than prior lows
  50.   for shorts -  highs being higher than prior highs}
  51.   
  52. Ldiff = IFF(L[1] > L, L[1] - L, 0);   { Difference of lows }
  53. Lday  = IFF(L[1] > L, 1, 0);          { 1 if this is a "low's" day }
  54. Sdiff = IFF(H[1] < H, H - H[1], 0);   { Difference of highs }
  55. Sday  = IFF(H[1] < H, 1, 0);          { 1 if this is a "high's" day }
  56.   
  57. {SAFEZONE FOR LONGS}
  58. {Get average of lows lower than prior low}
  59. Longsum = summation(Ldiff, Lookbacktemp);                     
  60. Countlong = summation(Lday, Lookbacktemp);
  61. IF Countlong <> 0 THEN Avglow = Longsum / Countlong;
  62.   
  63. {Calculate stop at "X" times avglow}
  64. Lstop = LOW - (Multiplelong * Avglow);     
  65.             
  66. {Prevent stop from being lowered}
  67. Longstop = MAXLIST(Lstop, Lstop[1], Lstop[2], Lstop[3], Lstop[4], Lstop[5]);
  68.   
  69. {Set Plot}
  70. IF Condition1 THEN BEGIN
  71. PLOT1(Longstop[1], "STOP", ColourLong);   
  72. IF lastbaronchart THEN BEGIN
  73.   Plot1[-1](Longstop, "STOP", ColourLong);           {Shows tomorrows stop on lastbar+1}
  74.   Plot2(Longstop, "StopNext");                       {Indicates tomorrows stop: set indicator to point/black}
  75.   END;
  76. END;
  77.   
  78. {SAFEZONE FOR SHORTS}
  79. {Get average of highs higher than prior high}
  80. Shortsum = summation(Sdiff, Lookbacktemp);  
  81. Countshort = summation(Sday, Lookbacktemp);
  82. IF Countshort <> 0 THEN Avghigh = Shortsum / Countshort;
  83.   
  84. {Calculate stop at "X" times avghigh}
  85. Sstop = HIGH + (Multipleshort * Avghigh);  
  86.   
  87. {Prevent stop from rising}
  88. Shortstop = MINLIST(Sstop, Sstop[1], Sstop[2], Sstop[3], Sstop[4], Sstop[5]);  
  89.   
  90. {Set Plot}
  91. IF Condition2 THEN BEGIN
  92. PLOT1(Shortstop[1], "STOP", ColourShort);   
  93. IF lastbaronchart THEN BEGIN
  94.   Plot1[-1](Shortstop, "STOP", ColourShort);     {Shows tomorrows stop on lastbar+1}
  95.   Plot2(Shortstop, "StopNext", Black);           {Indicates tomorrows stop: set indicator to point/black}
  96.   END;
  97. END;
  98. [/prettyprint]
複製代碼

評分

參與人數 2金錢 +4 收起 理由
Timan + 2
Soprano + 2 按一個讚!

查看全部評分

發表於 12-11-8 06:29 | 顯示全部樓層
謝謝分享...
發表於 12-11-8 10:07 | 顯示全部樓層
感謝分享
雖然不瞭解這個策略
發表於 12-11-8 20:49 | 顯示全部樓層
感謝板主的分享,能否再提示一下  這指標的用法??
發表於 12-11-21 19:51 | 顯示全部樓層
太棒了,先收下來研究,感謝。
發表於 12-11-22 10:19 | 顯示全部樓層
感謝分享   趕緊來研究        
發表於 13-1-21 00:35 | 顯示全部樓層
感謝大大分享
快點來研究一下
發表於 13-5-6 20:04 | 顯示全部樓層
謝謝大大分享

  先收下用看看   thx
發表於 13-5-6 20:12 | 顯示全部樓層
有誰知道怎麼使用嗎
很炫的樣子
發表於 13-5-6 21:08 | 顯示全部樓層
謝謝大大  
先收下來試用看看
發表於 13-5-7 21:39 | 顯示全部樓層
好神奇的感覺~~感謝分享
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-4-18 20:10

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook