コード例 #1
0
ファイル: Analysize.cs プロジェクト: pureuniverse/GoblinBat
        private void Analysis(Chart ch)
        {
            bool   check = false;
            string time  = ch.Date.ToString();

            if (specify.Time > 0 && specify.Time < 1440)
            {
                check = time.Length > 8 && GetCheckOnTime(time);
            }

            else if (specify.Time == 1440)
            {
                check = time.Length > 8 && time.Substring(6).Equals("090000000") == false;
            }

            if (check)
            {
                Short.Pop();
                Long.Pop();
            }
            Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, ch.Price, Short.Peek()) : EMA.Make(ch.Price));
            Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, ch.Price, Long.Peek()) : EMA.Make(ch.Price));
            double popShort = Short.Pop(), popLong = Long.Pop();
            var    trend = Short.Count > 1 && Long.Count > 1 ? popShort - popLong - (Short.Peek() - Long.Peek()) > 0 ? 1 : -1 : 0;

            Short.Push(popShort);
            Long.Push(popLong);
        }
コード例 #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));
 }
コード例 #3
0
ファイル: Trading.cs プロジェクト: hur-kyuh-leez/Strategy
        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;
                }
            }
        }
コード例 #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));
 }
コード例 #5
0
ファイル: Analysis.cs プロジェクト: hur-kyuh-leez/Strategy
        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);
        }
コード例 #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);
        }
コード例 #7
0
ファイル: TF.cs プロジェクト: w1r2p1/GoblinBat
        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);
            }
        }
コード例 #8
0
ファイル: Analysis.cs プロジェクト: w1r2p1/GoblinBat
        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;
        }
コード例 #9
0
ファイル: Analysis.cs プロジェクト: hur-kyuh-leez/Strategy
        void Analysize(Chart ch)
        {
            if (GetCheckOnTime(ch.Date))
            {
                Short.Pop();
                Long.Pop();
            }
            Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, ch.Price, Short.Peek()) : EMA.Make(ch.Price));
            Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, ch.Price, Long.Peek()) : EMA.Make(ch.Price));
            double popShort = Short.Pop(), popLong = Long.Pop();
            int    i, quantity = Short.Count > 1 && Long.Count > 1 ? popShort - popLong - (Short.Peek() - Long.Peek()) > 0 ? 1 : -1 : 0;
            var    max = specify.Assets / (specify.Code.Length == 8 ? ch.Price * Const.TransactionMultiplier * Const.MarginRate200402 : ch.Price);

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

            if (ch.Date > 99999999 && ch.Date.ToString().Substring(6, 4).Equals("1545"))
            {
                info.Save(ch, specify);

                return;
            }
            if (ch.Date > 99999999 && info.Quantity != 0 && GetRemainingDate(specify.Code, ch.Date))
            {
                for (i = Math.Abs(info.Quantity); i > 0; i--)
                {
                    info.Operate(ch, info.Quantity > 0 ? -1 : 1);
                }

                return;
            }
            if (ch.Date > 99999999 && Math.Abs(info.Quantity + quantity) < max)
            {
                info.Operate(ch, quantity);
            }

            else if (ch.Date > 99999999 && Math.Abs(info.Quantity) > max)
            {
                info.Operate(ch, info.Quantity > 0 ? -1 : 1);
            }
        }
コード例 #10
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);
            }
        }
コード例 #11
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);
            }
        }
コード例 #12
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;
                }
            }
        }
コード例 #13
0
ファイル: TrendsToCashflow.cs プロジェクト: w1r2p1/GoblinBat
        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;
                }
            }
