Beispiel #1
0
        private void MakeTickEMA(List <double> list, EMA ema)
        {
            int i, j, count;

            for (j = 0; j < longLength.Length; j++)
            {
                for (i = 0; i < shortLength.Length; i++)
                {
                    List <double[]> widthTick = new List <double[]>(2097152);
                    List <double>   shortTick = new List <double>(2097152);
                    List <double>   longTick  = new List <double>(2097152);

                    foreach (double price in list)
                    {
                        double[] temp = new double[3];
                        count = shortTick.Count;
                        shortTick.Add(count > 0 ? ema.Make(shortLength[i], count, price, shortTick[count - 1]) : ema.Make(price));
                        longTick.Add(count > 0 ? ema.Make(longLength[j], count, price, longTick[count - 1]) : ema.Make(price));
                        temp[0] = price;
                        temp[1] = shortTick[count] - longTick[count];
                        temp[2] = price - shortTick[count];
                        widthTick.Add(temp);
                    }
                    Analysis(string.Concat(i.ToString("D2"), j.ToString("D2")), widthTick);
                }
            }
        }
Beispiel #2
0
 protected internal void Analysize(Catalog.Chart chart)
 {
     if (GetCheckOnTime(chart.Date))
     {
         Short.Pop();
         Long.Pop();
     }
     Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, chart.Price, Short.Peek()) : EMA.Make(chart.Price));
     Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, chart.Price, Long.Peek()) : EMA.Make(chart.Price));
 }
Beispiel #3
0
        void Analysize(object sender, Datum e)
        {
            if (GetCheckOnTimeByAPI(e.Time))
            {
                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();
            var    trend = popShort - popLong - (Short.Peek() - Long.Peek());

            Short.Push(popShort);
            Long.Push(popLong);

            API.Trend[specify.Strategy] = string.Concat(trend.ToString("F2"), " (", specify.Time == 1440 ? "Day" : Check, ")");

            switch (specify.Strategy)
            {
            case "TF":
                SetTrendFollowing(specify.Assets / (specify.Code.Length == 8 ? e.Price * Const.TransactionMultiplier * Const.MarginRate200402 : e.Price), trend);
                break;

            case "WU":
                SetWindingUp(trend);

                if (API.Quantity != 0 && API.OnReceiveBalance && GetTickRevenue(specify.Strategy))
                {
                    var price = GetExactPrice();

                    if (API.Quantity > 0 ? price > e.Price : price < e.Price)
                    {
                        SendNewOrder(API.Quantity > 0 ? "1" : "2", price);
                    }
                }
                break;
            }
            if (GetTrend(trend.ToString()))
            {
                SendClearingOrder(trend);
            }

            if (specify.Reaction > 0)
            {
                API.Volume += e.Volume;

                if (API.OnReceiveBalance && (trend > 0 ? API.BuyOrder.Count == 0 : API.SellOrder.Count == 0) && GetJudgeTheReaction(trend, e.Price) && GetJudgeTheReaction(API.Volume, trend))
                {
                    var price = e.Price + (trend > 0 ? -Const.ErrorRate : Const.ErrorRate);
                    SendNewOrder(trend > 0 ? "2" : "1", price);
                    API.Volume = 0;
                }
            }
        }
Beispiel #4
0
 void DrawChart(long date, dynamic price)
 {
     if (GetCheckOnTimeByAPI(date.ToString()))
     {
         Short.Pop();
         Long.Pop();
         Trend.Pop();
     }
     Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, price, Short.Peek()) : EMA.Make(price));
     Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, price, Long.Peek()) : EMA.Make(price));
     Trend.Push(Trend.Count > 0 ? EMA.Make(specify.Trend, Trend.Count, price, Trend.Peek()) : EMA.Make(price));
 }
Beispiel #5
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 #6
0
        void Analysize(object sender, Datum e)
        {
            if (GetCheckOnTimeByAPI(e.Time))
            {
                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();

            API.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify, Check);
            Short.Push(popShort);
            Long.Push(popLong);
        }
