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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Trend Continuation Factor
  4. //  Author/Uploader: Dale butkowski 
  5. //  E-mail:          msc626@yahoo.com
  6. //  Date/Time Added: 2002-02-24 11:18:35
  7. //  Origin:          "Trend Continuation Factor", M.H.Pee March, 2002 TAS&C
  8. //  Keywords:        
  9. //  Level:           basic
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=163
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=163
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  System to identify trend and its direction.
  17. //
  18. //------------------------------------------------------------------------------
  19. /*Trend Continuation Factor
  20.   MArch 2000 TAS&C */
  21. EnableScript("jscript");
  22. Length=Optimize("Length",35,1,100,1);
  23. Change= Close-Ref(Close,-1);
  24. PlusChange=IIf(Change>0,Change,0);
  25. MinusChange=IIf(Change<0,-Change,0);
  26. <%
  27. PlusChange=VBArray(AFL("PlusChange")).toArray();
  28. MinusChange=
  29. VBArray(AFL("MinusChange")).toArray();
  30. /*Make two new arrays*/
  31. var PlusCF=new Array ();
  32. var MinusCF=new Array();
  33. /*fill array "PlusCF"*/
  34. for (i=0; i<PlusChange.length; i++ )
  35. {
  36.    if (PlusChange[i]==0) {
  37.    PlusCF[i]=0;
  38. }
  39. else {
  40.    PlusCF[i]=PlusChange[i]+PlusCF[i-1];
  41. }
  42. }
  43. /*Fill array "MinusCF*/
  44. for (i=0; i<MinusChange.length; i++ )
  45. {
  46.    if (MinusChange[i]==0) {
  47.    MinusCF[i]=0;
  48. }
  49. else {
  50.   MinusCF[i]=MinusChange[i]+MinusCF[i-1];
  51. }
  52. }
  53. /*Convert to AFL variables*/
  54. AFL("PlusCF")=PlusCF;
  55. AFL("MinusCF")=MinusCF;
  56. %>
  57. PlusTCF=
  58. Sum(PlusChange-MinusCF,Length);
  59. MinusTCF=
  60. Sum(MinusChange-PlusCF,Length);
  61. Buy=PlusTCF>0;
  62. Sell=MinusTCF>0;
  63. Short=Sell;
  64. Cover=Buy;
  65. /*This is optional*/
  66. ApplyStop(2,1,Optimize("Stop Loss",12,1,15,1),1);
  67. Buy=ExRem(Buy,Sell);
  68. Sell=ExRem(Sell,Buy);
  69. Cover=ExRem(Cover,Short);
  70. Short=ExRem(Short,Cover);