예제 #1
0
파일: Program.cs 프로젝트: wushian/MLEA
        static void Main(string[] args)
        {
            System.Console.Write("File Date: ");
            System.Console.WriteLine(System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location));

            try
            {
                Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(new Microsoft.Practices.ServiceLocation.ServiceLocatorProvider(
                delegate()
                {
                    return new EmptyServiceProvider();
                }));

                //Feng.Utils.SecurityHelper.SelectAutomaticServer();

                java.lang.System.setOut(new PrintStream(new ByteArrayOutputStream()));
                java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("GMT"));

                string cmdSymbol = "EURUSD";
                if (args.Length == 2)
                {
                    if (args[0] == "-s")
                    {
                        cmdSymbol = args[1];
                    }
                }
                //if (args.Length > 0)
                //{
                //    int n = ea.ReadConfig(args);
                //    if (n == 1)
                //        return;
                //}

                //DbUtils.CompensateMissingDateAll();
                //DbUtils.CheckDataIntegrityAll();
                //DbUtils.CheckDateIntegrityOfCount();
                //DbUtils.CheckDbZeroValues();
                //DbUtils.ConvertHpdataFromSaturday2Monday();
                //TestTool.CheckMtData("EURUSD_M1");
                //TestTool.CheckMtHpData("EURUSD");
                //DbUtils.ImportToDbAll("EURUSD", "M30");
                //DbUtils.CalculateUSDX();
                //DbUtils.GeneratePeriodData("USDX", "D1", 0);
                //DbUtils.GenerateIndicators("USDX", "D1");
                //return;
                //DbUtils.GenerateRandomData("EURUSD");

                //TestParameters2.InitParameters("EURUSD", "M15", 1);
                //string updateHpWhere = string.Format("TIME >= {0} AND TIME < {1} AND Time % 1800 = 0",
                //    WekaUtils.GetTimeFromDate(new DateTime(2000, 1, 1)), WekaUtils.GetTimeFromDate(new DateTime(2013, 1, 1)));
                //DbUtils.UpdateAllHp3("EURUSD", updateHpWhere);

                //WekaEA.WekaEA2 wekaEA2 = new WekaEA.WekaEA2();
                //wekaEA2.Init("EURUSD");
                //wekaEA2.RunTool("ImportDB");
                //WekaEA.WekaEA2.SimulateMt("EURUSD");
                //return;

                //SimulateIncrementTest();

                //TestTool.GenerateConsoleCCs();

                //TestTool.CheckHpData();
                //TestTool.GetResultCost("f:\\Forex\\console.2000-2012.USDCHF.w8.txt", "d:\\result8.txt");
                //TestTool.ParseMtReport4Consecutive();
                //TestTool.TestMultiClassifierResult();

                //DbUtils.CheckDbCountToSame("D1");

                //TestTool.ReorderEaOrderTxt(string.Format("f:\\forex\\TestDebug\\ea_order_{0}.txt", TestParameters2.CandidateParameter.MainSymbol),
                //    "f:\\forex\\TestDebug\\ea_order.txt", 1);
                //TestTool.GenerateHpAccordCloseTime("USDCHF");
                //TestTool.ConvertHpAccordCloseTime();
                //DbUtils.GeneratePeriodData("IF9999", "D1", TestParameters2.HourAhead);
                //DbUtils.GenerateIndicators("AUDUSD", "D1");
                //TestTool.ParseDetailDealLog(string.Format("{0}_ccScores_w{1}", TestParameters2.CandidateParameter.MainSymbol, TestParameters2.lastWeek));

                //string symbol = cmdSymbol;

                TestTool.ParseTotalResult("e:\\total_result.txt", "e:\\ff", true);
                //foreach (var s in Parameters.AllSymbolsFull)
                //{
                //    string fileName = string.Format("\\\\192.168.0.10\\f$\\Forex\\Test_{0}\\total_result.txt", s);
                //    if (System.IO.File.Exists(fileName))
                //        TestTool.ParseTotalResult(fileName, s);
                //}

                TaLibTest taLibTest = new TaLibTest();
                TestManager tm = new TestManager();
                TxtTest txtTest = new TxtTest();

                foreach (string s in new string[] { "EURUSD" })//"GBPUSD", "EURUSD", "USDCHF","AUDUSD", "USDJPY", "USDCAD"
                {
                    foreach (string p in new string[] { "M15" })//"M5", "M15", "M30", "H1", "H4", "D1" })
                    {
                        TestParameters2.InitParameters(s, p, 1);
                        TestParameters.TestName = "Test_" + s;

                        System.IO.File.Delete(TestParameters.GetBaseFilePath("console.txt"));
                        foreach (string s1 in Directory.GetFiles(TestParameters.BaseDir, "ea_order*.txt"))
                            System.IO.File.Delete(s1);

                        //TxtTest.SimulateEaOrders();

                        HpData.Instance.GenerateHpDataToTxt(TestParameters2.CandidateParameter.MainSymbol, TestParameters2.CandidateParameter.MainPeriod);

                        bool[,] selectedTpSl = new bool[20, 20];
                        for (int i = 0; i < 20; i += 1)
                            for (int j = 0; j < 20; j += 1)
                                selectedTpSl[i, j] = false;

                        bool onlyOneTime = false;

                        for (int t = 0; t < 1; ++t)
                        {
                            //TestParameters2.TrainStartTime = (new DateTime(2010, 1, 1)).AddMonths(12 * t);
                            //TestParameters2.TrainEndTime = (new DateTime(2010, 1, 1)).AddMonths(12 * (t + 1));
                            //if (TestParameters2.TrainStartTime > new DateTime(2012, 8, 1))
                            //    break;

                            string resultFileName = TestParameters.GetBaseFilePath("total_result.txt");
                            var alreadyResults = TestTool.ParseTotalResult(resultFileName, null);

                            for (int i = 9; i >= 2; i -= 1)
                            {
                                for (int j = 19; j >= 2; j -= 1)
                                {
                                    if (alreadyResults[i, j] != -1)
                                        continue;

                                    if (!onlyOneTime)
                                    {
                                        TestParameters2.slStart = i;
                                        TestParameters2.slCount = i + 1;
                                        TestParameters2.tpStart = j;
                                        TestParameters2.tpCount = j + 1;
                                    }

                                    using (StreamWriter sw = new StreamWriter(resultFileName, true))
                                    {
                                        sw.WriteLine(string.Format("{0},{1},{2},{3}",
                                               TestParameters2.slStart, TestParameters2.slCount,
                                               TestParameters2.tpStart, TestParameters2.tpCount));

                                        if (!(args.Length >= 1 && args[0] == "-t"))
                                        {
                                            foreach (string s1 in Directory.GetFiles(TestParameters.BaseDir, "IncrementTest_*.txt"))
                                                System.IO.File.Delete(s1);
                                            foreach (string s1 in Directory.GetFiles(TestParameters.BaseDir, "*.arff"))
                                                System.IO.File.Delete(s1);
                                        }

                                        try
                                        {
                                            TestParameters2.OutputParameters();

                                            var s0 = tm.BuildHpProbDeals();
                                            sw.WriteLine(s0);

                                            var s1 = tm.BuildPricePatternDeals();
                                            sw.WriteLine(s1);

                                            var s2 = taLibTest.BuildCandlePatternDeals();
                                            sw.WriteLine(s2);

                                            //foreach (string w in new string[] { "1" })
                                            //{
                                            //    TestParameters2.lastWeek = w;
                                            //    try
                                            //    {
                                            //        CCScoreData.Instance.GenerateData(s, Convert.ToInt32(w));
                                            //    }
                                            //    catch (Exception ex)
                                            //    {
                                            //        WekaUtils.Instance.WriteLog(ex.Message);
                                            //    }

                                            //    CCScoreData.Instance.GenerateDataToTxt(TestParameters2.CandidateParameter.MainSymbol, TestParameters2.lastWeek);
                                            //    txtTest.BuildCCScoreDeals();
                                            //}

                                            WekaUtils.Instance.DeInit();

                                            string result;
                                            if (selectedTpSl[i, j] || onlyOneTime)
                                            {
                                                if (selectedTpSl[i, j])
                                                {
                                                    sw.WriteLine(string.Format("{0} select {1},{2}",
                                                        TestParameters2.TrainStartTime.ToString(Parameters.DateTimeFormat), i, j));
                                                }
                                                result = txtTest.SimulateAccordDealLog(true);
                                            }
                                            else
                                            {
                                                result = txtTest.SimulateAccordDealLog(false);
                                            }
                                            sw.WriteLine(result);
                                            sw.Flush();

                                            string profitString = WekaUtils.GetSubstring(result, "ProfitFactor = ");
                                            double profitFactor = 0;
                                            if (!string.IsNullOrEmpty(profitString))
                                                profitFactor = Convert.ToDouble(profitString);
                                            if (profitFactor > 1.1)
                                                selectedTpSl[i, j] = true;
                                            else
                                                selectedTpSl[i, j] = false;

                                            if (!onlyOneTime)
                                            {
                                                foreach (string is1 in Directory.GetFiles(TestParameters.BaseDir, "IncrementTest_*.txt"))
                                                {
                                                    string is2 = string.Format("{0}_{1}_{2}.txt", is1.Replace(".txt", "").Replace("IncrementTest_", "IncrementTest2_"), i, j);
                                                    System.IO.File.Delete(is2);
                                                    System.IO.File.Move(is1, is2);
                                                }

                                                WekaUtils.Instance.DeInit();
                                                foreach (string is1 in Directory.GetFiles(TestParameters.BaseDir, "console.txt"))
                                                {
                                                    string is2 = string.Format("{0}_{1}_{2}.txt", is1.Replace(".txt", ""), i, j);
                                                    System.IO.File.Delete(is2);
                                                    System.IO.File.Move(is1, is2);
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            WekaUtils.Instance.WriteLog(ex.Message);
                                            WekaUtils.Instance.WriteLog(ex.StackTrace);
                                        }

                                        TestManager.Clear();

                                        if (onlyOneTime)
                                            break;
                                    }
                                    if (onlyOneTime)
                                        break;
                                }

                                HpData.Instance.Clear();
                                DbData.Instance.Clear();
                                taLibTest.Clear();
                                WekaData.ClearTemplates();
                                CCScoreData.Instance.Clear();
                            }
                        }
                        TxtTest.SortEaOrders();
                    }
                }

                //foreach (string s in new string[] { "GBPUSD", "AUDUSD", "USDJPY", "USDCAD", "USDCHF", "EURUSD" })
                //{
                //    TestParameters.TestName = "Test_" + s;
                //    TestParameters2.InitParameters(s, "M5", 1);

                //    foreach (string w in new string[] { "1" })
                //    {
                //        TestParameters2.lastWeek = w;
                //        try
                //        {
                //            CCScoreData.Instance.GenerateData(s, Convert.ToInt32(w));
                //        }
                //        catch (Exception ex)
                //        {
                //            WekaUtils.Instance.WriteLog(ex.Message);
                //        }
                //    }

                //    foreach (string p in new string[] { "M5", "M15", "M30", "H1", "H4", "D1" })
                //    {
                //        TestParameters.TestName = "Test_" + s;

                //        if (p == "M5")
                //            TestParameters2.MaxTrainSize = TestParameters2.MinTrainSize = 5;
                //        else
                //            TestParameters2.MaxTrainSize = TestParameters2.MinTrainSize = 2;

                //        TestParameters2.InitParameters(s, p, 1);
                //        //TestParameters2.tpCount = TestParameters2.slCount = 20;

                //        //TestParameters2.InitParameters(symbol, "D1", 4);
                //        //TestParameters2.tpCount = TestParameters2.slCount = 10;
                //        //TestParameters2.tpStart = TestParameters2.slStart = 9;

                //        TestParameters2.OutputParameters();

                //        foreach (string w in new string[] { "1" })
                //        {
                //            TestParameters2.lastWeek = w;

                //            CCScoreData.Instance.GenerateDataToTxt(TestParameters2.CandidateParameter.MainSymbol, TestParameters2.lastWeek);
                //            txtTest.BuildCCScoreDeals();
                //        }
                //    }
                //}

                ///////////////////////////////////////////////////////////////////////////////////
                WaitForThreads();
                //Feng.Utils.SecurityHelper.DeselectAutomaticServer();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                System.Console.WriteLine(ex.StackTrace);
                System.Console.ReadLine();
            }

            System.Console.WriteLine("End");
            System.Console.Beep();

            ReadLine(60000);
        }
예제 #2
0
        static void Main(string[] args)
        {
            System.Console.Write("File Date: ");
            System.Console.WriteLine(System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location));

            try
            {
                Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(new Microsoft.Practices.ServiceLocation.ServiceLocatorProvider(
                                                                                          delegate()
                {
                    return(new EmptyServiceProvider());
                }));

                //Feng.Utils.SecurityHelper.SelectAutomaticServer();

                java.lang.System.setOut(new PrintStream(new ByteArrayOutputStream()));
                java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("GMT"));

                string cmdSymbol = "EURUSD";
                if (args.Length == 2)
                {
                    if (args[0] == "-s")
                    {
                        cmdSymbol = args[1];
                    }
                }
                //if (args.Length > 0)
                //{
                //    int n = ea.ReadConfig(args);
                //    if (n == 1)
                //        return;
                //}

                //DbUtils.CompensateMissingDateAll();
                //DbUtils.CheckDataIntegrityAll();
                //DbUtils.CheckDateIntegrityOfCount();
                //DbUtils.CheckDbZeroValues();
                //DbUtils.ConvertHpdataFromSaturday2Monday();
                //TestTool.CheckMtData("EURUSD_M1");
                //TestTool.CheckMtHpData("EURUSD");
                //DbUtils.ImportToDbAll("EURUSD", "M30");
                //DbUtils.CalculateUSDX();
                //DbUtils.GeneratePeriodData("USDX", "D1", 0);
                //DbUtils.GenerateIndicators("USDX", "D1");
                //return;
                //DbUtils.GenerateRandomData("EURUSD");

                //TestParameters2.InitParameters("EURUSD", "M15", 1);
                //string updateHpWhere = string.Format("TIME >= {0} AND TIME < {1} AND Time % 1800 = 0",
                //    WekaUtils.GetTimeFromDate(new DateTime(2000, 1, 1)), WekaUtils.GetTimeFromDate(new DateTime(2013, 1, 1)));
                //DbUtils.UpdateAllHp3("EURUSD", updateHpWhere);

                //WekaEA.WekaEA2 wekaEA2 = new WekaEA.WekaEA2();
                //wekaEA2.Init("EURUSD");
                //wekaEA2.RunTool("ImportDB");
                //WekaEA.WekaEA2.SimulateMt("EURUSD");
                //return;

                //SimulateIncrementTest();

                //TestTool.GenerateConsoleCCs();

                //TestTool.CheckHpData();
                //TestTool.GetResultCost("f:\\Forex\\console.2000-2012.USDCHF.w8.txt", "d:\\result8.txt");
                //TestTool.ParseMtReport4Consecutive();
                //TestTool.TestMultiClassifierResult();

                //DbUtils.CheckDbCountToSame("D1");

                //TestTool.ReorderEaOrderTxt(string.Format("f:\\forex\\TestDebug\\ea_order_{0}.txt", TestParameters2.CandidateParameter.MainSymbol),
                //    "f:\\forex\\TestDebug\\ea_order.txt", 1);
                //TestTool.GenerateHpAccordCloseTime("USDCHF");
                //TestTool.ConvertHpAccordCloseTime();
                //DbUtils.GeneratePeriodData("IF9999", "D1", TestParameters2.HourAhead);
                //DbUtils.GenerateIndicators("AUDUSD", "D1");
                //TestTool.ParseDetailDealLog(string.Format("{0}_ccScores_w{1}", TestParameters2.CandidateParameter.MainSymbol, TestParameters2.lastWeek));

                //string symbol = cmdSymbol;

                TestTool.ParseTotalResult("e:\\total_result.txt", "e:\\ff", true);
                //foreach (var s in Parameters.AllSymbolsFull)
                //{
                //    string fileName = string.Format("\\\\192.168.0.10\\f$\\Forex\\Test_{0}\\total_result.txt", s);
                //    if (System.IO.File.Exists(fileName))
                //        TestTool.ParseTotalResult(fileName, s);
                //}

                TaLibTest   taLibTest = new TaLibTest();
                TestManager tm        = new TestManager();
                TxtTest     txtTest   = new TxtTest();

                foreach (string s in new string[] { "EURUSD" })  //"GBPUSD", "EURUSD", "USDCHF","AUDUSD", "USDJPY", "USDCAD"
                {
                    foreach (string p in new string[] { "M15" }) //"M5", "M15", "M30", "H1", "H4", "D1" })
                    {
                        TestParameters2.InitParameters(s, p, 1);
                        TestParameters.TestName = "Test_" + s;

                        System.IO.File.Delete(TestParameters.GetBaseFilePath("console.txt"));
                        foreach (string s1 in Directory.GetFiles(TestParameters.BaseDir, "ea_order*.txt"))
                        {
                            System.IO.File.Delete(s1);
                        }

                        //TxtTest.SimulateEaOrders();

                        HpData.Instance.GenerateHpDataToTxt(TestParameters2.CandidateParameter.MainSymbol, TestParameters2.CandidateParameter.MainPeriod);

                        bool[,] selectedTpSl = new bool[20, 20];
                        for (int i = 0; i < 20; i += 1)
                        {
                            for (int j = 0; j < 20; j += 1)
                            {
                                selectedTpSl[i, j] = false;
                            }
                        }

                        bool onlyOneTime = false;

                        for (int t = 0; t < 1; ++t)
                        {
                            //TestParameters2.TrainStartTime = (new DateTime(2010, 1, 1)).AddMonths(12 * t);
                            //TestParameters2.TrainEndTime = (new DateTime(2010, 1, 1)).AddMonths(12 * (t + 1));
                            //if (TestParameters2.TrainStartTime > new DateTime(2012, 8, 1))
                            //    break;

                            string resultFileName = TestParameters.GetBaseFilePath("total_result.txt");
                            var    alreadyResults = TestTool.ParseTotalResult(resultFileName, null);

                            for (int i = 9; i >= 2; i -= 1)
                            {
                                for (int j = 19; j >= 2; j -= 1)
                                {
                                    if (alreadyResults[i, j] != -1)
                                    {
                                        continue;
                                    }

                                    if (!onlyOneTime)
                                    {
                                        TestParameters2.slStart = i;
                                        TestParameters2.slCount = i + 1;
                                        TestParameters2.tpStart = j;
                                        TestParameters2.tpCount = j + 1;
                                    }

                                    using (StreamWriter sw = new StreamWriter(resultFileName, true))
                                    {
                                        sw.WriteLine(string.Format("{0},{1},{2},{3}",
                                                                   TestParameters2.slStart, TestParameters2.slCount,
                                                                   TestParameters2.tpStart, TestParameters2.tpCount));

                                        if (!(args.Length >= 1 && args[0] == "-t"))
                                        {
                                            foreach (string s1 in Directory.GetFiles(TestParameters.BaseDir, "IncrementTest_*.txt"))
                                            {
                                                System.IO.File.Delete(s1);
                                            }
                                            foreach (string s1 in Directory.GetFiles(TestParameters.BaseDir, "*.arff"))
                                            {
                                                System.IO.File.Delete(s1);
                                            }
                                        }

                                        try
                                        {
                                            TestParameters2.OutputParameters();

                                            var s0 = tm.BuildHpProbDeals();
                                            sw.WriteLine(s0);

                                            var s1 = tm.BuildPricePatternDeals();
                                            sw.WriteLine(s1);

                                            var s2 = taLibTest.BuildCandlePatternDeals();
                                            sw.WriteLine(s2);

                                            //foreach (string w in new string[] { "1" })
                                            //{
                                            //    TestParameters2.lastWeek = w;
                                            //    try
                                            //    {
                                            //        CCScoreData.Instance.GenerateData(s, Convert.ToInt32(w));
                                            //    }
                                            //    catch (Exception ex)
                                            //    {
                                            //        WekaUtils.Instance.WriteLog(ex.Message);
                                            //    }

                                            //    CCScoreData.Instance.GenerateDataToTxt(TestParameters2.CandidateParameter.MainSymbol, TestParameters2.lastWeek);
                                            //    txtTest.BuildCCScoreDeals();
                                            //}

                                            WekaUtils.Instance.DeInit();

                                            string result;
                                            if (selectedTpSl[i, j] || onlyOneTime)
                                            {
                                                if (selectedTpSl[i, j])
                                                {
                                                    sw.WriteLine(string.Format("{0} select {1},{2}",
                                                                               TestParameters2.TrainStartTime.ToString(Parameters.DateTimeFormat), i, j));
                                                }
                                                result = txtTest.SimulateAccordDealLog(true);
                                            }
                                            else
                                            {
                                                result = txtTest.SimulateAccordDealLog(false);
                                            }
                                            sw.WriteLine(result);
                                            sw.Flush();

                                            string profitString = WekaUtils.GetSubstring(result, "ProfitFactor = ");
                                            double profitFactor = 0;
                                            if (!string.IsNullOrEmpty(profitString))
                                            {
                                                profitFactor = Convert.ToDouble(profitString);
                                            }
                                            if (profitFactor > 1.1)
                                            {
                                                selectedTpSl[i, j] = true;
                                            }
                                            else
                                            {
                                                selectedTpSl[i, j] = false;
                                            }

                                            if (!onlyOneTime)
                                            {
                                                foreach (string is1 in Directory.GetFiles(TestParameters.BaseDir, "IncrementTest_*.txt"))
                                                {
                                                    string is2 = string.Format("{0}_{1}_{2}.txt", is1.Replace(".txt", "").Replace("IncrementTest_", "IncrementTest2_"), i, j);
                                                    System.IO.File.Delete(is2);
                                                    System.IO.File.Move(is1, is2);
                                                }

                                                WekaUtils.Instance.DeInit();
                                                foreach (string is1 in Directory.GetFiles(TestParameters.BaseDir, "console.txt"))
                                                {
                                                    string is2 = string.Format("{0}_{1}_{2}.txt", is1.Replace(".txt", ""), i, j);
                                                    System.IO.File.Delete(is2);
                                                    System.IO.File.Move(is1, is2);
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            WekaUtils.Instance.WriteLog(ex.Message);
                                            WekaUtils.Instance.WriteLog(ex.StackTrace);
                                        }

                                        TestManager.Clear();

                                        if (onlyOneTime)
                                        {
                                            break;
                                        }
                                    }
                                    if (onlyOneTime)
                                    {
                                        break;
                                    }
                                }

                                HpData.Instance.Clear();
                                DbData.Instance.Clear();
                                taLibTest.Clear();
                                WekaData.ClearTemplates();
                                CCScoreData.Instance.Clear();
                            }
                        }
                        TxtTest.SortEaOrders();
                    }
                }

                //foreach (string s in new string[] { "GBPUSD", "AUDUSD", "USDJPY", "USDCAD", "USDCHF", "EURUSD" })
                //{
                //    TestParameters.TestName = "Test_" + s;
                //    TestParameters2.InitParameters(s, "M5", 1);

                //    foreach (string w in new string[] { "1" })
                //    {
                //        TestParameters2.lastWeek = w;
                //        try
                //        {
                //            CCScoreData.Instance.GenerateData(s, Convert.ToInt32(w));
                //        }
                //        catch (Exception ex)
                //        {
                //            WekaUtils.Instance.WriteLog(ex.Message);
                //        }
                //    }

                //    foreach (string p in new string[] { "M5", "M15", "M30", "H1", "H4", "D1" })
                //    {
                //        TestParameters.TestName = "Test_" + s;

                //        if (p == "M5")
                //            TestParameters2.MaxTrainSize = TestParameters2.MinTrainSize = 5;
                //        else
                //            TestParameters2.MaxTrainSize = TestParameters2.MinTrainSize = 2;

                //        TestParameters2.InitParameters(s, p, 1);
                //        //TestParameters2.tpCount = TestParameters2.slCount = 20;

                //        //TestParameters2.InitParameters(symbol, "D1", 4);
                //        //TestParameters2.tpCount = TestParameters2.slCount = 10;
                //        //TestParameters2.tpStart = TestParameters2.slStart = 9;

                //        TestParameters2.OutputParameters();

                //        foreach (string w in new string[] { "1" })
                //        {
                //            TestParameters2.lastWeek = w;

                //            CCScoreData.Instance.GenerateDataToTxt(TestParameters2.CandidateParameter.MainSymbol, TestParameters2.lastWeek);
                //            txtTest.BuildCCScoreDeals();
                //        }
                //    }
                //}

                ///////////////////////////////////////////////////////////////////////////////////
                WaitForThreads();
                //Feng.Utils.SecurityHelper.DeselectAutomaticServer();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                System.Console.WriteLine(ex.StackTrace);
                System.Console.ReadLine();
            }

            System.Console.WriteLine("End");
            System.Console.Beep();

            ReadLine(60000);
        }
예제 #3
0
        public void RunOnBar(long nowTime)
        {
            DateTime nowDate = WekaUtils.GetDateFromTime(nowTime);

            //TestParameters2.TrainStartTime = new DateTime(2000, 1, 1);
            if (nowDate < TestParameters2.TrainStartTime)
            {
                return;
            }
            TestParameters2.TrainEndTime = nowDate.AddSeconds(1);

            //// only for batchbatch
            //var ttts = m_tm.SetTimeMinutesFromTestEnd(nowDate,
            //    TestParameters.BatchTrainMinutes, TestParameters.BatchTestMinutes);
            //WekaUtils.DebugAssert((ttts[3] - nowDate).TotalMinutes < 1, "(ttts[3] - nowDate).TotalMinutes < 1");

            //Console.WriteLine(string.Format("TrainTime = {0}, {1}; TestTime = {2}, {3}", ttts[0], ttts[1], ttts[2], ttts[3]));
            //if (nowDate >= new DateTime(2004, 3, 29))
            //{
            //}

            //WekaUtils.Instance.WriteLog("Run ExecuteCandidate.");
            //if (!TestParameters2.DBDataConsistent)
            //{
            //    _realDealsCandidate.UpdateUnclosedDeals(nowDate);
            //}
            //_realDealsCandidate.ExecuteCandidate(nowDate);

            //WekaUtils.Instance.WriteLog("Run GenerateCCScores.");
            //GenerateCCScores(nowDate);

            bool inPrepare = false;

            if (TestParameters2.InPreparing)
            {
                inPrepare = true;
            }
            if ((TestParameters2.TrainEndTime - TestParameters2.TrainStartTime).TotalHours < TestParameters2.MinTrainSize * TestParameters2.MainPeriodOfHour)
            {
                inPrepare = true;
            }

            if (!inPrepare)
            {
                WekaUtils.Instance.WriteLog("Run GenerateHpDataToTxt.");
                HpData.Instance.GenerateHpDataToTxt(TestParameters2.CandidateParameter.MainSymbol, TestParameters2.CandidateParameter.MainPeriod);

                foreach (string s1 in System.IO.Directory.GetFiles(TestParameters.BaseDir, "*.arff"))
                {
                    System.IO.File.Delete(s1);
                }
                foreach (string s1 in System.IO.Directory.GetFiles(TestParameters.BaseDir, "IncrementTest_*.txt"))
                {
                    System.IO.File.Delete(s1);
                }

                //WekaUtils.Instance.WriteLog("Run BuildHpProbDeals.");
                m_tm.BuildHpProbDeals();

                //WekaUtils.Instance.WriteLog("Run BuildPricePatternDeals.");
                m_tm.BuildPricePatternDeals();

                //WekaUtils.Instance.WriteLog("Run BuildCandlePatternDeals.");
                m_taLibTest.BuildCandlePatternDeals();

                ////WekaUtils.Instance.WriteLog("Run BuildCCScoreDeals.");
                //m_txtTest.BuildCCScoreDeals();

                string orderFile = TestParameters.GetBaseFilePath(string.Format("ea_order_{0}.txt", TestParameters2.CandidateParameter.MainSymbol));
                System.IO.File.Delete(orderFile);
                m_txtTest.MergeAllBuildResult();

                if (System.IO.File.Exists(orderFile))
                {
                    string signalResultFile = "C:\\ProgramData\\MetaQuotes\\Terminal\\Common\\Files\\{0}_{1}.txt";
                    if (!TestParameters2.DBDataConsistent)
                    {
                        signalResultFile = string.Format(signalResultFile, "MLEASignal", TestParameters2.CandidateParameter.MainSymbol);
                    }
                    else
                    {
                        signalResultFile = string.Format(signalResultFile, "MLEASignal_db", TestParameters2.CandidateParameter.MainSymbol);
                    }
                    System.IO.File.Copy(orderFile, signalResultFile, true);
                }
            }

            HpData.Instance.Clear();
            DbData.Instance.Clear();
            m_taLibTest.Clear();
            WekaData.ClearTemplates();
            CCScoreData.Instance.Clear();

            System.GC.Collect();
        }