private void SimulateStrategyBear5K(DateTime dtStartDate, DateTime dtEndDate, StrategyExcel strategyExcel, string sStrategyName1, string sStrategyName2)
        {
            int nAT = 0, n2AT = 0, nDirection = 2;
            double dSR = 0, dEV = 0, d2SR = 0, d2EV = 0;
            int nSG = m_Config.SG, nSL = m_Config.SL;
            if (m_Config.SG == 0)
                nSG = 10000;
            if (m_Config.SL == 0)
                nSL = 10000;

            try
            { 
                foreach (KeyValuePair<int, DateStrategyMap> kp in m_DateStrategy)
                {
                    DateStrategyMap dsMap = kp.Value;
                    if (dsMap.Date.CompareTo(dtStartDate) < 0 || dsMap.Date.CompareTo(dtEndDate) > 0)
                        continue;

                    if (dsMap.IsContainStrategy(sStrategyName1) && dsMap.IsContainStrategy(sStrategyName2))
                    {
                        nAT++;
                        double dIn;
                        bool bHit = false;
                        DateTime Start = Convert.ToDateTime("08:45");
                        DateTime End = Convert.ToDateTime("13:25");

                        if (m_Config.IsStrategy0900(sStrategyName1) || m_Config.IsStrategy0900(sStrategyName2))
                        {
                            Start = Convert.ToDateTime("09:00");
                            dIn = dsMap.Get5KOpen(Start);
                        }
                        else
                            dIn = dsMap.FuturesOpen;

                        double dOut = dsMap.Get5KClose(End);

                        if (m_DateStrategy.Count - kp.Key <= m_Config.NearPeriod)
                            n2AT++;

                        while (Start.CompareTo(End) < 1)
                        {
                            // 打到停損
                            //
                            if (dsMap.Get5KHigh(Start) - dIn >= nSL)
                            {
                                bHit = true;
                                dEV -= m_Config.SL;

                                if (m_DateStrategy.Count - kp.Key <= m_Config.NearPeriod)
                                    d2EV++;
                                break;
                            }
                            // 打到停利
                            //
                            else if (dIn - dsMap.Get5KLow(Start) >= nSG)
                            {
                                bHit = true;
                                dEV += m_Config.SG;
                                dSR++;

                                if (m_DateStrategy.Count - kp.Key <= m_Config.NearPeriod)
                                {
                                    d2EV += m_Config.SG;
                                    d2SR++;
                                }
                                break;
                            }
                            Start = Start.AddMinutes(5);
                        }

                        if (!bHit)
                        {
                            double dResult = dIn - dOut;

                            if (dResult > 0)
                                dSR++;
                            dEV += dResult;

                            if (m_DateStrategy.Count - kp.Key <= m_Config.NearPeriod)
                            {
                                d2EV += dResult;
                                if (dResult >= 0)
                                    d2SR++;
                            }
                        }
                    }
                }
                dSR = dSR / nAT;
                dEV = dEV / nAT - 2;
                d2SR = d2SR / n2AT;
                d2EV = d2EV / n2AT - 2;
                strategyExcel.Write(sStrategyName1 + sStrategyName2, m_Config.SG, m_Config.SL, nAT, dSR, dEV, n2AT, d2SR, d2EV, nDirection);
            }
            catch (Exception ex)
            {
                Form1.g_UI_ShowInfo(ex.ToString());
            }
        }
        public async Task StartSimulateAsync(bool bIsCross, DateTime dtStartDate, DateTime dtEndDate)
        {
            rwLock.EnterReadLock();
            try
            {                
                StrategyExcel strategyExcel = new StrategyExcel(m_Config, "Raw_{0:yyyyMMdd}-{1:yyyyMMdd}_R{2}_C{3}.xlsx", dtStartDate, dtEndDate, m_Config.SG, m_Config.SL);
                if (!strategyExcel.Init())
                {
                    Form1.g_UI_ShowInfo("Excel Already Exist");
                    return;
                }

                Form1.g_UI_ShowInfo("Simulating...");

                string[][] AllStrategy = m_Config.AllStrategy;

                // 交集
                if (bIsCross)
                {
                    for (int i = 0; i < AllStrategy.Length; i++)
                    {
                        for (int j = 0; j < AllStrategy[i].Length; j++)
                        {
                            if (i + 1 < AllStrategy.Length)
                            {
                                for (int k = i + 1; k < AllStrategy.Length; k++)
                                {
                                    for (int l = 0; l < AllStrategy[k].Length; l++)
                                    {
                                        await Task.Run (() => {
                                            SimulateStrategyBull5K(dtStartDate, dtEndDate, strategyExcel, AllStrategy[i][j], AllStrategy[k][l]);
                                            SimulateStrategyBear5K(dtStartDate, dtEndDate, strategyExcel, AllStrategy[i][j], AllStrategy[k][l]);
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < AllStrategy.Length; i++)
                    {
                        for (int j = 0; j < AllStrategy[i].Length; j++)
                        {
                            await Task.Run(() => {
                                SimulateStrategyBull5K(dtStartDate, dtEndDate, strategyExcel, AllStrategy[i][j], "");
                                SimulateStrategyBear5K(dtStartDate, dtEndDate, strategyExcel, AllStrategy[i][j], "");
                            });
                        }
                    }
                }
                
                strategyExcel.Close();
                Form1.g_UI_ShowInfo("Simulate Finished");
            }
            catch (Exception ex)
            {
                Form1.g_UI_ShowInfo(ex.ToString());
            }
            finally
            {
                rwLock.ExitReadLock();
            }

        }