Beispiel #1
0
        private void ThreeGetClick(object sender, EventArgs e)
        {
            //ThreeData d = this.GetThreeData("0001", Int32.Parse(this.textBox1.Text), Int32.Parse(this.textBox2.Text));
            string    code      = "0001";
            int       checkDate = 20190814;
            ThreeData d         = GetThreeData(code, checkDate, 2);

            d.Print(); // TODO for check

            //string buyRule = "IsPlus&IsAvgGolden&IsIncludeTime 930,1430&IsUpperThanDayStartPrice&IsAvg5ChangeToUp&IsAvg120Rising -10,-5";

            ArrayList ordersArray = new ArrayList();

            HashSet <string> ruleSet = BuyRule.Pattern.GetMassRule();

            Console.WriteLine("[CHECK] RULE TOTAL : " + ruleSet.Count());

            foreach (string buyRule in ruleSet)
            {
                Orders orders = new Orders();
                Check.CheckThreeData(d, buyRule, orders);
                if (orders.orderList.Count > 0)
                {
                    orders.rule = buyRule;
                    orders.date = Util.GetDateNow();
                    ordersArray.Add(orders);
                    //orders.Evaluate();
                }
            }

            Console.WriteLine("INSERT TO EVALUATE START");
            dao.InsertEvaluateData(ordersArray);
            Console.WriteLine("INSERT TO EVALUATE END");
        }
Beispiel #2
0
        public static void CheckThreeData(ThreeData d, String buyRule, Orders orders)
        {
            if (d.array == null)
            {
                return;
            }

            orders.checkTotal += 1;
            Order order = null;

            for (int i = d.dayStartIdx; i < d.array.Length; i++)
            {
                int checkIdx = i;

                if (order == null)
                {
                    order = BuyCheck(d, i, buyRule);
                }
                else
                {
                    order = SellCheck(d, i, order);

                    if (order.status != "S")
                    {
                        orders.AddOrder(order);
                        order = null;
                    }
                }
            }
        }
Beispiel #3
0
        private static Order SellCheck(ThreeData data, int checkIdx, Order order)
        {
            float lossCut      = 3;
            float lossCutPrice = order.buyPrice - (order.buyPrice * lossCut / 100);

            float profitCut      = 3;
            float profitCutPrice = order.buyPrice + (order.buyPrice * profitCut / 100);

            if (data.array[checkIdx] != null)
            {
                int currentPrice = (data.array[checkIdx].startprice + data.array[checkIdx].endprice) / 2;
                if (lossCutPrice >= currentPrice)
                {
                    //Console.WriteLine("LOSSCUT CURRENT PRICE : " + lossCutPrice);
                    order.status    = "F";
                    order.sellDate  = data.array[checkIdx].date;
                    order.sellTime  = data.array[checkIdx].time;
                    order.sellPrice = currentPrice;
                }
                else if (lossCutPrice >= data.array[checkIdx].endprice)
                {
                    order.status    = "F";
                    order.sellDate  = data.array[checkIdx].date;
                    order.sellTime  = data.array[checkIdx].time;
                    order.sellPrice = data.array[checkIdx].endprice;
                }
                else if (lossCutPrice >= data.array[checkIdx].lowprice)
                {
                    order.status    = "F";
                    order.sellDate  = data.array[checkIdx].date;
                    order.sellTime  = data.array[checkIdx].time;
                    order.sellPrice = data.array[checkIdx].lowprice;
                }
                else if (profitCutPrice <= data.array[checkIdx].startprice)
                {
                    order.status    = "W";
                    order.sellDate  = data.array[checkIdx].date;
                    order.sellTime  = data.array[checkIdx].time;
                    order.sellPrice = data.array[checkIdx].startprice;
                }
                else if (profitCutPrice <= data.array[checkIdx].endprice)
                {
                    order.status    = "W";
                    order.sellDate  = data.array[checkIdx].date;
                    order.sellTime  = data.array[checkIdx].time;
                    order.sellPrice = data.array[checkIdx].endprice;
                }
                else if (profitCutPrice <= data.array[checkIdx].startprice)
                {
                    order.status    = "W";
                    order.sellDate  = data.array[checkIdx].date;
                    order.sellTime  = data.array[checkIdx].time;
                    order.sellPrice = data.array[checkIdx].highprice;
                }
            }
            return(order);
        }
Beispiel #4
0
        private void SingleRuleSimulate(int startDate, int endDate, string code, string buyRule, Orders orders)
        {
            ThreeData d = GetThreeData(code, startDate, 2);

            Check.CheckThreeData(d, buyRule, orders);
            if (d.endDate < endDate)
            {
                SingleRuleSimulate(d.endDate, endDate, code, buyRule, orders);
            }
        }
