Beispiel #1
0
        void Analysize(object sender, EventHandler.BackTesting.Datum e)
        {
            if (GetCheckOnTime(e.Date))
            {
                Short.Pop();
                Long.Pop();
            }
            Short.Push(EMA.Make(specify.Short, Short.Count, e.Price, Short.Peek()));
            Long.Push(EMA.Make(specify.Long, Long.Count, e.Price, Long.Peek()));
            double popShort = Short.Pop(), popLong = Long.Pop();

            bt.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify);
            Short.Push(popShort);
            Long.Push(popLong);
        }
Beispiel #2
0
        void Analysize(object sender, EventHandler.BackTesting.Datum e)
        {
            if (GetCheckOnTime(e.Date))
            {
                Short.Pop();
                Long.Pop();
            }
            Short.Push(EMA.Make(specify.Short, Short.Count, e.Price, Short.Peek()));
            Long.Push(EMA.Make(specify.Long, Long.Count, e.Price, Long.Peek()));
            double popShort = Short.Pop(), popLong = Long.Pop();

            bt.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify);
            Short.Push(popShort);
            Long.Push(popLong);

            if (specify.Time == 1440)
            {
                if (GetCheckTime(e.Date.ToString()))
                {
                    OnReceiveTrend(e.Volume);
                }

                var date = e.Date.ToString().Substring(6, 6);

                if (date.Equals(end))
                {
                    bt.SetStatisticalStorage(e.Date.ToString().Substring(0, 6), e.Price, RollOver);
                }

                if (uint.TryParse(date, out uint cme) && cme > 45958 && cme < 85959)
                {
                    bt.SellOrder.Clear();
                    bt.BuyOrder.Clear();
                }
                if (bt.SellOrder.Count > 0 && e.Volume > 0)
                {
                    bt.SetSellConclusion(e.Date.ToString(), e.Price, e.Volume);
                }

                if (bt.BuyOrder.Count > 0 && e.Volume < 0)
                {
                    bt.SetBuyConclusion(e.Date.ToString(), e.Price, e.Volume);
                }
            }
            bt.TradingJudge[specify.Time] = popShort;
        }
Beispiel #3
0
        void Analysize(object sender, EventHandler.BackTesting.Datum e)
        {
            if (GetCheckOnTime(e.Date))
            {
                Short.Pop();
                Long.Pop();
            }
            Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, e.Price, Short.Peek()) : EMA.Make(e.Price));
            Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, e.Price, Long.Peek()) : EMA.Make(e.Price));

            if (e.Date.ToString().Length > 8)
            {
                double popShort = Short.Pop(), popLong = Long.Pop();
                bt.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify.Time);
                Short.Push(popShort);
                Long.Push(popLong);

                if (specify.Time == 1440)
                {
                    switch (e.Date.ToString().Substring(6))
                    {
                    case end:
                        bt.SetStatisticalStorage(e.Date.ToString().Substring(0, 6), e.Price, !specify.RollOver);
                        bt.Charts.Enqueue(new Models.Charts
                        {
                            Code  = specify.Code,
                            Date  = e.Date.ToString().Substring(0, 6),
                            Time  = 405,
                            Base  = specify.Short,
                            Value = Short.Peek()
                        });
                        bt.Charts.Enqueue(new Models.Charts
                        {
                            Code  = specify.Code,
                            Date  = e.Date.ToString().Substring(0, 6),
                            Time  = 405,
                            Base  = specify.Long,
                            Value = Long.Peek()
                        });
                        break;

                    case "045959000":
                    case "045959001":
                    case "045959002":
                    case "045959003":
                    case "045959004":
                    case "045959005":
                        bt.Charts.Enqueue(new Models.Charts
                        {
                            Code  = specify.Code,
                            Date  = e.Date.ToString().Substring(0, 6),
                            Time  = 660,
                            Base  = specify.Short,
                            Value = Short.Peek()
                        });
                        bt.Charts.Enqueue(new Models.Charts
                        {
                            Code  = specify.Code,
                            Date  = e.Date.ToString().Substring(0, 6),
                            Time  = 660,
                            Base  = specify.Long,
                            Value = Long.Peek()
                        });
                        break;

                    case onTime:
                    case nTime:
                        if (bt.SellOrder.Count > 0 || bt.BuyOrder.Count > 0)
                        {
                            bt.SellOrder.Clear();
                            bt.BuyOrder.Clear();
                        }
                        break;

                    default:
                        if (int.TryParse(e.Date.ToString().Substring(6, 6), out int time) && (time < 090001 && time > 045959) == false && (time > 153459 && time < 180000) == false && string.IsNullOrEmpty(bt.Classification) == false)
                        {
                            var judge = bt.Judge.OrderBy(o => o.Key);
                            var trend = judge.First().Value;

                            if ((bt.Classification.Equals(buy) ? e.Volume + trend > e.Volume : e.Volume + trend < e.Volume) && GetJudgeTheTrading(e.Price, e.Volume))
                            {
                                if (bt.Judge.Count > 2)
                                {
                                    var num          = 0;
                                    var accumulative = 0D;

                                    foreach (var kv in judge)
                                    {
                                        if (kv.Key == judge.First().Key)
                                        {
                                            continue;
                                        }

                                        if (kv.Key == 1440)
                                        {
                                            if (bt.Classification.Equals(sell) && kv.Value + accumulative < 0)
                                            {
                                                num = 8;
                                            }

                                            break;
                                        }
                                        if (bt.Classification.Equals(sell))
                                        {
                                            accumulative += kv.Value;

                                            continue;
                                        }
                                        if (bt.Classification.Equals(buy) && kv.Value < 0)
                                        {
                                            num++;
                                        }
                                    }
                                    if (num == 8 && bt.SetConclusion(e.Date, e.Price, bt.Classification))
                                    {
                                        return;
                                    }
                                }
                                if (bt.Judge.Count == 2 && bt.SetConclusion(e.Date, e.Price, bt.Classification))
                                {
                                    return;
                                }
                            }
                            if (bt.Judge.Count > 2 && this.judge % 2 == 0)
                            {
                                var num = 0;

                                if (bt.Quantity > 0 && e.Volume < (CME ? this.judge / -5 : -this.judge) && e.Volume + trend < e.Volume)
                                {
                                    foreach (var kv in judge)
                                    {
                                        if (kv.Key == judge.First().Key)
                                        {
                                            continue;
                                        }

                                        if (kv.Key == 1440)
                                        {
                                            break;
                                        }

                                        if (bt.Classification.Equals(buy) && kv.Value > 0)
                                        {
                                            num++;
                                        }
                                    }
                                    if (num == 8 && bt.SetConclusion(e.Date, e.Price, sell))
                                    {
                                        return;
                                    }
                                }
                                else if (bt.Quantity < 0 && e.Volume > (CME ? this.judge / 5 : this.judge) && e.Volume + trend > e.Volume)
                                {
                                    foreach (var kv in judge)
                                    {
                                        if (kv.Key == judge.First().Key)
                                        {
                                            continue;
                                        }

                                        if (kv.Key == 1440)
                                        {
                                            break;
                                        }

                                        if (bt.Classification.Equals(sell) && kv.Value < 0)
                                        {
                                            num++;
                                        }
                                    }
                                    if (num == 8 && bt.SetConclusion(e.Date, e.Price, buy))
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }