Elder safe Zone Long + short.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Elder safe Zone Long + short
  4. //  Author/Uploader: Boodha 
  5. //  E-mail:          boodha@focale.us
  6. //  Date/Time Added: 2005-10-16 19:35:37
  7. //  Origin:          A. ELDER
  8. //  Keywords:        Trailing stop
  9. //  Level:           semi-advanced
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=569
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=569
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Trailing stop m閠hod
  17. //
  18. //------------------------------------------------------------------------------
  19. _SECTION_BEGIN("Elder safe Zone Long + short");
  20. L1=Ref(L,-1);
  21. H1=Ref(H,-1);
  22. Pd=Param("Period",10,1,50,1);
  23. DnPen=IIf(L<L1,L1-L,0);
  24. UpPen=IIf(H>H1,H-H1,0);
  25. DnPenSum=Sum(DnPen,Pd);
  26. UpPenSum=Sum(UpPen,Pd);
  27. DnPenCount=Sum(L<L1,Pd);
  28. UpPenCount=Sum(H>H1,Pd);
  29. AvgDnPen=IIf(DnPenCount>0,DnPenSum/DnPenCount,0.01);
  30. AvgUpPen=IIf(UpPenCount>0,UpPenSum/UpPenCount,0.01);
  31. AvgDnPenMult=Param("Multiplier",2,1,4,0.1);
  32. AvgUpPenMult=Param("Multiplier",2,1,4,0.1);
  33. DaysInTrade=Param("Days in trade",1,1,50,1);
  34. StopLong=L-(AvgDnPen*AvgDnPenMult);
  35. StopShort=H+(AvgUpPen*AvgUpPenMult);
  36. SafeZoneStopLong=HHV(StopLong,DaysInTrade);
  37. SafeZoneStopShort=LLV(StopShort,DaysInTrade);
  38. MilieuCorps = (C+O)/2;
  39. Plot( C, "Close", ParamColor("Couleur ", colorBlack ), styleNoTitle | ParamStyle("Style") | styleCandle|styleThick);
  40. ShortStop=BeginValue(C);
  41. LongStop=BeginValue(C);
  42. i=1;
  43. for (i=1;i < BarCount; i++)
  44. {
  45. if (SafeZoneStopShort[i] >= SafeZoneStopShort[i-1] && ShortStop[i-1] <= H[i])
  46. ShortStop[i] = SafeZoneStopShort[i] ;
  47. if (SafeZoneStopShort[i] >= SafeZoneStopShort[i-1] && ShortStop[i-1] > H[i])
  48. ShortStop[i] = ShortStop[i-1];
  49. if (SafeZoneStopShort[i] < SafeZoneStopShort[i-1] && ShortStop[i-1] <= H[i])
  50. ShortStop[i] = SafeZoneStopShort[i] ;
  51. if (SafeZoneStopShort[i] < SafeZoneStopShort[i-1] && ShortStop[i-1] > H[i])
  52. ShortStop[i] = ShortStop[i-1];
  53. if (IsEmpty(SafeZoneStopShort[i]))
  54. ShortStop[i] = SafeZoneStopShort[i] ;
  55. if (ShortStop[i] >= SafeZoneStopShort[i])
  56.   ShortStop[i] = SafeZoneStopShort[i] ;
  57. if (SafeZoneStopLong[i] <= SafeZoneStopLong[i-1] && LongStop[i-1] >= L[i])
  58. LongStop[i] = SafeZoneStopLong[i] ;
  59. if (SafeZoneStopLong[i] <= SafeZoneStopLong[i-1] && LongStop[i-1] < L[i])
  60. LongStop[i] = LongStop[i-1];
  61. if (SafeZoneStopLong[i] > SafeZoneStopLong[i-1] && LongStop[i-1] >= L[i])
  62. LongStop[i] = SafeZoneStopLong[i] ;
  63. if (SafeZoneStopLong[i] > SafeZoneStopLong[i-1] && LongStop[i-1] < L[i])
  64. LongStop[i] = LongStop[i-1];
  65. if (IsEmpty(SafeZoneStopLong[i]))
  66. LongStop[i] = SafeZoneStopLong[i] ;
  67. if (LongStop[i] <= SafeZoneStopLong[i])
  68.   LongStop[i] = SafeZoneStopLong[i] ;
  69. }
  70. PlotShapes(IIf(ShortStop>Ref(ShortStop,-1), shapeHollowSmallDownTriangle, shapeNone), colorRed, 0, ShortStop, Offset=-15);
  71. PlotShapes(IIf(LongStop<Ref(LongStop,-1), shapeHollowSmallUpTriangle, shapeNone), colorGreen, 0,  LongStop, Offset=-15);
  72. Plot(SafeZoneStopShort,"Safe Zone Short", ParamColor("Couleur Safe Zone Short", colorRed ),ParamStyle("Style Safe Zone Short",styleDots|styleNoLine) );
  73. Plot(SafeZoneStopLong,"Safe zone Long", ParamColor("Couleur Stop Long", colorGreen ),ParamStyle("Safe zone Long",styleDots|styleNoLine) );
  74. Plot(ShortStop,"Stop Short", IIf(ShortStop>Ref(ShortStop,-1),colorCustom1,colorBlue),ParamStyle("Style Stop Short",styleLine|styleLine) );
  75. Plot(LongStop,"Stop Long", IIf(LongStop<Ref(LongStop,-1),colorCustom1,colorRed),ParamStyle("Style Stop Long",styleLine|styleLine) );
  76. _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%)n - Elder SafeZone long-Short pour trades apr鑣 le "+Date()+"n {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
  77. Title= Title
  78. +"n\c56Periode: \c56"
  79. +WriteVal(Pd,1.0)
  80. +"\c56 - Multiplicateur Long : \c56"
  81. +WriteVal(AvgDnPenMult,1.1)
  82. +"\c56 - Multiplicateur Short : \c56"
  83. +WriteVal(AvgUpPenMult,1.1)
  84. +"\c56 - Jour en position(inclus): \c56"
  85. +WriteVal(DaysInTrade,1.0) 
  86. +"n\c56Milieu corps : \c56"
  87. +WriteVal(MilieuCorps,1.2 )
  88. +": \c56 - N