Beispiel #7
0
        protected internal void Analysize(Catalog.Chart chart)
        {
            var input = GetCheckOnTime(chart.Date);

            if (input)
            {
                Short.Pop();
                Long.Pop();
            }
            double st = Short.Count > 0 ? Short.Peek() : chart.Price, lt = Long.Count > 0 ? Long.Peek() : chart.Price;

            if (input == false && (lCollection || sCollection))
            {
                var date = chart.Date.ToString();
                date = date.Length == 8 ? date.Substring(2) : date;

                switch (specify.Time)
                {
                case 1440:
                    date = date.Substring(0, 6);
                    break;

                default:
                    if (date.Length > 8)
                    {
                        date = date.Substring(0, 10);
                    }

                    break;
                }
                if (sCollection)
                {
                    ShortValue[date] = st;
                }

                if (lCollection)
                {
                    LongValue[date] = lt;
                }
            }
            Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, chart.Price, st) : EMA.Make(chart.Price));
            Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, chart.Price, lt) : EMA.Make(chart.Price));

            if (specify.Time == 1440 && chart.Volume != 0 && GetCheckTime(chart.Date.ToString()))
            {
                OnReceiveTrend(chart.Volume);
            }
        }
Beispiel #8
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 #9
0
        internal void DrawChart(string time, int price)
        {
            if (GetCheckOnTimeByAPI(time))
            {
                Short.Pop();
                Long.Pop();
                Trend.Pop();
            }
            Short.Push(EMA.Make(specify.Short, Short.Count, price, Short.Peek()));
            Long.Push(EMA.Make(specify.Long, Long.Count, price, Long.Peek()));
            Trend.Push(EMA.Make(specify.Trend, Trend.Count, price, Trend.Peek()));
            double popShort = Short.Pop(), popLong = Long.Pop(), gap = popShort - popLong - (Short.Peek() - Long.Peek());

            Short.Push(popShort);
            Long.Push(popLong);

            if (specify.Short < Short.Count && specify.Long < Long.Count && specify.Trend < Trend.Count && price < Trend.Peek() && gap > 0 && (price <= Price || Price == 0) && price <= BuyPrice)
            {
                Price = API.OnReceiveOrder(Code, price);
            }
        }
Beispiel #10
0
        void Analysize(object sender, Datum e)
        {
            if (GetCheckOnTimeByAPI(e.Time))
            {
                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();

            API.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify, Check);
            Short.Push(popShort);
            Long.Push(popLong);
            API.TradingJudge[specify.Time] = popShort;

            if (specify.Time == 1440 && GetCheckTime(e.Time))
            {
                OnReceiveTrend(e.Volume);
            }
        }
