Second-order Infinite impulse response filter.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:1k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    Second-order Infinite impulse response filter
  4. //  Author/Uploader: Tomasz Janeczko 
  5. //  E-mail:          tj@amibroker.com
  6. //  Date/Time Added: 2003-04-30 15:43:03
  7. //  Origin:          
  8. //  Keywords:        moving average functions
  9. //  Level:           semi-advanced
  10. //  Flags:           indicator,function
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=274
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=274
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  This code demonstrates new looping and user-definable functions.
  17. //
  18. //------------------------------------------------------------------------------
  19. // the following function is 2nd order smoother
  20. // Input is the data array
  21. // f0, f1, f2 are filter coefficients
  22. // you can try 0.2, 1.4, -0.6 
  23. function IIR2( input, f0, f1, f2 )
  24. {
  25.   result[ 0 ] = input[ 0 ];
  26.   result[ 1 ] = input[ 1 ]; 
  27.   for( i = 2; i < BarCount; i++ )
  28.   {
  29.     result[ i ] = f0 * input[ i ] + 
  30.     f1 * result[ i - 1 ] + 
  31.     f2 * result[ i - 2 ]; 
  32.   }
  33.   return result;
  34. }
  35. Plot( Close, "Price", colorBlack, styleCandle );
  36. Plot( IIR2( Close, 0.2, 1.4, -0.6 ), "function example", colorRed );