コード例 #14
0
ファイル: Consecutive.cs プロジェクト: blueysnow2/GoblinBat
        void OnReceiveDrawChart(object sender, SendConsecutive e)
        {
            int tShort, tLong, tMinute, trend;

            switch (strategics)
            {
            case TrendsInValuation _:
                tShort = tv.Short;
                tLong  = tv.Long;
                trend  = tv.Trend;

                if (GetCheckOnDate(e.Date, 0x5A0))
                {
                    Short.Pop();
                    Long.Pop();
                    Trend.Pop();
                }
                Trend.Push(Trend.Count > 0 ? EMA.Make(trend, Trend.Count, e.Price, Trend.Peek()) : EMA.Make(e.Price));
                tMinute = tv.AddtionalInterval;
                break;

            case TrendToCashflow _:
                tShort = tc.Short;
                tLong  = tc.Long;
                trend  = tc.Trend;

                if (GetCheckOnDate(e.Date, 0x5A0))
                {
                    Short.Pop();
                    Long.Pop();
                    Trend.Pop();
                }
                Trend.Push(Trend.Count > 0 ? EMA.Make(trend, Trend.Count, e.Price, Trend.Peek()) : EMA.Make(e.Price));
                tMinute = tc.Interval;
                break;

            case TrendsInStockPrices _:
                tShort = ts.Short;
                tLong  = ts.Long;
                trend  = ts.Trend;

                switch (ts)
                {
                case TrendsInStockPrices sp when sp.LongShort.Equals(LongShort.Minute) && sp.TrendType.Equals(Interface.Trend.Minute) || sp.LongShort.Equals(LongShort.Day) && sp.TrendType.Equals(Interface.Trend.Day):
                    if (GetCheckOnDate(e.Date, sp.LongShort.Equals(LongShort.Minute) && sp.TrendType.Equals(Interface.Trend.Minute) ? 1 : 0x5A0))
                    {
                        Short.Pop();
                        Long.Pop();
                        Trend.Pop();
                    }

                    break;

                case TrendsInStockPrices sp when sp.LongShort.Equals(LongShort.Day) && sp.TrendType.Equals(Interface.Trend.Minute):
                    if (GetCheckOnDate(e.Date, 1))
                        Trend.Pop();

                    if (GetCheckOnDate(e.Date, 0x5A0))
                    {
                        Short.Pop();
                        Long.Pop();
                    }

                    break;

                case TrendsInStockPrices sp when sp.LongShort.Equals(LongShort.Minute) && sp.TrendType.Equals(Interface.Trend.Day):
                    if (GetCheckOnDate(e.Date, 0x5A0))
                        Trend.Pop();

                    if (GetCheckOnDate(e.Date, 1))
                    {
                        Short.Pop();
                        Long.Pop();
                    }

                    break;
                }
                Trend.Push(Trend.Count > 0 ? EMA.Make(trend, Trend.Count, e.Price, Trend.Peek()) : EMA.Make(e.Price));
                tMinute = (int)ts.TrendType;
                break;

            case TrendFollowingBasicFutures _:
                if (GetCheckOnDate(e.Date, tf.Minute))
                {
                    Short.Pop();
                    Long.Pop();
                }
                tShort  = tf.Short;
                tLong   = tf.Long;
                tMinute = tf.Minute;
                break;

            case ScenarioAccordingToTrend _:
                tShort = st.Short;
                tLong  = st.Long;
                trend  = st.Trend;

                if (e.Date.Length > 6 && double.IsNaN(Compare) && Trend.Count > 0 && string.IsNullOrEmpty(st.Calendar) == false && (e.Date.Length == 8 ? e.Date.Substring(2) : e.Date.Substring(0, 6)).CompareTo(st.Calendar) >= 0)
                {
                    Compare = Trend.Pop();

                    if (int.TryParse(e.Date.Length == 8 ? e.Date.Substring(2, 4) : e.Date.Substring(0, 4), out int closest))
                    {
                        var baseDate = int.MaxValue;
                        var temp     = string.Empty;
                        var list     = new List <ConvertConsensus>(ho.Consensus.Item1);
                        list.AddRange(ho.Consensus.Item2);

                        foreach (var parse in list.OrderByDescending(o => o.Date))
                        {
                            if (int.TryParse(parse.Date.Substring(0, 5).Replace(".", string.Empty), out int date) && Math.Abs(date - closest) < baseDate)
                            {
                                baseDate = Math.Abs(date - closest);
                                temp     = parse.Date;
                            }
                        }
                        var estimate = new Security(temp, list, st).EstimateThePrice(e.Date, Compare);

                        if (estimate.Count > 3)
                        {
                            ho.EstimatedPrice = estimate;
                        }

                        else
                        {
                            return;
                        }
                    }
                    Trend.Clear();
                }
                if (GetCheckOnDate(e.Date, 0x5A0))
                {
                    Short.Pop();
                    Long.Pop();

                    if (double.IsNaN(Compare) && Trend.Count > 0)
                    {
                        Trend.Pop();
                    }
                }
                if (double.IsNaN(Compare))
                {
                    Trend.Push(Trend.Count > 0 ? EMA.Make(trend, Trend.Count, e.Price, Trend.Peek()) : EMA.Make(e.Price));
                }

                tMinute = st.IntervalInSeconds;
                break;

            default:
                return;
            }
            Short.Push(Short.Count > 0 ? EMA.Make(tShort, Short.Count, e.Price, Short.Peek()) : EMA.Make(e.Price));
            Long.Push(Long.Count > 0 ? EMA.Make(tLong, 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);

                switch (sender)
                {
                case OpenAPI.HoldingStocks os:
                    os.OnReceiveTrendsInPrices(e, gap, Trend.Peek());
                    break;

                case XingAPI.HoldingStocks xs:
                    xs.OnReceiveTrendsInPrices(e, gap, tMinute);
                    break;

                case HoldingStocks hs:
                    hs.OnReceiveTrendsInPrices(e, gap, popShort, popLong, hs.Code.Length == 6 ? (Trend.Count > 0 ? Trend.Peek() : CalculateTheEstimatedPrice(e.Date)) : tMinute);
                    break;
                }
            }
        }
コード例 #15
0
ファイル: Trading.cs プロジェクト: w1r2p1/GoblinBat
        private 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.MarginRate : e.Price), trend);
             *          break;
             *
             *      case "WU":
             *          quotes.SetWindingUp(trend);
             *          break;
             *  }
             *  if (GetTrend(trend.ToString()))
             *      quotes.SendClearingOrder(trend);
             * }
             * else if (specify.Reaction > 0)
             * {
             *  api.Volume += e.Volume;
             *
             *  if (api.OnReceiveBalance && 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(0, 99).ToString("D3")),
             *          AccNo = Array.Find(specify.Account, o => o.Substring(8, 2).Equals("31")),
             *          Code = specify.Code,
             *          OrdKind = 1,
             *          SlbyTP = trend > 0 ? "2" : "1",
             *          OrdTp = ((int)PurchaseInformation.OrderType.지정가).ToString(),
             *          Qty = 1,
             *          Price = price.ToString("F2"),
             *          OrgOrdNo = string.Empty
             *      });
             *      api.Volume = 0;
             *  }
             * }
             */
        }
コード例 #16
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;
                        }
                    }
                }
            }
        }
コード例 #17
0
ファイル: Consecutive.cs プロジェクト: w1r2p1/GoblinBat
        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;
                    }
                }
            }
        }