Beispiel #11
0
        public override void OnReceiveDrawChart(object sender, SendConsecutive e)
        {
            if (GetCheckOnDate(e.Date))
            {
                Short.Pop();
                Long.Pop();
                Trend.Pop();
            }
            Trend.Push(Trend.Count > 0 ? EMA.Make(Line.Item3, Trend.Count, e.Price, Trend.Peek()) : EMA.Make(e.Price));
            Short.Push(Short.Count > 0 ? EMA.Make(Line.Item1, Short.Count, e.Price, Short.Peek()) : EMA.Make(e.Price));
            Long.Push(Long.Count > 0 ? EMA.Make(Line.Item2, Long.Count, e.Price, Long.Peek()) : EMA.Make(e.Price));

            if (e.Volume != 0 && e.Date.Length > 8 && Short.Count > 1 && Long.Count > 1)
            {
                double popShort = Short.Pop(), popLong = Long.Pop(), gap = popShort - popLong - (Short.Peek() - Long.Peek());
                Short.Push(popShort);
                Long.Push(popLong);
                var date = e.Date.Substring(6, 4);

                if (date.CompareTo(Base.Start) > 0 && date.CompareTo(Base.Transmit) < 0 && Strategics is Catalog.TrendsToCashflow tc &&
                    DateTime.TryParseExact(e.Date.Substring(0, 12), Base.FullDateFormat, CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime cInterval))
                {
                    if (Balance.Quantity > tc.ReservationQuantity - 1 && (Offer ?? int.MaxValue) < e.Price &&
                        OrderNumber.Any(o => o.Key[0] == '8' && o.Value == e.Price - GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee    += (uint)(e.Price * tc.ReservationQuantity * (Commission + Base.Tax));
                        Balance.Revenue  += (long)((e.Price - (Balance.Purchase ?? 0D)) * tc.ReservationQuantity);
                        Balance.Quantity -= tc.ReservationQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("8") && o.Value == e.Price - GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital -= profit.Value * tc.ReservationQuantity;
                            Offer    = profit.Value;
                        }
                    }
                    else if ((Bid ?? int.MinValue) > e.Price && OrderNumber.Any(o => o.Key[0] == '7' && o.Value == e.Price + GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee += (uint)(e.Price * Commission * tc.ReservationQuantity);
                        Balance.Purchase
                            = (double)((e.Price * tc.ReservationQuantity + (Balance.Purchase ?? 0D) * Balance.Quantity) / (Balance.Quantity + tc.ReservationQuantity));
                        Balance.Quantity += tc.ReservationQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("7") && o.Value == e.Price + GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital += profit.Value * tc.ReservationQuantity;
                            Bid      = profit.Value;
                        }
                    }
                    else if (Balance.Quantity > tc.TradingQuantity - 1 && OrderNumber.Any(o => o.Key[0] == '2' && o.Value == e.Price - GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee    += (uint)(e.Price * tc.TradingQuantity * (Commission + Base.Tax));
                        Balance.Revenue  += (long)((e.Price - (Balance.Purchase ?? 0D)) * tc.TradingQuantity);
                        Balance.Quantity -= tc.TradingQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("2") && o.Value == e.Price - GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital -= profit.Value * tc.TradingQuantity;
                        }
                    }
                    else if (OrderNumber.Any(o => o.Key.StartsWith("1") && o.Value == e.Price + GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee    += (uint)(e.Price * Commission * tc.TradingQuantity);
                        Balance.Purchase  = (double)((e.Price * tc.TradingQuantity + (Balance.Purchase ?? 0D) * Balance.Quantity) / (Balance.Quantity + tc.TradingQuantity));
                        Balance.Quantity += tc.TradingQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("1") && o.Value == e.Price + GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital += profit.Value * tc.TradingQuantity;
                        }
                    }
                    else if (Balance.Quantity > tc.TradingQuantity - 1 && OrderNumber.ContainsValue(e.Price) == false &&
                             e.Price > Trend.Peek() * (1 + tc.PositionRevenue) && e.Price > (Balance.Purchase ?? 0D) &&
                             gap < 0 && (tc.Interval == 0 || tc.Interval > 0 && cInterval.CompareTo(NextOrderTime) > 0))
                    {
                        var unit = GetQuoteUnit(e.Price, Market);

                        if (OrderNumber.ContainsValue(e.Price + unit) == false)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.신규매도)] = e.Price + unit;
                        }

                        if (tc.Interval > 0)
                        {
                            NextOrderTime = Base.MeasureTheDelayTime(tc.Interval, cInterval);
                        }
                    }
                    else if (tc.TradingQuantity > 0 && OrderNumber.ContainsValue(e.Price) == false && e.Price < Trend.Peek() * (1 - tc.PositionAddition) &&
                             gap > 0 && (tc.Interval == 0 || tc.Interval > 0 && cInterval.CompareTo(NextOrderTime) > 0))
                    {
                        var unit = GetQuoteUnit(e.Price, Market);

                        if (OrderNumber.ContainsValue(e.Price - unit) == false)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.신규매수)] = e.Price - unit;
                        }

                        if (tc.Interval > 0)
                        {
                            NextOrderTime = Base.MeasureTheDelayTime(tc.Interval, cInterval);
                        }
                    }
                }
                else if (date.CompareTo(Base.Transmit) > 0 && Strategics is Catalog.TrendsToCashflow cf)
                {
                    OrderNumber.Clear();
                    long revenue = Balance.Revenue - CumulativeFee, unrealize = (long)((e.Price - (Balance.Purchase ?? 0D)) * Balance.Quantity);
                    var  avg = EMA.Make(++Accumulative, revenue - TodayRevenue + unrealize - TodayUnrealize, Before);

                    if (cf.ReservationQuantity > 0 && Balance.Quantity > cf.ReservationQuantity - 1)
                    {
                        var stock = Market;
                        int quantity = Balance.Quantity / cf.ReservationQuantity, price = e.Price, sell = (int)((Balance.Purchase ?? 0D) * (1 + cf.ReservationRevenue)),
                            buy = (int)((Balance.Purchase ?? 0D) * (1 - cf.Addition)), upper = (int)(price * 1.3), lower = (int)(price * 0.7),
                            bPrice = Base.GetStartingPrice(lower, stock), sPrice = Base.GetStartingPrice(sell, stock);
                        sPrice = sPrice < lower ? lower + GetQuoteUnit(sPrice, stock) : sPrice;

                        while (sPrice < upper && quantity-- > 0)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.예약매도)] = sPrice;

                            for (int i = 0; i < cf.Unit; i++)
                            {
                                sPrice += GetQuoteUnit(sPrice, stock);
                            }
                        }
                        while (bPrice < upper && bPrice < buy)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.예약매수)] = bPrice;

                            for (int i = 0; i < cf.Unit; i++)
                            {
                                bPrice += GetQuoteUnit(bPrice, stock);
                            }
                        }
                        Bid   = OrderNumber.Count > 0 && OrderNumber.Any(o => o.Key.StartsWith("7")) ? OrderNumber.Where(o => o.Key.StartsWith("7")).Max(o => o.Value) : 0;
                        Offer = OrderNumber.Count > 0 && OrderNumber.Any(o => o.Key.StartsWith("8")) ? OrderNumber.Where(o => o.Key.StartsWith("8")).Min(o => o.Value) : 0;
                    }
                    SendMessage = new Catalog.Strategics.Statistics
                    {
                        Key        = string.Concat("TC.", cf.AnalysisType),
                        Date       = e.Date.Substring(0, 6),
                        Cumulative = revenue + unrealize,
                        Base       = SendMessage.Base > Capital ? SendMessage.Base : Capital,
                        Statistic  = (int)avg,
                        Price      = (int)Trend.Peek()
                    };
                    Before         = avg;
                    TodayRevenue   = revenue;
                    TodayUnrealize = unrealize;
                }
            }
