ehlers center of gravity oscillator.afl

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

AFL
57
字号
//------------------------------------------------------------------------------
//
//  Formula Name:    Ehlers Center of Gravity Oscillator
//  Author/Uploader: Not Too Swift 
//  E-mail:          
//  Date/Time Added: 2005-06-25 01:14:08
//  Origin:          
//  Keywords:        
//  Level:           medium
//  Flags:           indicator
//  Formula URL:     http://www.amibroker.com/library/formula.php?id=484
//  Details URL:     http://www.amibroker.com/library/detail.php?id=484
//
//------------------------------------------------------------------------------
//
//  Ehlers Center of Gravity Oscillator is from Cybernetic Analysis for Stocks
//  and Futures. Wiley. 2004.
//
//  This indicator represents the center of gravity of prices over the window
//  of observation.
//
//------------------------------------------------------------------------------

SetBarsRequired(200, 0);

// Ehlers formulas
// from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley. 2004. 
// Chapter 5, p. 47. Code on p. 49.

function CGOscillator(array, length)
// Figure 5.1 on p. 49.
{
  CGOValue = array;

  for(i = length; i < BarCount; i++)
  {
    num = 0;
    denom = 0;
    for(j = 0; j < length; j++)
    {
      num = num + (1 + j) * array[i - j];
      denom = denom + array[i - j];
    }
    if (denom != 0) CGOValue[i] = -num / denom + (length +1)/2;
  }
  return CGOValue;
}

med = (H + L) / 2;
Period = Param("Period", 10, 1, 250, 1);

Plot(CGOscillator(med, Period), "CG Oscillator", colorRed, styleLine);
Plot(Ref(CGOscillator(med, Period), -1), "Trigger", colorBlue, styleLine);
PlotGrid(.8);
PlotGrid(.5);
PlotGrid(.2);

⌨️ 快捷键说明

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