protected override ISignal CreateIndicator(Symbol pair, int i, string entryOrExit)
        {
            var key          = entryOrExit + "Indicator" + i + "Direction";
            var intDirection = GetConfigValue(key);

            var direction = intDirection == 0 || intDirection == 1 ? Direction.LongOnly : Direction.ShortOnly;

            key = entryOrExit + "Indicator" + i;

            var     indicator = (TechnicalIndicator)GetConfigValue(key);
            ISignal signal    = null;

            switch (indicator)
            {
            case TechnicalIndicator.SimpleMovingAverage:
                var fast = _algorithm.SMA(pair, _ignorePeriod ? 50 : _period, _resolution);
                var slow = _algorithm.SMA(pair, _ignorePeriod ? 200 : _period, _resolution);
                signal = new CrossingMovingAverageSignal(fast, slow, direction);
                break;

            case TechnicalIndicator.MovingAverageConvergenceDivergence:
                var macd = _algorithm.MACD(pair, _ignorePeriod ? 12 : _fastPeriod, _ignorePeriod ? 26 : _slowPeriod, _ignorePeriod ? 9 : _signalPeriod, MovingAverageType.Simple, _resolution);
                signal = new CrossingMovingAverageSignal(macd, macd.Signal, direction);
                break;

            case TechnicalIndicator.Stochastic:
                var sto = _algorithm.STO(pair, _ignorePeriod ? 14 : _period, _resolution);
                signal = new OscillatorSignal(sto, direction, _enableSurvival ? 3 : 1);
                break;

            case TechnicalIndicator.RelativeStrengthIndex:
                var rsi = _algorithm.RSI(pair, _ignorePeriod ? 11 : _period);
                signal = new OscillatorSignal(rsi, new[] { 30, 70 }, direction);
                break;

            case TechnicalIndicator.CommodityChannelIndex:
                var cci = _algorithm.CCI(pair, _ignorePeriod ? 20 : _period, MovingAverageType.Simple, _resolution);
                signal = new OscillatorSignal(cci, new[] { -100, 100 }, direction);
                break;

            case TechnicalIndicator.MomentumPercent:
                var pm = _algorithm.MOMP(pair, _ignorePeriod ? 60 : _period, _resolution);
                signal = new OscillatorSignal(pm, new[] { -5, 5 }, direction);
                break;

            case TechnicalIndicator.WilliamsPercentR:
                var wr = _algorithm.WILR(pair, _ignorePeriod ? 14 : _period, _resolution);
                signal = new OscillatorSignal(wr, new[] { -20, -80 }, direction);
                break;

            case TechnicalIndicator.PercentagePriceOscillator:
                var ppo = _algorithm.MACD(pair, _ignorePeriod ? 12 : _fastPeriod, _ignorePeriod ? 26 : _slowPeriod, _ignorePeriod ? 9 : _signalPeriod, MovingAverageType.Simple, _resolution)
                          .Over(_algorithm.EMA(pair, _ignorePeriod ? 120 : _period, resolution: _resolution)).Plus(constant: 100m);
                var compound = new SimpleMovingAverage(_ignorePeriod ? 120 : _period).Of(ppo);
                signal = new CrossingMovingAverageSignal(ppo, compound, direction);
                break;

            case TechnicalIndicator.None:
                signal = new EmptySignal();
                break;

            case TechnicalIndicator.AverageDirectionalIndex:
                var adx = _algorithm.ADX(pair, _ignorePeriod ? 20 : _period, _resolution);
                signal = new OscillatorSignal(adx, new[] { 25, 25 }, direction);
                break;

            //todo:
            case TechnicalIndicator.NormalizedAverageTrueRange:
                var natr = _algorithm.NATR(pair, _ignorePeriod ? 20 : _period, _resolution);
                signal = new OscillatorSignal(natr, new[] { 1, 1 }, direction);
                break;

            case TechnicalIndicator.BollingerBands:
                var bb = _algorithm.BB(pair, _ignorePeriod ? 20 : _period, k: 2);
                signal = new BBOscillatorSignal(bb, direction, _enableSurvival ? 4 : 1);
                break;

            case TechnicalIndicator.ExponentialMovingAverage:
                var fastema = _algorithm.EMA(pair, _ignorePeriod ? 50 : _fastPeriod);
                var slowema = _algorithm.EMA(pair, _ignorePeriod ? 200 : _slowPeriod);
                signal = new CrossingMovingAverageSignal(fastema, slowema, direction);
                break;

            case TechnicalIndicator.ChannelBreakout:
                var delay = new Delay(5);
                var _max  = delay.Of(_algorithm.MAX(pair, _ignorePeriod ? 20 : _period));
                var _min  = delay.Of(_algorithm.MIN(pair, _ignorePeriod ? 20 : _period));
                var cur   = _algorithm.MAX(pair, 1);   //current value
                signal = new ChannelOscillatorSignal(cur, _max, _min, direction, _enableSurvival ? 4 : 1);
                break;

            case TechnicalIndicator.DonchianTrend:
                var donchian = _algorithm.DCH(pair, _ignorePeriod ? 20 : _period);
                var max      = _algorithm.MAX(pair, _ignorePeriod ? 1 : _period);
                signal = new DonchianSignal(max, donchian, 2, direction);
                break;
            }

            signal.Name = indicator.ToString();
            return(signal);
        }