Beispiel #12
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;
                    }
                }
            }
        }
Beispiel #13
0
        void Analysize(object sender, Datum e)
        {
            if (GetCheckOnTimeByAPI(e.Time))
            {
                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();

            API.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify.Time, Check);
            Short.Push(popShort);
            Long.Push(popLong);

            if (specify.Time == 1440 && string.IsNullOrEmpty(API.Classification) == false && API.OnReceiveBalance)
            {
                var judge = API.Judge.OrderBy(o => o.Key);
                var trend = judge.First().Value;

                if ((API.Classification.Equals(buy) ? e.Volume + trend > e.Volume : e.Volume + trend < e.Volume) && GetJudgeTheTrading(e.Volume))
                {
                    if (API.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 (API.Classification.Equals(sell) && kv.Value + accumulative < 0)
                                {
                                    num = 8;
                                }

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

                                continue;
                            }
                            if (API.Classification.Equals(buy) && kv.Value < 0)
                            {
                                num++;
                            }
                        }
                        if (num == 8 && API.OnReceiveBalance && SendNewOrder(e.Price, API.Classification))
                        {
                            API.Volume = e.Volume;

                            return;
                        }
                    }
                    if (API.Judge.Count == 2 && API.OnReceiveBalance && SendNewOrder(e.Price, API.Classification))
                    {
                        API.Volume = e.Volume;

                        return;
                    }
                }
                if (API.Judge.Count > 2 && this.judge % 2 == 0)
                {
                    var num = 0;

                    if (API.Quantity > 0 && e.Volume < -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 (API.Classification.Equals(buy) && kv.Value > 0)
                            {
                                num++;
                            }
                        }
                        if (num == 8 && API.OnReceiveBalance && SendNewOrder(e.Price, sell))
                        {
                            API.Volume = e.Volume;

                            return;
                        }
                    }
                    else if (API.Quantity < 0 && e.Volume > 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 (API.Classification.Equals(sell) && kv.Value < 0)
                            {
                                num++;
                            }
                        }
                        if (num == 8 && API.OnReceiveBalance && SendNewOrder(e.Price, buy))
                        {
                            API.Volume = e.Volume;

                            return;
                        }
                    }
                }
            }
        }