Beispiel #5
0
        private ThreeData GetThreeData(string code, int date, int dayCount)
        {
            ThreeData d = new ThreeData();

            Candle[] dbData = dao.GetThreeDataFromDB(code, date, dayCount);
            if (dbData != null && dbData.Length > 0)
            {
                d.AddThreeArray(dbData);
                d.CreateAvgData(0);
            }
            return(d);
        }
Beispiel #6
0
        private void UpdateAvgData(string code, int startDate, int endDate)
        {
            ThreeData d = GetThreeData(code, startDate, 2);

            if (d.array != null)
            {
                control.Print("Updated average data from " + startDate + " to " + endDate, code);
                dao.InsertThreeData(new ArrayList(d.array));
                if (d.endDate != 0 && d.startDate != d.endDate && d.endDate <= endDate)
                {
                    UpdateAvgData(code, d.endDate, endDate);
                }
            }
        }
Beispiel #7
0
 private static Order BuyCheck(ThreeData data, int checkIdx, string ruleString)
 {
     if (BuyRule.Judge(data, checkIdx, ruleString) == false)
     {
         return(null);
     }
     else
     {
         Order order = new Order();
         order.status   = "S";
         order.code     = data.array[checkIdx].code;
         order.buyDate  = data.array[checkIdx].date;
         order.buyTime  = data.array[checkIdx].time;
         order.buyPrice = data.array[checkIdx].endprice;
         return(order);
     }
 }
Beispiel #8
0
        public static Boolean Judge(ThreeData data, int chkIndex, string ruleString)
        {
            Boolean result = false;

            char[] charsToTrim = { '\r', '\n' };
            string trimmed     = ruleString.Trim(charsToTrim);

            string[] rules = ruleString.Split('.');
            foreach (string rule in rules)
            {
                string[] conditions = rule.Split('&');
                foreach (string condition in conditions)
                {
                    if (data.array[chkIndex] != null && !String.IsNullOrWhiteSpace(condition))
                    {
                        // single candle check
                        if ("IsPlus".Equals(condition))
                        {
                            result = data.array[chkIndex].IsPlus();
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if ("IsAvg5UpperThanAvg20".Equals(condition))
                        {
                            result = data.array[chkIndex].IsAvg5UpperThanAvg20();
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if ("IsAvg20UpperThanAvg120".Equals(condition))
                        {
                            result = data.array[chkIndex].IsAvg20UpperThanAvg120();
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if ("IsAvgGolden".Equals(condition))
                        {
                            result = data.array[chkIndex].IsAvgGolden();
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if ("IsIncludeTime".StartsWith(condition))
                        {
                            string[] ps = condition.Replace("IsIncludeTime", "").TrimStart().Split(',');
                            result = data.array[chkIndex].IsIncludeTime(Int32.Parse(ps[0]), Int32.Parse(ps[1]));
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if ("IsExcludeTime".StartsWith(condition))
                        {
                            string[] ps = condition.Replace("IsExcludeTime", "").TrimStart().Split(',');
                            result = data.array[chkIndex].IsIncludeTime(Int32.Parse(ps[0]), Int32.Parse(ps[1]));
                            if (result == false)
                            {
                                return(false);
                            }
                        }

                        // multiple candle check
                        else if ("IsUpperThanDayStartPrice".Equals(condition))
                        {
                            result = data.IsUpperThanDayStartPrice(chkIndex);
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if ("IsAvg5ChangeToUp".Equals(condition))
                        {
                            result = data.IsAvg5ChangeToUp(chkIndex);
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if ("IsVolumeRising".Equals(condition))
                        {
                            result = data.IsVolumeRising(chkIndex);
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if (condition.StartsWith("IsAvg5Rising"))
                        {
                            string[] ps = condition.Replace("IsAvg5Rising", "").TrimStart().Split(',');
                            result = data.IsAvg5Rising(Int32.Parse(ps[0]), Int32.Parse(ps[1]), chkIndex);
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if (condition.StartsWith("IsAvg20Rising"))
                        {
                            string[] ps = condition.Replace("IsAvg20Rising", "").TrimStart().Split(',');
                            result = data.IsAvg20Rising(Int32.Parse(ps[0]), Int32.Parse(ps[1]), chkIndex);
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                        else if (condition.StartsWith("IsAvg120Rising"))
                        {
                            string[] ps = condition.Replace("IsAvg120Rising", "").TrimStart().Split(',');
                            result = data.IsAvg120Rising(Int32.Parse(ps[0]), Int32.Parse(ps[1]), chkIndex);
                            if (result == false)
                            {
                                return(false);
                            }
                        }
                    }
                }

                if (result == true)
                {
                    return(true);
                }
            }

            return(result);
        }