I'm trading my strategy live with MB Trading. It works fine on the Sim account and in the backtester. It keeps stalling in live markets in the same way: the exit order sends correctly, but the entry order is not sent.
I added tons of custom logging notes to show me where it stalls.
You can see that the log comments make it to "Sending a buy order", then the code never finishes. OnBarUpdate() doesn't run to the point where it should note that the order was sent. You can see that I don't have any custom code between the two logging notes. Why does NT hang to the point where it won't even log the heartbeats?
bool placeTrade = false;
if( bullish )
{
status = OrderAction.Buy;
debug.Append(": downward bullish cross " + Instrument.FullName);
Print(debug.ToString());
WriteToLog("Downward bullish cross - OnBarUpdate()");
placeTrade = true;
}
else if( bearish )
{
status = OrderAction.SellShort;
debug.Append(": upward bearish cross " + Instrument.FullName);
Print(debug.ToString());
WriteToLog("Upward bearish cross - OnBarUpdate()");
placeTrade = true;
}
ManageAccount();
if( placeTrade )
{
WriteToLog("About to place an order");
if( status == OrderAction.Buy )
{
WriteToLog("Sending a buy order");
myEntry = EnterLongLimit(0,true,Units,GetCurrentBid(),"Hil");
}
else if( status == OrderAction.SellShort )
{
WriteToLog("Sending a sell order");
myEntry = EnterShortLimit(0,true,Units,GetCurrentAsk(),"Hil");
}
WriteToLog("Escaping place trade. The order should be submitted.");
}
smaThen = sma;
}
private void ManageAccount()
{
if( status == null || myEntry == null )
return;
if( myEntry.OrderState != OrderState.Cancelled )
{
try
{
if( status == OrderAction.Buy && myEntry.OrderAction == OrderAction.SellShort )
{
CancelOrder( myEntry );
WriteToLog("Cancel short entry order - ManageAccount()");
}
else if( status == OrderAction.SellShort && myEntry.OrderAction == OrderAction.Buy )
{
CancelOrder( myEntry );
WriteToLog("Cancel long entry order - ManageAccount()");
}
}
catch(Exception e)
{
WriteToLog("EXCEPTION in ManageAccount(): " + e.Message + "\n" + e.StackTrace);
}
}
}
2/1/2012 12:21:01 PM.855: bar time 2/1/2012 12:20:48 PM: Cancel long entry order - ManageAccount()
2/1/2012 12:21:01 PM.855: bar time 2/1/2012 12:20:48 PM: About to place an order
2/1/2012 12:21:01 PM.855: bar time 2/1/2012 12:20:48 PM: Sending a sell order
2/1/2012 12:21:01 PM.890: bar time 2/1/2012 12:20:48 PM: Escaping place trade. The order should be submitted.
2/1/2012 12:21:01 PM.894: bar time 2/1/2012 12:20:48 PM: 2/1/2012 12:21:01 PM: Order status Filled with 1000 units. Order action Buy
2/1/2012 12:21:02 PM.129: bar time 2/1/2012 12:20:48 PM: 2/1/2012 12:21:02 PM: Order status PendingSubmit with 1000 units. Order action SellShort
2/1/2012 12:21:02 PM.360: bar time 2/1/2012 12:20:48 PM: 2/1/2012 12:21:02 PM: Order status PendingSubmit with 1000 units. Order action SellShort
2/1/2012 12:21:02 PM.958: bar time 2/1/2012 12:20:48 PM: 2/1/2012 12:21:02 PM: Order status PendingSubmit with 1000 units. Order action SellShort
2/1/2012 12:21:03 PM.276: bar time 2/1/2012 12:20:48 PM: 2/1/2012 12:21:03 PM: Order status Accepted with 1000 units. Order action SellShort
2/1/2012 12:21:03 PM.602: bar time 2/1/2012 12:20:48 PM: 2/1/2012 12:21:03 PM: Order status Working with 1000 units. Order action SellShort
2/1/2012 12:21:16 PM.804: bar time 2/1/2012 12:21:04 PM: OnBarUpdate() heartbeat
2/1/2012 12:21:20 PM.304: bar time 2/1/2012 12:21:20 PM: OnBarUpdate() heartbeat
2/1/2012 12:21:28 PM.521: bar time 2/1/2012 12:21:28 PM: OnBarUpdate() heartbeat
2/1/2012 12:21:39 PM.70: bar time 2/1/2012 12:21:36 PM: OnBarUpdate() heartbeat
2/1/2012 12:21:44 PM.494: bar time 2/1/2012 12:21:44 PM: OnBarUpdate() heartbeat
2/1/2012 12:21:52 PM.739: bar time 2/1/2012 12:21:52 PM: OnBarUpdate() heartbeat
2/1/2012 12:22:03 PM.799: bar time 2/1/2012 12:22:00 PM: OnBarUpdate() heartbeat
2/1/2012 12:22:14 PM.215: bar time 2/1/2012 12:22:00 PM: 2/1/2012 12:22:14 PM: Order status Filled with 1000 units. Order action SellShort
2/1/2012 12:22:14 PM.215: bar time 2/1/2012 12:22:00 PM: myEntry updated to e.Order in OnExecution()
2/1/2012 12:22:17 PM.675: bar time 2/1/2012 12:22:08 PM: OnBarUpdate() heartbeat
2/1/2012 12:22:24 PM.434: bar time 2/1/2012 12:22:24 PM: OnBarUpdate() heartbeat
2/1/2012 12:22:32 PM.866: bar time 2/1/2012 12:22:32 PM: OnBarUpdate() heartbeat
2/1/2012 12:22:42 PM.992: bar time 2/1/2012 12:22:40 PM: OnBarUpdate() heartbeat
2/1/2012 12:22:48 PM.117: bar time 2/1/2012 12:22:48 PM: OnBarUpdate() heartbeat
2/1/2012 12:22:59 PM.279: bar time 2/1/2012 12:22:56 PM: OnBarUpdate() heartbeat
2/1/2012 12:23:05 PM.57: bar time 2/1/2012 12:23:04 PM: OnBarUpdate() heartbeat
2/1/2012 12:23:12 PM.381: bar time 2/1/2012 12:23:12 PM: OnBarUpdate() heartbeat
2/1/2012 12:23:20 PM.161: bar time 2/1/2012 12:23:20 PM: OnBarUpdate() heartbeat
2/1/2012 12:23:29 PM.416: bar time 2/1/2012 12:23:28 PM: OnBarUpdate() heartbeat
2/1/2012 12:23:38 PM.751: bar time 2/1/2012 12:23:36 PM: OnBarUpdate() heartbeat
2/1/2012 12:23:44 PM.184: bar time 2/1/2012 12:23:44 PM: OnBarUpdate() heartbeat
2/1/2012 12:23:52 PM.196: bar time 2/1/2012 12:23:52 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:00 PM.335: bar time 2/1/2012 12:24:00 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:13 PM.760: bar time 2/1/2012 12:24:08 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:21 PM.895: bar time 2/1/2012 12:24:16 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:24 PM.514: bar time 2/1/2012 12:24:24 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:32 PM.872: bar time 2/1/2012 12:24:32 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:40 PM.223: bar time 2/1/2012 12:24:40 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:49 PM.577: bar time 2/1/2012 12:24:48 PM: OnBarUpdate() heartbeat
2/1/2012 12:24:56 PM.210: bar time 2/1/2012 12:24:56 PM: OnBarUpdate() heartbeat
2/1/2012 12:25:04 PM.964: bar time 2/1/2012 12:25:04 PM: OnBarUpdate() heartbeat
2/1/2012 12:25:14 PM.614: bar time 2/1/2012 12:25:12 PM: OnBarUpdate() heartbeat
2/1/2012 12:25:43 PM.500: bar time 2/1/2012 12:25:20 PM: OnBarUpdate() heartbeat
2/1/2012 12:25:44 PM.587: bar time 2/1/2012 12:25:44 PM: OnBarUpdate() heartbeat
2/1/2012 12:25:52 PM.604: bar time 2/1/2012 12:25:52 PM: OnBarUpdate() heartbeat
2/1/2012 12:26:02 PM.915: bar time 2/1/2012 12:26:00 PM: OnBarUpdate() heartbeat
2/1/2012 12:26:11 PM.227: bar time 2/1/2012 12:26:08 PM: OnBarUpdate() heartbeat
2/1/2012 12:26:17 PM.344: bar time 2/1/2012 12:26:16 PM: OnBarUpdate() heartbeat
2/1/2012 12:26:26 PM.232: bar time 2/1/2012 12:26:24 PM: OnBarUpdate() heartbeat
2/1/2012 12:26:33 PM.530: bar time 2/1/2012 12:26:32 PM: OnBarUpdate() heartbeat
2/1/2012 12:26:49 PM.820: bar time 2/1/2012 12:26:40 PM: OnBarUpdate() heartbeat
2/1/2012 12:27:02 PM.44: bar time 2/1/2012 12:26:56 PM: OnBarUpdate() heartbeat
2/1/2012 12:27:04 PM.234: bar time 2/1/2012 12:27:04 PM: OnBarUpdate() heartbeat
2/1/2012 12:27:12 PM.108: bar time 2/1/2012 12:27:12 PM: OnBarUpdate() heartbeat
2/1/2012 12:27:23 PM.253: bar time 2/1/2012 12:27:20 PM: OnBarUpdate() heartbeat
2/1/2012 12:27:49 PM.67: bar time 2/1/2012 12:27:28 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:01 PM.341: bar time 2/1/2012 12:27:52 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:10 PM.502: bar time 2/1/2012 12:28:08 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:17 PM.215: bar time 2/1/2012 12:28:16 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:26 PM.994: bar time 2/1/2012 12:28:24 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:38 PM.796: bar time 2/1/2012 12:28:32 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:42 PM.558: bar time 2/1/2012 12:28:40 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:51 PM.814: bar time 2/1/2012 12:28:48 PM: OnBarUpdate() heartbeat
2/1/2012 12:28:58 PM.998: bar time 2/1/2012 12:28:56 PM: OnBarUpdate() heartbeat
2/1/2012 12:29:04 PM.569: bar time 2/1/2012 12:29:04 PM: OnBarUpdate() heartbeat
2/1/2012 12:29:17 PM.334: bar time 2/1/2012 12:29:12 PM: OnBarUpdate() heartbeat
2/1/2012 12:29:17 PM.341: bar time 2/1/2012 12:29:12 PM: Downward bullish cross - OnBarUpdate()
2/1/2012 12:29:17 PM.341: bar time 2/1/2012 12:29:12 PM: Cancel short entry order - ManageAccount()
2/1/2012 12:29:17 PM.341: bar time 2/1/2012 12:29:12 PM: About to place an order
2/1/2012 12:29:17 PM.341: bar time 2/1/2012 12:29:12 PM: Sending a buy order
2/1/2012 1:19:26 PM.863: bar time 2/1/2012 12:29:12 PM: Strategy terminated.

Comment