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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Follow the Leader
  4. //  Author/Uploader: Kelly Griffiths 
  5. //  E-mail:          
  6. //  Date/Time Added: 2004-10-06 00:45:08
  7. //  Origin:          Kelly Griffiths (October 5, 2004)
  8. //  Keywords:        volume institution profit loss stopbars
  9. //  Level:           basic
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=386
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=386
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  This follows institutional investing by using volume as an indicator.
  17. //
  18. //------------------------------------------------------------------------------
  19. /*
  20. Follow The Leader.
  21. Kelly Griffiths (4Oct04)
  22. Large volume trades can have a quick impact on the price of a position up or 
  23. down (supply and demand).  Institutions are typically responsible for
  24. most large volume trades.  I developed this formula to track the trading 
  25. activity of institutional investors, so that a small investor can capitalize
  26. on thier research without doing the research.
  27. Some assumptions are made that are typical of institutional investors.  The
  28. first assumption is that institutional investors follow trading practices 
  29. that require them to sell at certain percentage gains or losses.  The next 
  30. assumption is that institutional investors will not hold on to a stock 
  31. for more than a given number of days in order to minimize their exposure.
  32. The final assumption is that institutional investors have done their
  33. homework and know when to buy, hold or sell.
  34. This formula identifies the days when institutional investors buy or sell
  35. (SinceLastHit).  It also records the price that was paid on that day 
  36. (CLast).  It then tracks the profit/loss that the institutional holders 
  37. have made since their purchase (ChLast).  Using some averages, I came up 
  38. with some settings to determine what the selling points will be 
  39. (SellHigh and SellLow) and how many days to hold the position (StopBars). 
  40. My goal is not to present the most optimal solution, although this is not bad
  41. as it stands.  My intent is to share the fundamental formula so that others
  42. can integrate it with their own trading systems.
  43. */
  44. // Settings
  45. SellHigh = 15; // Selling percentage for profit
  46. SellLow = -11; // Selling percentage for loss
  47. StopBars = 70; // Time window to hold position
  48. BackRef = 150; // Number of days to look back (identify peaks)
  49. MaxChLast = 2.8; // This ensures the profit is not already gone
  50. RSIMin = 40; // Minimum RSI for entry
  51. // Number of bars since the last volume spike
  52. SinceLastSpike = BarsSince(V>(MA(V,BackRef)+StDev(V,BackRef)));
  53. // Closing price since the last volume spike
  54. CLast = Ref(C,-SinceLastSpike);
  55. // Profit/loss percentage (multiplied by 100)
  56. ChLast = ((C-CLast)/CLast)*100;
  57. // Trading rules
  58. PositionScore = RSI();
  59. Buy = Cross(ChLast,0) AND (ChLast<MaxChLast) AND IIf(RSI()>RSIMin,1,0);
  60. Sell = Cross(ChLast,SellHigh) OR Cross(SellLow,ChLast);
  61. ApplyStop(stopTypeNBar,stopModeBars,StopBars);
  62. // Exploration 
  63. Filter = Buy OR Sell;
  64. AddColumn(IIf(Buy,66,83),"Signal",formatChar);
  65. AddColumn(SinceLastSpike,"Bars since last spike");
  66. AddColumn(ChLast,"Change % since last spike");
  67. AddColumn(RSI(),"Reletive strength");