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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Sector Tracking
  4. //  Author/Uploader: Ara Kaloustian 
  5. //  E-mail:          ara1@san.rr.com
  6. //  Date/Time Added: 2002-04-07 14:40:40
  7. //  Origin:          Written by Ara Kaloustian, 3/31/02
  8. //  Keywords:        Sectors
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=184
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=184
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  Tracks normalized relative performance of the most heavily traded sectors 4
  17. //  sectors (XLE, XLK, XLB, XLF).
  18. //
  19. //  Performance is tracked by comparing the daily performance of the sector to
  20. //  the daily performance of the S&P500, then a 13 day exp moving average
  21. //  and finally the sum of 9 days to smooth out the data.
  22. //
  23. //  CAUTION: You may need to edit the symbol for S&P 500 index if different
  24. //  for your data source than what I have used (SP-500).
  25. //
  26. //------------------------------------------------------------------------------
  27. // Look for relative strength of sectors wrt their S&P
  28. // Plot the 13 week EMA of incremental differences
  29. // This is useful for finding strengthening sectors / industries
  30. // Normalize data
  31. Title = "TC2k-Sector vs. S&P-500: Energy - Technology - Finance - Materials";
  32. Sum_Filter = 9;
  33. Index_Value = Foreign("SP-500","close");
  34. Energy_Ratio      = Foreign("XLE","Close",fixup=1) / Index_Value;
  35. Tech_Ratio        = Foreign("XLK","Close",fixup=1) / Index_Value;
  36. Finance_Ratio     = Foreign("XLF","Close",fixup=1) / Index_Value;
  37. Materials_Ratio   = Foreign("XLB","Close",fixup=1) / Index_Value;
  38. Energy_Perf       = EMA(Energy_Ratio      - Ref(Energy_Ratio,-1),13) * 10000;
  39. Tech_Perf         = EMA(Tech_Ratio        - Ref(Tech_Ratio,-1),13) * 10000;
  40. Finance_Perf      = EMA(Finance_Ratio     - Ref(Finance_Ratio,-1),13) * 10000;
  41. Materials_Perf    = EMA(Materials_Ratio   - Ref(Materials_Ratio,-1),13) * 10000;
  42. N_Energy_Perf    = (Energy_Perf)    / Foreign("XLE","Close",fixup=1);
  43. N_Tech_Perf      = (Tech_Perf)      / Foreign("XLK","Close",fixup=1);
  44. N_Finance_Perf   = (Finance_Perf)   / Foreign("XLF","Close",fixup=1);
  45. N_Materials_Perf = (Materials_Perf) / Foreign("XLB","Close",fixup=1);
  46. Energy_Sum        = Sum(N_Energy_Perf,Sum_Filter);
  47. Tech_Sum          = Sum(N_Tech_Perf,Sum_Filter);
  48. Finance_Sum       = Sum(N_Finance_Perf,Sum_Filter);
  49. Materials_Sum     = Sum(N_Materials_Perf,Sum_Filter);
  50. /*
  51. Backtest performance by selectig top sector to buy
  52. Buy when rel performance above 0 and slope maximum
  53. Sell when slope decreass relative to another sector
  54. Always be in the market
  55. */
  56. Filter = Close > 0;
  57. NumColumns = 4;
  58. Column0Name = "Energy";
  59. Column0     = Energy_Sum;
  60. Column1Name = "Tech";
  61. Column1     = Tech_Sum;
  62. Column2Name = "Finance";
  63. Column2     = Finance_Sum;
  64. Column3Name = "Materials";
  65. Column3     = MAterials_Sum;
  66. MaxGraph = 4;
  67. Graph0 = Energy_Sum;
  68. Graph0Color = 1;      //Black - Energy
  69. Graph1 = Tech_Sum;    
  70. Graph1Color = 2;      //White - Tech
  71. Graph2 = Finance_Sum;
  72. Graph2Color = 4;      //Red - Finance
  73. Graph3 = Materials_Sum;
  74. Graph3Color = 5;      //Green - Mater.
  75. Graph0Style = 4;
  76. Graph1Style = 4;
  77. Graph2Style = 4;
  78. Graph3Style = 4;