示例#1
0
文件: Test.old.cs 项目: slb7/backtest
        //        private void ProcessTradeEntry(List<string> results, BarDay barday, ref bool inPosition, ref bool orderInForce, double enterLimitPrice, ref double exitLimitPrice, ref double enterExecPrice, ref int stopTime)
        private void ProcessTradeEntry(List <string> results, IBarDay barday) //, ref bool inPosition, ref bool orderInForce, double enterLimitPrice, ref double exitLimitPrice, ref double enterExecPrice, ref int stopTime)
        {
            IBar b = bd.GetMinuteBar(i, 1, 1);

            if (b.Open < enterLimitPrice)
            {
                DateTime barTime = barday.Date.AddHours(9.5).AddMinutes(i);

                inPosition     = true;
                inPositionDays = 0;
                enterExecPrice = b.Open;
                exitLimitPrice = enterExecPrice + profitExit;
                b = bd.GetMinuteBar(i, 1, 0);
                string str = $"{bd.Symbol} enter:{barTime.ToString("MM-dd-yy HH:mm:ss")} {i} {b.ToString()} enterExecPrice={enterExecPrice} exitLimitPrice={exitLimitPrice}";
                results.Add(str);
                results.AddRange(Container.messages);
                orderInForce = false;
                stopTime     = i + StopTimeInterval;
                //File.AppendAllText(@"c:\src\diag.txt", $"stopTime={stopTime} i={i}\r\n");
            }
        }
示例#2
0
文件: Test.old.cs 项目: slb7/backtest
 private void CheckEntryCriteria(List <string> results, IBarDay barday, ref bool orderInForce, ref int orderInForceExpiry, ref double enterLimitPrice, int i)
 {
     if (t(i))
     {
         IBar b = bd.GetMinuteBar(i, 1, 0);
         if (b == null)
         {
             underflow = true;
         }
         if (!underflow)
         {
             DateTime barTime = barday.Date.AddHours(9.5).AddMinutes(i);
             entering        = true;
             enterLimitPrice = exec();
             //double d = MinuteClose(5, 0);
             //double dd = bars[i].Close;
             entering = false;
             string str = $"{bd.Symbol} met: {barTime.ToString("MM-dd-yy HH:mm:ss")} {i} {b.ToString()} enterLimitPrice={enterLimitPrice}";
             results.Add(str);
             results.AddRange(Container.messages);
             orderInForce       = true;
             orderInForceExpiry = i + tif;
             //File.AppendAllText(@"c:\src\diag.txt", $"profitExit={profitExit} tif={tif}\r\n");
         }
     }
 }
示例#3
0
文件: Test.old.cs 项目: slb7/backtest
        //        private void ProcessTradeExit(List<string> results, BarDay barday, ref bool inPosition, double exitLimitPrice, double enterExecPrice, ref double exitExecPrice, int stopTime)
        private void ProcessTradeExit(List <string> results, IBarDay barday) //, ref bool inPosition, double exitLimitPrice, double enterExecPrice, ref double exitExecPrice, int stopTime)
        {
            IBar b = bd.GetMinuteBar(i, 1, 0);

            //File.AppendAllText(@"c:\src\diag.txt", $"profitExit={profitExit} tif={tif} exitLimitPrice{exitLimitPrice}\r\n");
            if (b != null)
            {
                if (b.Open > exitLimitPrice)
                {
                    DateTime barTime = barday.Date.AddHours(9.5).AddMinutes(i);
                    exitExecPrice = exitLimitPrice;
                    double pandl = exitExecPrice - enterExecPrice;
                    Container.testResult.NumTrades++;
                    Container.testResult.PandL += pandl;
                    //testResults.Add(testResult);
                    string str = $"{bd.Symbol} exit:{barTime.ToString("MM-dd-yy HH:mm:ss")} {i} {b.ToString()} exitExecPrice={exitExecPrice} p&l={(exitExecPrice - enterExecPrice).ToString("0.00")}";
                    results.Add(str);
                    results.AddRange(Container.messages);
                    inPosition = false;
                }
                else if (i >= stopTime || (i >= CloseAll && inPositionDays >= maxOvernights))
                {
                    //File.AppendAllText(@"c:\src\diag.txt", $"profitExit={profitExit} tif={tif} exitLimitPrice{exitLimitPrice} \r\n");
                    DateTime barTime = barday.Date.AddHours(9.5).AddMinutes(i);
                    exitExecPrice = b.Open;
                    double pandl = exitExecPrice - enterExecPrice;
                    Container.testResult.NumTrades++;
                    Container.testResult.PandL += pandl;
                    //testResults.Add(testResult);
                    string str = $"{bd.Symbol} Stop Exit:{barTime.ToString("MM-dd-yy HH:mm:ss")} {i} {b.ToString()} exitExecPrice={exitExecPrice} p&l={(exitExecPrice - enterExecPrice).ToString("0.00")}";
                    results.Add(str);
                    results.AddRange(Container.messages);
                    inPosition = false;
                }
            }
        }