コード例 #1
0
ファイル: SwissArmyKnife.cs プロジェクト: w1r2p1/Core-2
        /// <summary>
        /// Swiss Army Knife indicator by John Ehlers
        /// </summary>
        /// <param name="name"></param>
        /// <param name="period"></param>
        /// <param name="delta"></param>
        /// <param name="tool"></param>
        public SwissArmyKnife(string name, int period, double delta, SwissArmyKnifeTool tool)
            : base(name)
        {
            _period = period;
            _tool   = tool;
            _delta  = delta;
            _filt   = new RollingWindow <double>(2)
            {
                0.0, 0.0
            };
            _price = new RollingWindow <double>(3);
            double alpha;
            double beta;
            double gamma;

            if (_tool == SwissArmyKnifeTool.Gauss)
            {
                beta  = 2.415 * (1 - Math.Cos(2 * Math.PI / _period));
                alpha = -beta + Math.Sqrt(Math.Pow(beta, 2) + 2d * beta);
                _c0   = alpha * alpha;
                _a1   = 2d * (1 - alpha);
                _a2   = -(1 - alpha) * (1 - alpha);
            }

            if (_tool == SwissArmyKnifeTool.Butter)
            {
                beta  = 2.415 * (1 - Math.Cos(2 * Math.PI / _period));
                alpha = -beta + Math.Sqrt(Math.Pow(beta, 2) + 2d * beta);
                _c0   = alpha * alpha / 4d;
                _b1   = 2;
                _b2   = 1;
                _a1   = 2d * (1 - alpha);
                _a2   = -(1 - alpha) * (1 - alpha);
            }

            if (_tool == SwissArmyKnifeTool.HighPass)
            {
                alpha = (Math.Cos(2 * Math.PI / _period) + Math.Sin(2 * Math.PI / _period) - 1) / Math.Cos(2 * Math.PI / _period);
                _c0   = (1 + alpha) / 2;
                _b1   = -1;
                _a1   = 1 - alpha;
            }

            if (_tool == SwissArmyKnifeTool.TwoPoleHighPass)
            {
                beta  = 2.415 * (1 - Math.Cos(2 * Math.PI / _period));
                alpha = -beta + Math.Sqrt(Math.Pow(beta, 2) + 2d * beta);
                _c0   = (1 + alpha) * (1 + alpha) / 4;
                _b1   = -2;
                _b2   = 1;
                _a1   = 2d * (1 - alpha);
                _a2   = -(1 - alpha) * (1 - alpha);
            }

            if (_tool == SwissArmyKnifeTool.BandPass)
            {
                beta  = Math.Cos(2 * Math.PI / _period);
                gamma = (1 / Math.Cos(4 * Math.PI * _delta / _period));
                alpha = gamma - Math.Sqrt(Math.Pow(gamma, 2) - 1);
                _c0   = (1 - alpha) / 2d;
                _b0   = 1;
                _b2   = -1;
                _a1   = -beta * (1 - alpha);
                _a2   = alpha;
            }
        }