TD sequential.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:3k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    TD sequential
  4. //  Author/Uploader: s.carrasset 
  5. //  E-mail:          s.carrasset@laposte.net
  6. //  Date/Time Added: 2004-11-02 04:57:37
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           basic
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=396
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=396
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Td sequential
  17. //
  18. //------------------------------------------------------------------------------
  19. Title= " Td seq I";
  20. /*TD seq long et short side full version*/
  21. /********Optimize***********/
  22. Opt1=Param("Opt1",9,5,21,1);
  23. Opt2=Param("Opt2",13,1,21,1);
  24. /*********Setup Buy*********/
  25. TD1=IIf(Close<Ref(Close,-4),1,0); 
  26. TD2=IIf(BarsSince(BarsSince(TD1))==Opt1, 1,0); //Sum(TD1,9)==9;
  27. TD3= Ref(H,-1)>=Ref(LLV(L,Opt1-4),-3);
  28. TD4= Ref(C,-Opt1)>=Ref(C,-Opt2);
  29. SetupBuy= TD3 AND TD2 AND TD4;
  30. /***********SetupSell************/
  31. TD1=IIf(Close>Ref(Close,-4),1,0); 
  32. TD2=IIf(BarsSince(BarsSince(TD1))==Opt1, 1,0); 
  33. TD3= Ref(L,-1)<=Ref(HHV(H,Opt1-4),-3);
  34. TD4= Ref(C,-Opt1)<=Ref(C,-Opt2);
  35. SetupSell= TD3 AND TD2 AND TD4 ;
  36. /*********Count Buy ********/
  37. CountBuy= Sum(IIf(C<Ref(C,-2),1,0),BarsSince(SetupBuy));
  38. //or C<Ref(H,-2)
  39. /*********Count Sell ********/
  40. CountSell= Sum(IIf(C>Ref(C,-2),1,0),BarsSince(SetupSell));
  41. //or C>Ref(L,-2)
  42. /***********A***********/
  43. B1= CountBuy >=Opt2; 
  44. B1= Hold(B1==0,2) AND B1;
  45. Timing=(BarsSince(SetUpbuy)< BarsSince(SetUpsell));
  46. Ccount=IIf(CountBuy >=Opt2,ValueWhen(B1,HHV(C,BarsSince(SetupBuy))),Null);
  47. Hsetup=IIf(CountBuy >=Opt2,ValueWhen(SetupBuy,HHV(H,Opt1)),Null);
  48. BuyA=B1 AND Timing AND Hsetup > Ccount;
  49. /******B**********/
  50. B2= CountBuy >Opt2 AND Close > Ref(Close,-4);
  51. B2=Hold(B2==0,2) AND B2;
  52. B2=ExRem(B2,B1);
  53. BuyB=B2  AND Timing  AND Hsetup > Ccount;
  54. /*************C***********/
  55. B3= CountBuy >Opt2 AND Close > Ref(High,-2);
  56. B3= Hold(B3==0,2) AND B3;
  57. B3=ExRem(B3,B1);
  58. BuyC= B3  AND Timing  AND Hsetup > Ccount;
  59. /************Buy Signal********/
  60. Buy=BuyB OR BuyC  ;
  61. ////////////////////////////////
  62. //SHORT
  63. /////////////////////////////////
  64. /***********A***********/
  65. S1= CountSell >=Opt2; 
  66. S1= Hold(S1==0,2) AND S1;
  67. Timing=(BarsSince(SetUpSell)< BarsSince(SetUpbuy));
  68. Ccount=IIf(CountSell >=Opt2,ValueWhen(S1,LLV(C,BarsSince(SetupSell))),Null);
  69. Lsetup=IIf(CountSell >=Opt2,ValueWhen(SetupSell,LLV(L,Opt1)),Null);
  70. SellA=S1 AND Timing AND Lsetup < Ccount;
  71. /******B**********/
  72. S2= CountSell >Opt2 AND Close < Ref(Close,-4);
  73. S2=Hold(S2==0,2) AND S2;
  74. S2=ExRem(S2,S1);
  75. SellB=S2  AND Timing  AND Lsetup < Ccount;
  76. /*************C***********/
  77. S3= CountSell >Opt2 AND Close < Ref(Low,-2);
  78. S3= Hold(S3==0,2) AND S3;
  79. S3=ExRem(S3,S1);
  80. SellC= S3  AND Timing  AND Lsetup < Ccount;
  81. /***********Short Signal********/
  82. Short= SellB OR SellC  ;
  83. Plot(C,"",IIf(Short,colorYellow,IIf(Buy,colorGreen,1)),64);
  84. PlotShapes(IIf(Short,
  85. shapeDownArrow,shapeNone),colorYellow,0,H,-10); 
  86. PlotShapes(IIf(Buy,
  87. shapeUpArrow,shapeNone),colorGreen,0,L,-10);
  88. PlotShapes(IIf(SetupSell,
  89. shapeDigit9,shapeNone),colorRed,0,H,20);  
  90. PlotShapes(IIf(SetupBuy,
  91. shapeDigit9,shapeNone),colorBlue,0,L,-20);