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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    ADXbuy
  4. //  Author/Uploader: goldfreaz 
  5. //  E-mail:          goldfreaz@thelion.com
  6. //  Date/Time Added: 2002-04-21 21:12:36
  7. //  Origin:          System using ADX Buy on positive PDI momentum and sell when the momentum diminishes
  8. //  Keywords:        
  9. //  Level:           medium
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=185
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=185
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Buy: slope ADX > slope ADX threshold and
  17. //
  18. //  ADX > ADX threshold + ADX histeresis and
  19. //
  20. //  PDI > ADX + DI histeresis and
  21. //
  22. //  slope PDI - slope MDI > slope DI threshold and
  23. //
  24. //  PDI > ADX
  25. //
  26. //  Sell: {ADX > ADX threshold - ADX histeresis and
  27. //
  28. //  PDI < ADX - DI histeresis} or
  29. //
  30. //  MDI > PDI + DI histeresis
  31. //
  32. //  with optimization */
  33. //
  34. //------------------------------------------------------------------------------
  35. /*ADX system
  36. goldfreaz - 18 April 2002
  37. Buy:  slope ADX > slope ADX threshold and
  38.       ADX > ADX threshold + ADX histeresis and
  39.       PDI > ADX + DI histeresis and
  40.       slope PDI - slope MDI > slope DI threshold and
  41.       PDI > ADX
  42. Sell:  {ADX > ADX threshold - ADX histeresis and
  43.        PDI < ADX - DI histeresis} or
  44.        MDI > PDI + DI histeresis      
  45. with  optimization */ 
  46. // ADX and PDI/MDI have different smoothing constants
  47. // smoothing defined as a exponential daily average, not Wilder's nonsense
  48. Aperiod=11;
  49. Bperiod=13;
  50. ADXthreshold=18;
  51. dadxthr=0.5;
  52. slpadxD=18;
  53. slpadxthr=0.35;
  54. dPM=3.5;
  55. slppmD=3;
  56. slpPMthr=-0.65;
  57.   //Aperiod=Optimize("Aperiod",13,11,15,1);
  58.   //Bperiod=Optimize("Bperiod",14,13,17,1);
  59.   //ADXthreshold=Optimize("ADXthreshold",17,16,18,0.25);
  60.   //dadxthr=Optimize("dADXthr",0.25,0,1.5,0.25);
  61.   //slpadxD=Optimize("slpadxD",12,18,22,1);
  62.   //slpadxthr=Optimize("slpadxthr",0.35,0.2,0.5,0.05);
  63.   //dPM=Optimize("dPM",1,3.5,4,0.2);
  64.   //slppmD=Optimize("slppmD",3,2,4,1);
  65.   //slpPMthr=Optimize("slpPMthr",-0.65,-1,-0.5,0.05);
  66. Ppdi=PDI(Bperiod);
  67. Mmdi=MDI(Bperiod);
  68. dx=100*abs(Ppdi-Mmdi)/(Ppdi+Mmdi);
  69. Aadx=EMA(dx,Aperiod);
  70. slpadx=(Aadx-Ref(MA(Aadx,slpadxD),-1))/slpadxD;
  71. slpPM=(Ppdi-Ref(EMA(Ppdi,slppmD),-1)-Mmdi+Ref(EMA(Mmdi,slppmD),-1))/slppmD;
  72. Buy =slpadx>slpadxthr AND Aadx>ADXthreshold+dadxthr AND Ppdi>Mmdi+dPM AND slpPM>slpPMthr AND Ppdi>Aadx;
  73. Sell=(Aadx>ADXthreshold-dadxthr AND Ppdi<Aadx-dPM) OR Mmdi>Ppdi+dPM;
  74.   Filter=Buy OR Sell; 
  75.   Sell=ExRem(Sell,Buy); Buy=ExRem(Buy,Sell);
  76. AddColumn(Buy,"Buy");
  77. AddColumn(Sell,"sell");
  78. AddColumn(Aadx,"Aadx");
  79. AddColumn(slpPM,"slpPM");
  80. AddColumn(BuyPrice,"BuyPrice");
  81. AddColumn(SellPrice,"SellPrice");