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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Ehlers Instantaneous Trend
  4. //  Author/Uploader: Not Too Swift 
  5. //  E-mail:          
  6. //  Date/Time Added: 2005-03-20 00:25:13
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           medium
  10. //  Flags:           indicator
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=444
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=444
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  This is a zero lag trend indicator with an interesting predictive trigger.
  17. //
  18. //------------------------------------------------------------------------------
  19. SetBarsRequired(200, 0);
  20. // Ehlers ITrend
  21. // from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. 
  22. // Chapter 3, p. 21. Code on p. 24.
  23. function ITrend(array, alpha)
  24. {
  25.   // initialize early array values and declare as array
  26.   it = array;
  27.   //it = (array[2] - 2*array[1] + array[0])/4; This initialization takes a long time to converge.
  28.   for(i = 2; i < BarCount; i++)
  29.   {
  30.     it[i] = (alpha - alpha*alpha/4)*array[i] + 
  31.          .5*alpha*alpha*array[i-1] -
  32.          (alpha - .75*alpha*alpha)*array[i-2] +
  33.          2*(1 - alpha)*it[i-1] -
  34.          (1 - alpha)*(1 - alpha)*it[i-2];
  35.   }
  36.   return it;
  37. }
  38. function ITrendTrigger(array)
  39. {
  40.   trigger = 2*array - Ref(array, -2);
  41.   return trigger;
  42. }
  43. Med = (H+L)/2;
  44. // Instantaneous Trend
  45. Plot(Med, "", colorBlack, styleLine);
  46. trend = ITrend(Med, .07);
  47. Plot(trend, "ITrend", colorBlue, styleLine);
  48. Plot(ITrendTrigger(trend), "", colorRed, styleLine);