Beispiel #14
0
        void Analysize(object sender, Datum e)
        {
            if (api == null)
            {
                if (GetCheckOnTime(e.Chart.Date))
                {
                    Short.Pop();
                    Long.Pop();
                }
                Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, e.Chart.Price, Short.Peek()) : EMA.Make(e.Chart.Price));
                Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, e.Chart.Price, Long.Peek()) : EMA.Make(e.Chart.Price));

                return;
            }
            if (GetCheckOnTimeByAPI(e.Time))
            {
                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();
            var    trend = popShort - popLong - (Short.Peek() - Long.Peek());

            Short.Push(popShort);
            Long.Push(popLong);
            api.Trend[specify.Strategy] = string.Concat(trend.ToString("F2"), " (", specify.Time == 1440 ? "Day" : Check, ")");

            if (quotes != null)
            {
                switch (specify.Strategy)
                {
                case "TF":
                    quotes.SetTrendFollowing(specify.Assets / (specify.Code.Length == 8 ? e.Price * Const.TransactionMultiplier * Const.MarginRate200402 : e.Price), trend);
                    break;

                case "WU":
                    quotes.SetWindingUp(trend);

                    if (api.Quantity != 0 && api.OnReceiveBalance && quotes.GetTickRevenue(specify.Strategy))
                    {
                        var price = quotes.GetExactPrice();

                        if (api.Quantity > 0 ? price > e.Price : price < e.Price)
                        {
                            api.OnReceiveBalance = false;
                            api.OnReceiveOrder(new PurchaseInformation
                            {
                                RQName   = string.Concat(price, ';'),
                                ScreenNo = string.Concat(api.Quantity > 0 ? "1" : "2", new Random().Next(1, 76).ToString("D3")),
                                AccNo    = Array.Find(specify.Account, o => o.Substring(8, 2).Equals("31")),
                                Code     = api.Code,
                                OrdKind  = 1,
                                SlbyTP   = api.Quantity > 0 ? "1" : "2",
                                OrdTp    = ((int)OrderType.지정가).ToString(),
                                Qty      = 1,
                                Price    = price.ToString("F2"),
                                OrgOrdNo = string.Empty
                            });
                        }
                    }
                    break;
                }
                if (GetTrend(trend.ToString()))
                {
                    quotes.SendClearingOrder(trend);
                }
            }
            else if (specify.Reaction > 0)
            {
                api.Volume += e.Volume;

                if (api.OnReceiveBalance && (trend > 0 ? api.BuyOrder.Count == 0 : api.SellOrder.Count == 0) && GetJudgeTheReaction(trend, e.Price) && GetJudgeTheReaction(api.Volume, trend))
                {
                    api.OnReceiveBalance = false;
                    var price = e.Price + (trend > 0 ? -Const.ErrorRate : Const.ErrorRate);
                    api.OnReceiveOrder(new PurchaseInformation
                    {
                        RQName   = string.Concat(price, ';'),
                        ScreenNo = string.Concat(trend > 0 ? "2" : "1", new Random().Next(1, 76).ToString("D3")),
                        AccNo    = Array.Find(specify.Account, o => o.Substring(8, 2).Equals("31")),
                        Code     = api.Code,
                        OrdKind  = 1,
                        SlbyTP   = trend > 0 ? "2" : "1",
                        OrdTp    = ((int)OrderType.지정가).ToString(),
                        Qty      = 1,
                        Price    = price.ToString("F2"),
                        OrgOrdNo = string.Empty
                    });
                    api.Volume = 0;
                }
            }
        }