コード例 #1
0
        public TRENDResult GetResult()
        {
            this.result = TRENDResult.Flat;

            if (this.type == "simple")
            {
                //decimal d = _data.Last() - _data[0];

                decimal d = GetDiff(_data[0], _data.Last());

                if (d > 0.15m)
                {
                    this.result = TRENDResult.Up;
                }

                if (d < -0.15m)
                {
                    this.result = TRENDResult.Down;
                }
            }

            if (this.type == "macd")
            {
                decimal d = GetDiff(_data[0], _data.Last());

                //if (Math.Abs(_data.Last()) < 1m && Math.Abs(_data[0]) < 1m)
                //{
                //    d = 0m;
                //}

                if (d > 10m && d <= 70m)
                {
                    this.result = TRENDResult.Up;
                }
                ;

                if (d < -10m && d >= -70m)
                {
                    this.result = TRENDResult.Down;
                }

                if (d > 70m)
                {
                    this.result = TRENDResult.StrongUp;
                }
                ;

                if (d < -70m)
                {
                    this.result = TRENDResult.StrongDown;
                }
            }

            return(result);
        }
コード例 #2
0
        public StrategyDecision GetDecision(IDictionary <string, IList <ICandle> > data, string name, string currentPos, Security security, DateTime CurrentDt)
        {
            StrategyDecision dec = new StrategyDecision()
            {
                Decision = null
            };

            SimpleMovingAverage short_ma = new SimpleMovingAverage(data["5"], 9);
            SimpleMovingAverage long_ma  = new SimpleMovingAverage(data["5"], 30);

            MACD        macd      = new MACD(data["5"], 12, 26, 9);
            TREND       macdTrend = new TREND(macd, 2);
            TRENDResult power     = macdTrend.GetResult();

            TRENDResult trend = new TREND(long_ma, 3).GetResult();

            AverageTrueRange atr = new AverageTrueRange(data["5"], 14);

            //dec.Profit = Math.Round(atr.Last() * 2m, 2);
            //dec.StopLoss = Math.Round(atr.Last(), 2);

            dec.Profit   = Math.Round(data["5"].Last().close * 0.006m, 2);
            dec.StopLoss = Math.Round(data["5"].Last().close * 0.002m, 2);


            decimal vollast = data["5"].Last().volume;
            decimal volprev = data["5"][data["5"].Count - 2].volume;

            bool vol = vollast > volprev * 2m;

            //if (power == TRENDResult.StrongUp && new Crossover(short_ma, long_ma).GetResult())
            //{
            //    //dec.Decision = "open long";

            //    //dec.Price = Math.Round(data["5"].Last().close * 1.005m, 2);

            //    signals.Add(new Signal() { Security = name, Action = "open long", DateTime = CurrentDt, Price= data["5"].Last().close });
            //}
            //else
            if (power == TRENDResult.StrongUp)
            {
                //dec.Decision = "open long";

                //dec.Price = Math.Round(data["5"].Last().close * 1.005m, 2);
                signals.Add(new Signal()
                {
                    Security = name, Action = "open long", DateTime = CurrentDt, Price = data["5"].Last().close
                });
            }

            if (currentPos == "free")
            {
                DateTime minDt = CurrentDt.AddMinutes(-20);
                DateTime maxDt = CurrentDt.AddMinutes(-15);

                var lastSignals = signals.Where(s => s.Security == name && s.Action == "open long" && s.DateTime < maxDt && s.DateTime >= minDt).ToList();

                Signal signal = lastSignals.FirstOrDefault();

                decimal summ = 0;

                if (signal != null)
                {
                    var candlesToCheck = data["5"].Where(c => c.begin >= signal.DateTime).ToList();

                    foreach (Candle c in candlesToCheck)
                    {
                        summ += c.close - c.open;
                    }
                }


                if (summ > atr.Last() * 2m && data["5"].Last().close > signal.Price)
                {
                    dec.Decision = "open long";

                    dec.LongPrice = Math.Round(data["5"].Last().close * 1.005m, 2);
                }
            }



            //if ((power == TRENDResult.Down || power == TRENDResult.StrongDown) && new Crossover(long_ma, short_ma).GetResult() && currentPos == "free")
            //{
            //    dec.Decision = "open short";

            //    dec.Price = Math.Round(data[5].Last().close * 0.995m, 2);
            //}


            if (security.MinStep == 1)
            {
                dec.Profit    = Math.Round(dec.Profit);
                dec.StopLoss  = Math.Round(dec.StopLoss);
                dec.LongPrice = Math.Round(dec.LongPrice);
            }

            //dec.Decision = "open long";

            return(dec);
        }
コード例 #3
0
        public StrategyDecision GetDecision(IDictionary <string, IList <ICandle> > data, string name, string currentPos, Security security, DateTime CurrentDt)
        {
            StrategyDecision dec = new StrategyDecision()
            {
                Decision = null
            };

            ExponentialMovingAverage hours_ema = new ExponentialMovingAverage(data["60"], 9);

            //ExponentialMovingAverage minutes_ema = new ExponentialMovingAverage(data[5], 4);

            MACD macd = new MACD(data["5"], 12, 26, 9);

            TREND hoursTrend = new TREND(hours_ema, 3);
            //TREND minutesTrend = new TREND(minutes_ema, 3);
            TREND macdTrend    = new TREND(macd, 2);
            bool  valueConfirm = new ValueConfirm(data["5"], 5).GetResult();

            AverageTrueRange atr = new AverageTrueRange(data["5"], 14);

            Extremum extremum = new Extremum(atr, 3, 20);

            //hoursTrend.GetResult();
            //macdTrend.GetResult();

            //if ((hoursTrend.GetResult() == TRENDResult.Up && macdTrend.GetResult() == TRENDResult.Up || macdTrend.GetResult() == TRENDResult.StrongUp) && currentPos == "free")
            //{
            //    dec = "open long";
            //}

            //if ((hoursTrend.GetResult() == TRENDResult.Down && macdTrend.GetResult() == TRENDResult.Down || macdTrend.GetResult() == TRENDResult.StrongDown) && currentPos == "free")
            //{
            //    dec = "open short";
            //}

            TRENDResult trend = hoursTrend.GetResult();
            TRENDResult power = macdTrend.GetResult();


            decimal value = data["5"].Last().value;

            //*if (extremum.Count() > 0 && extremum.Last().ext == "L" && extremum.Last().val < atr.Last())
            if (atr.Last() > 10m && valueConfirm)
            {
                dec.Profit   = Math.Round(atr.Last() * 4m, 2);
                dec.StopLoss = Math.Round(atr.Last(), 2);



                if (trend == TRENDResult.Up && (power == TRENDResult.Up || power == TRENDResult.StrongUp) && currentPos == "free")
                {
                    dec.Decision = "open long";
                }

                if (trend == TRENDResult.Flat && power == TRENDResult.StrongUp && currentPos == "free")
                {
                    dec.Decision = "open long";
                }

                if (trend == TRENDResult.Down && (power == TRENDResult.Down || power == TRENDResult.StrongDown) && currentPos == "free")
                {
                    dec.Decision = "open short";
                }

                if (trend == TRENDResult.Flat && power == TRENDResult.StrongDown && currentPos == "free")
                {
                    dec.Decision = "open short";
                }
            }

            if (CurrentDt >= new DateTime(2017, 5, 15, 15, 20, 0))
            {
                //dec = null;
            }

            return(dec);
        }