Ejemplo n.º 2
0
        protected override ISignal CreateIndicator(Symbol pair, int i, string entryOrExit)
        {
            var key          = entryOrExit + "Indicator" + i + "Direction";
            var intDirection = GetConfigValue(key);

            var direction = intDirection == 0 ? Direction.LongOnly : Direction.ShortOnly;

            key = entryOrExit + "Indicator" + i;

            var     indicator = (TechnicalIndicator)GetConfigValue(key);
            ISignal signal    = null;

            switch (indicator)
            {
            case TechnicalIndicator.SimpleMovingAverage:
                var fast = _algorithm.SMA(pair, _fastPeriod, _resolution);
                var slow = _algorithm.SMA(pair, _slowPeriod, _resolution);
                signal = new CrossingMovingAverageSignal(fast, slow, direction);
                break;

            case TechnicalIndicator.ExponentialMovingAverage:
                // Canonical cross moving average parameters.
                var fastema = _algorithm.EMA(pair, period: 50);
                var slowema = _algorithm.EMA(pair, period: 200);
                signal = new CrossingMovingAverageSignal(fastema, slowema, direction);
                break;

            case TechnicalIndicator.MovingAverageConvergenceDivergence:
                var macd = _algorithm.MACD(pair, fastPeriod: 12, slowPeriod: 26, signalPeriod: 9, type: MovingAverageType.Simple, resolution: _resolution);
                signal = new CrossingMovingAverageSignal(macd, macd.Signal, direction, 1);
                break;

            case TechnicalIndicator.Stochastic:
                var sto = _algorithm.STO(pair, period: 14, resolution: _resolution);
                signal = new OscillatorSignal(sto, new[] { 20, 80 }, direction, 3);
                break;

            case TechnicalIndicator.RelativeStrengthIndex:
                var rsi = _algorithm.RSI(pair, period: 11);
                signal = new OscillatorSignal(rsi, new[] { 30, 70 }, direction);
                break;

            case TechnicalIndicator.CommodityChannelIndex:
                var cci = _algorithm.CCI(pair, period: 20, movingAverageType: MovingAverageType.Simple, resolution: _resolution);
                signal = new OscillatorSignal(cci, new[] { -100, 100 }, direction);
                break;

            case TechnicalIndicator.MomentumPercent:
                var pm = _algorithm.MOMP(pair, period: 60, resolution: _resolution);
                signal = new OscillatorSignal(pm, new[] { -5, 5 }, direction);
                break;

            case TechnicalIndicator.WilliamsPercentR:
                var wr = _algorithm.WILR(pair, period: 14, resolution: _resolution);
                signal = new OscillatorSignal(wr, new[] { -20, -80 }, direction);
                break;

            case TechnicalIndicator.PercentagePriceOscillator:
                var ppo = _algorithm.MACD(pair, fastPeriod: 12, slowPeriod: 26, signalPeriod: 9, type: MovingAverageType.Simple, resolution: _resolution)
                          .Over(_algorithm.EMA(pair, _period, resolution: _resolution)).Plus(constant: 100m);
                var compound = new SimpleMovingAverage(_period).Of(ppo);
                signal = new CrossingMovingAverageSignal(ppo, compound, direction);
                break;

            case TechnicalIndicator.None:
                signal = new EmptySignal();
                break;

            case TechnicalIndicator.AverageDirectionalIndex:
                var adx = _algorithm.ADX(pair, _period, _resolution);
                signal = new OscillatorSignal(adx, new[] { 25, 25 }, direction);
                break;

            //todo:
            //case TechnicalIndicator.AverageTrueRange:
            //    var atr = _algorithm.ATR(pair, _period, MovingAverageType.Simple, _resolution);
            //    signal = new OscillatorSignal(atr, oscillatorThresholds, direction);
            //    break;

            case TechnicalIndicator.BollingerBands:
                var bb = _algorithm.BB(pair, period: 20, k: 2);
                signal = new BBOscillatorSignal(bb, direction, 4);
                break;

            case TechnicalIndicator.ChannelBreakout:
                var delay = new Delay(5);
                var _max  = delay.Of(_algorithm.MAX(pair, 20));
                var _min  = delay.Of(_algorithm.MIN(pair, 20));
                var cur   = _algorithm.MAX(pair, 1);   //current value
                signal = new ChannelOscillatorSignal(cur, _max, _min, direction, 4);
                break;

            case TechnicalIndicator.DonchianTrend:
                var dch0 = _algorithm.DCH(pair, 20);
                var cur0 = _algorithm.MAX(pair, 1);
                signal = new DonchianSignal(cur0, dch0, 2, direction);
                break;
            }


            return(signal);
        }