crmathlib.afl

来自「一个更精度的平滑涵数, 可用于股票交易系统.用于Amibroker 平台」· AFL 代码 · 共 50 行

AFL
50
字号
//------------------------------------------------------------------------------
//
//  Formula Name:    crMathLib
//  Author/Uploader: Chuck Rademacher 
//  E-mail:          chuck_rademacher@xtra.co.nz
//  Date/Time Added: 2003-05-06 15:46:11
//  Origin:          
//  Keywords:        
//  Level:           medium
//  Flags:           system,exploration,indicator,function
//  Formula URL:     http://www.amibroker.com/library/formula.php?id=278
//  Details URL:     http://www.amibroker.com/library/detail.php?id=278
//
//------------------------------------------------------------------------------
//
//  A "work in progress" library of mathematical functions. This first posting
//  is purely to get things going. More functions will be added regularly.
//  Users may cut and paste functions into their own code. This version
//  includes:
//
//  crLinearCorrelation (bars)
//
//  crRSquare (bars)
//
//------------------------------------------------------------------------------

//  Linear Correlation

function crLinearCorrelation (crLength) {

crX            = BarIndex();
crCloseMA      = MA(Close,crLength);
crXMA          = MA(crX,crLength);
crCloseSquared = Close*Close;
crXSquared     = crX*crX;

crUpEQ   = Sum(crX * Close, crLength) - (crLength * crXMA * crCloseMA);
crLowEQ1 = Sum(crXSquared, crLength) - (crLength * crXMA * crXMA);
crLowEQ2 = Sum(crCloseSquared, crLength) - (crLength * crCloseMA * crCloseMA);
crLowEQT = sqrt(crLowEQ1 * crLowEQ2);

return IIf(crLowEQT == 0, 0, crUpEQ / crLowEQT);
}

//  R-Squared

function crRSquare (crLength) {
crR = crLinearCorrelation(crLength);
return crR*crR;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?