Exemplo n.º 1
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                RPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);

                switch (PriceType)
                {
                case "0":
                    CPrice = RPrice;
                    break;

                case "1":
                    CPrice = Math.Round(price.price3, RoundNum);
                    break;

                case "2":
                    CPrice = Math.Round(price.price5, RoundNum);
                    break;

                case "3":
                    CPrice = Math.Round(price.price7, RoundNum);
                    break;

                default:
                    CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                    break;
                }

                if (BPrice == CPrice)
                {
                    return;
                }
                if (HPrice < CPrice)
                {
                    HPrice = Math.Round(CPrice, RoundNum);
                }
                if (LPrice > CPrice)
                {
                    LPrice = Math.Round(CPrice, RoundNum);
                }

                PriceList.Insert(CPrice);

                if (!IsUse)
                {
                    return;
                }

                // //매수포지션 사용여부
                if (!IsBuyed)
                {
                    if (IsUseBuy)
                    {
                        //터치여부
                        if (!IsTouchedBasePrice)
                        {
                            if (PointsUtil.IsBreakThrough(BasePattern, BasePrice, PriceList))
                            {
                                IsTouchedBasePrice = true;
                                onStrategyTradeRuleHandler("터치", $"베이스 가격터치::현재가{CPrice}");
                            }
                        }
                        if (IsTouchedBasePrice && !IsBuyed)
                        {
                            //매도
                            if (Position == "1")
                            {
                                if (CPrice == BuyPrice)
                                {
                                    IsBuyed = true;
                                    SellBuy("진입", Position);
                                    onStrategyTradeRuleHandler("진입", $"매도진입::현재가{CPrice}");
                                }
                            }
                            //매수
                            if (Position == "2")
                            {
                                if (CPrice == BuyPrice)
                                {
                                    IsBuyed = true;
                                    SellBuy("진입", Position);
                                    onStrategyTradeRuleHandler("진입", $"매수진입::현재가{CPrice}");
                                }
                            }
                        }
                    }
                }
                if (IsBuyed && IsUseLosscut && !IsLosscuted && !IsRevenued)
                {
                    if (Position == "1")
                    {
                        if (RPrice == LosscutPrice)
                        {
                            IsLosscuted = true;
                            SellBuy("청산", "2");
                            onStrategyTradeRuleHandler("청산", $"매수청산::현재가{CPrice}");
                        }
                    }
                    //매수
                    if (Position == "2")
                    {
                        if (RPrice == LosscutPrice)
                        {
                            IsLosscuted = true;
                            SellBuy("청산", "1");
                            onStrategyTradeRuleHandler("청산", $"매도청산::현재가{CPrice}");
                        }
                    }
                }
                if (IsBuyed && IsUseRevenue && !IsRevenued && !IsLosscuted)
                {
                    if (Position == "1")
                    {
                        if (RPrice == RevenuePrice)
                        {
                            IsRevenued = true;
                            SellBuy("청산", "2");
                            onStrategyTradeRuleHandler("청산", $"매수청산::현재가{CPrice}");
                        }
                    }
                    //매수
                    if (Position == "2")
                    {
                        if (RPrice == RevenuePrice)
                        {
                            IsRevenued = true;
                            SellBuy("청산", "1");
                            onStrategyTradeRuleHandler("청산", $"매도청산::현재가{CPrice}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                onStrategyTradeRuleHandler("ERROR", ex.Message);
            }
            finally
            {
                BPrice = CPrice;
            }
        }
Exemplo n.º 2
0
        public override void Analysis(CurrentPrice price)
        {
            try
            {
                switch (PriceType)
                {
                case "0":
                    CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                    break;

                case "1":
                    CPrice = Math.Round(price.price3, RoundNum);
                    break;

                case "2":
                    CPrice = Math.Round(price.price5, RoundNum);
                    break;

                case "3":
                    CPrice = Math.Round(price.price7, RoundNum);
                    break;

                default:
                    CPrice = Math.Round(Convert.ToDouble(price.price), RoundNum);
                    break;
                }

                if (BPrice == CPrice)
                {
                    return;
                }
                if (HPrice < CPrice)
                {
                    HPrice = Math.Round(CPrice, RoundNum);
                }
                if (LPrice > CPrice)
                {
                    LPrice = Math.Round(CPrice, RoundNum);
                }
                PriceList.Insert(CPrice);
                if (!IsUse)
                {
                    return;
                }

                // //매수포지션 사용여부
                if (!IsBuyDone)
                {
                    if (IsUseP2)
                    {
                        //터치여부
                        if (!IsTouchedP2)
                        {
                            if (IsBaseLine)
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P2BuyPrice1) == P2BuyPattern)
                                {
                                    IsTouchedP2 = true;
                                    SellBuy("가격패턴매칭", "매수");
                                }
                            }
                            else
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P2BuyPrice1, P2BuyPrice2) == P2BuyPattern)
                                {
                                    IsTouchedP2 = true;
                                    SellBuy("가격패턴매칭", "매수");
                                }
                            }
                        }
                        if (IsTouchedP2)
                        {
                            //매수포지션 진입
                            IsBuyDone = true;
                            BuyPrice  = CPrice;
                            Position  = "매수";
                            SellBuy("신규진입", "매수");
                        }
                    }
                }
                //매도포지션 사용여부
                if (!IsBuyDone)
                {
                    if (IsUseP1)
                    {
                        //터치여부
                        if (!IsTouchedP1)
                        {
                            if (IsBaseLine)
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P1BuyPrice1) == P1BuyPattern)
                                {
                                    IsTouchedP1 = true;
                                    SellBuy("가격패턴매칭", "매도");
                                }
                            }
                            else
                            {
                                if (PointsUtil.GetUpDownPattern(PriceList, P1BuyPrice1, P1BuyPrice2) == P1BuyPattern)
                                {
                                    IsTouchedP1 = true;
                                    SellBuy("가격패턴매칭", "매도");
                                }
                            }
                        }
                        if (IsTouchedP1)
                        {
                            IsBuyDone = true;
                            BuyPrice  = CPrice;
                            Position  = "매도";
                            SellBuy("신규진입", "매도");
                        }
                    }
                }
                if (!IsBuyDone)
                {
                    return;
                }

                if (Position == "매수" && IsMinimumRevenue2 && MinimumRevenuePrice2 > 0)
                {
                    if (MinimumRevenuePrice2 < CPrice)
                    {
                        return;
                    }
                }
                if (Position == "매도" && IsMinimumRevenue1 && MinimumRevenuePrice1 > 0)
                {
                    if (MinimumRevenuePrice1 > CPrice)
                    {
                        return;
                    }
                }

                //손실체크
                if (Position == "매수")
                {
                    if (PointsUtil.IsBreakThrough(P2LosscutPattern1, P2LosscutPrice1, PriceList))
                    {
                        InitRule();
                        SellBuy("손실청산1", "매도");
                    }

                    if (P2LosscutPrice2 > 0 && P2LosscutPrice2 >= CPrice)
                    {
                        //매도진입
                        InitRule();
                        SellBuy("손실청산2", "매도");
                    }
                }
                if (Position == "매도")
                {
                    if (PointsUtil.IsBreakThrough(P1LosscutPattern1, P1LosscutPrice1, PriceList))
                    {
                        InitRule();
                        SellBuy("손실청산1", "매수");
                    }

                    if (P1LosscutPrice2 > 0 && P1LosscutPrice2 <= CPrice)
                    {
                        //매수진입
                        InitRule();
                        SellBuy("손실청산2", "매수");
                    }
                }

                //수익체크
                if (IsUseRevenue1)
                {
                    double revenuePrice = Math.Round(GetRevenuePrice1(), RoundNum);
                    if (revenuePrice == 0)
                    {
                        return;
                    }
                    if (Position == "매수")
                    {
                        if (revenuePrice <= CPrice)
                        {
                            //매도진입
                            InitRule();
                            SellBuy("수익청산", "매도");
                        }
                    }
                    if (Position == "매도")
                    {
                        if (revenuePrice >= CPrice)
                        {
                            //매수진입
                            InitRule();
                            SellBuy("수익청산", "매수");
                        }
                    }
                }
                if (IsUseRevenue2)
                {
                    double revenuePrice = Math.Round(GetRevenuePrice2(), RoundNum);
                    if (revenuePrice == 0)
                    {
                        return;
                    }
                    if (Position == "매수")
                    {
                        if (revenuePrice <= CPrice)
                        {
                            //매도진입
                            InitRule();
                            SellBuy("수익청산", "매도");
                        }
                    }
                    if (Position == "매도")
                    {
                        if (revenuePrice >= CPrice)
                        {
                            //매수진입
                            InitRule();
                            SellBuy("수익청산", "매수");
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                BPrice = CPrice;
            }
        }