Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Live trading problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Live trading problem

    Hi everyone,

    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?

    Code:
    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.854: bar time 2/1/2012 12:20:48 PM: Upward bearish cross - OnBarUpdate()
    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.

    #2
    Hello texasnomad,

    Generally we would not be able to fully debug your strategy. One missing piece here that would help you out is TraceOrders output.

    Yes, from your output you would expect that the strategy enters the code block for these commands:
    Code:
    WriteToLog("Sending a buy order");
    myEntry = EnterLongLimit(0,true,Units,GetCurrentBid(),"Hil");
    TraceOrders will tell you what happens next with your order, if it's submitted or ignored for any reason.

    You should expect the same mechanical operation in your strategy with live or sim account. If all other factors are equal and the strategy submits sim, it should submit live as well. There are additional considerations of course once the order gets to your broker. If there are any MBT messages you aren't sure about, we're happy to review your trace /log files to look into these. You can send using Help > Mail to support feature and include a link to this thread.

    If the order never gets to MBT, then TraceOrders should provide you additional information on how the strategy responds to the order commands.
    Last edited by NinjaTrader_RyanM1; 02-01-2012, 03:11 PM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the tip. I think that this is going to be useful.

      One issue that popped up was an overfill warning. I checked out the trace log. It says "2/2/2012 9:44:24 AM Entered internal PlaceOrder() method at 2/2/2012 9:44:24 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1,000 LimitPrice=76.12'7 StopPrice=0 SignalName='Hil' FromEntrySignal=''
      2/2/2012 9:44:24 AM Ignored PlaceOrder() method at 2/2/2012 9:44:24 AM: Action=SellShort OrderType=Limit Quantity=1,000 LimitPrice=76.12'7 StopPrice=0 SignalName='Hil' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

      What does this have to do with an overfill? I'm not trading multiple orders in the same direction. I buy once, then I'll go short. 100% of my trades are long-short-long-short and don't flip sequence.

      Comment


        #4
        The messages you posted are not the overfill ones. Overfill would shutdown the strategy, cancel all orders, and close your position.

        The overfill can happen anytime an order is marked for cancellation but is filled before it can be cancelled.

        The cancellation can be from autoexpiration on the orders. If the order is not filled on the bar it's submitted to, then it will be cancelled. You also send CancelOrder() manually so overfill could come as a result of this as well.

        2/2/2012 9:44:24 AM Ignored PlaceOrder() method at 2/2/2012 9:44:24 AM: Action=SellShort OrderType=Limit Quantity=1,000 LimitPrice=76.12'7 StopPrice=0 SignalName='Hil' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
        This message is returned because there is already an entry order in the same direction, and submitting more would violate those two properties mentioned. EntryHandling and EntriesPerDirection.

        It may help to simplify and focus on only one aspect at a time until the strategy works as you expect. The best design would be if you can have all conditions for entry joined by && in one section. Using bool flags would only be recommended if you wanted to create some sequencing to your conditions.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        668 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        377 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        110 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        580 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X