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

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    crMathLib
  4. //  Author/Uploader: Chuck Rademacher 
  5. //  E-mail:          chuck_rademacher@xtra.co.nz
  6. //  Date/Time Added: 2003-05-06 15:46:11
  7. //  Origin:          
  8. //  Keywords:        
  9. //  Level:           medium
  10. //  Flags:           system,exploration,indicator,function
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=278
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=278
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  A "work in progress" library of mathematical functions. This first posting
  17. //  is purely to get things going. More functions will be added regularly.
  18. //  Users may cut and paste functions into their own code. This version
  19. //  includes:
  20. //
  21. //  crLinearCorrelation (bars)
  22. //
  23. //  crRSquare (bars)
  24. //
  25. //------------------------------------------------------------------------------
  26. //  Linear Correlation
  27. function crLinearCorrelation (crLength) {
  28. crX            = BarIndex();
  29. crCloseMA      = MA(Close,crLength);
  30. crXMA          = MA(crX,crLength);
  31. crCloseSquared = Close*Close;
  32. crXSquared     = crX*crX;
  33. crUpEQ   = Sum(crX * Close, crLength) - (crLength * crXMA * crCloseMA);
  34. crLowEQ1 = Sum(crXSquared, crLength) - (crLength * crXMA * crXMA);
  35. crLowEQ2 = Sum(crCloseSquared, crLength) - (crLength * crCloseMA * crCloseMA);
  36. crLowEQT = sqrt(crLowEQ1 * crLowEQ2);
  37. return IIf(crLowEQT == 0, 0, crUpEQ / crLowEQT);
  38. }
  39. //  R-Squared
  40. function crRSquare (crLength) {
  41. crR = crLinearCorrelation(crLength);
  42. return crR*crR;
  43. }