NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 11-26-2008, 08:42 AM   #1
heech
Senior Member
 
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
Default "Unable to match order state to execution"

I received an alert + messages in the log this morning...

Quote:
11/26/2008 6:57:16 AM|1|128|Starting NinjaScript strategy 'ProtectDown/3d1fbd264b67483ba2eb9578a17475c8' : On starting a real-time strategy - StrategySync=SubmitLive EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=ByStrategyPosition ErrorHandling=TakeNoAction ExitOnClose=False Set order quantity by=Strategy
11/26/2008 6:57:17 AM|1|32|Order='NT-4/707028387' Name='Sell' New State=PendingSubmit Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
11/26/2008 6:57:21 AM|1|32|Order='4502008081/707028387' Name='Sell' New State=Accepted Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
11/26/2008 6:57:21 AM|1|32|Order='4502008081/707028387' Name='Sell' New State=Working Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
11/26/2008 6:57:21 AM|1|32|Order='4500271885/707028387' Name='Sell' New State=Cancelled Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
11/26/2008 7:07:54 AM|1|32|Order='4502008081/707028387' Name='Sell' New State=Filled Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Type=Stop Filled=1000 Fill price=10.982 Error=NoError Native error=''
11/26/2008 7:07:54 AM|1|16|Execution='4502109406' Instrument='MAC' Account='707028387' Exchange=Default Price=10.98 Quantity=100 Market position=Short Operation=Insert Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|1|16|Execution='4502109402' Instrument='MAC' Account='707028387' Exchange=Default Price=10.97 Quantity=300 Market position=Short Operation=Insert Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|1|16|Execution='4502109397' Instrument='MAC' Account='707028387' Exchange=Default Price=10.97 Quantity=200 Market position=Short Operation=Insert Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|1|16|Execution='4502109265' Instrument='MAC' Account='707028387' Exchange=Default Price=10.99 Quantity=100 Market position=Short Operation=Insert Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|1|16|Execution='4502108925' Instrument='MAC' Account='707028387' Exchange=Default Price=11 Quantity=300 Market position=Short Operation=Insert Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|0|128|Unable to match order state to execution: Order='4502008081/707028387' Name='Sell' State=Filled Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Strategy='ProtectDown' Type=Stop Tif=Day Oco='' Filled=1000 Fill price=10.982 Token='4de5a41889964344933a08a065aa9ec9' Gtd='12/1/2099 12:00:00 AM' / Execution='4502109406' Instrument='MAC' Account='707028387' Name='Sell' Exchange=Default Price=10.98 Quantity=100 Market position=Short Commission=0 Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|0|128|Unable to match order state to execution: Order='4502008081/707028387' Name='Sell' State=Filled Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Strategy='ProtectDown' Type=Stop Tif=Day Oco='' Filled=1000 Fill price=10.982 Token='4de5a41889964344933a08a065aa9ec9' Gtd='12/1/2099 12:00:00 AM' / Execution='4502109402' Instrument='MAC' Account='707028387' Name='Sell' Exchange=Default Price=10.97 Quantity=300 Market position=Short Commission=0 Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|0|128|Unable to match order state to execution: Order='4502008081/707028387' Name='Sell' State=Filled Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Strategy='ProtectDown' Type=Stop Tif=Day Oco='' Filled=1000 Fill price=10.982 Token='4de5a41889964344933a08a065aa9ec9' Gtd='12/1/2099 12:00:00 AM' / Execution='4502109397' Instrument='MAC' Account='707028387' Name='Sell' Exchange=Default Price=10.97 Quantity=200 Market position=Short Commission=0 Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|0|128|Unable to match order state to execution: Order='4502008081/707028387' Name='Sell' State=Filled Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Strategy='ProtectDown' Type=Stop Tif=Day Oco='' Filled=1000 Fill price=10.982 Token='4de5a41889964344933a08a065aa9ec9' Gtd='12/1/2099 12:00:00 AM' / Execution='4502109265' Instrument='MAC' Account='707028387' Name='Sell' Exchange=Default Price=10.99 Quantity=100 Market position=Short Commission=0 Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:54 AM|0|128|Unable to match order state to execution: Order='4502008081/707028387' Name='Sell' State=Filled Instrument='MAC' Action=Sell Limit price=0 Stop price=11 Quantity=1,000 Strategy='ProtectDown' Type=Stop Tif=Day Oco='' Filled=1000 Fill price=10.982 Token='4de5a41889964344933a08a065aa9ec9' Gtd='12/1/2099 12:00:00 AM' / Execution='4502108925' Instrument='MAC' Account='707028387' Name='Sell' Exchange=Default Price=11 Quantity=300 Market position=Short Commission=0 Order='4502008081' Time='11/26/2008 7:07:54 AM'
11/26/2008 7:07:56 AM|1|64|Instrument='MAC' Account='707028387' Avg price=0 Quantity=0 Market position=Long Operation=Remove Currency=UsDollar
What does this mean?
heech is offline  
Reply With Quote
Old 11-26-2008, 08:46 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

heech,

Where are you submitting orders from? You may be hitting race conditions. Hard to say without isolating out the specific line/block of code that generated this error.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-26-2008, 08:59 AM   #3
heech
Senior Member
 
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
heech,

Where are you submitting orders from? You may be hitting race conditions. Hard to say without isolating out the specific line/block of code that generated this error.
Josh,

This is one of the stop orders generated by my strategy (mentioned in the log as well).

A race condition in NT order handling code, I assume you mean? It looks like it might be that.
heech is offline  
Reply With Quote
Old 11-26-2008, 09:11 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Likely race condition. You will need to be mindful of the multi-threaded nature of NinjaTrader.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-26-2008, 10:01 AM   #5
heech
Senior Member
 
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Likely race condition. You will need to be mindful of the multi-threaded nature of NinjaTrader.
Not sure what that means, Josh... in terms of being mindful. Do I need to do anything to synchronize *my* code, or are you saying I should just be aware of/ignore these errors when they pop up?
heech is offline  
Reply With Quote
Old 11-26-2008, 10:05 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

There is nothing you can do to synchronize NT being multi-threaded. You have to work with it and be aware of it.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-26-2008, 10:12 AM   #7
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Just curious, is this with IB TWS and if yes, what NT version are you using? Help > About.
NinjaTrader_Ray is offline  
Reply With Quote
Old 11-26-2008, 12:20 PM   #8
heech
Senior Member
 
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
Just curious, is this with IB TWS and if yes, what NT version are you using? Help > About.
No, this is going direct to TDAmeritrade. I'm version 6.5.1000.7.

I actually think this isn't a race condition, I'm suspecting something else (problems in my code?). I just had another stop order hit, and the same error message popped up... that's pretty bad luck on my part if it's a race condition.

I've had three stop orders hit today, and two gave the same error. Note that the two orders that gave errors filled on multiple orders, whereas the stop order that didn't error out filled on a single order. I suspect that's significant.
heech is offline  
Reply With Quote
Old 11-26-2008, 12:26 PM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

We cannot evaluate the scenario without seeing exact code. Please post simple as possible code snippet.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-26-2008, 12:30 PM   #10
heech
Senior Member
 
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
We cannot evaluate the scenario without seeing exact code. Please post simple as possible code snippet.
Josh,

Not sure what to show you... this is the stop order code. It's only called once at the beginning of day (or when position is entered)... so hours ago from when the error popped up.

stopOrder = ExitLongStop(0, true, config.NumShares, holdPrice * stopMultiple, "", "");

holdPrice and stopMultiple are both static numbers from the point of view of this strategy (loaded from my cfg file).

I do use OnOrderUpdate, and here's the relevant code for orderstate.filled:
Quote:
if (order.OrderState == OrderState.Filled)
{
if (debugging)
Print("Order filled: " + order);
if ((longOrder != null) && (order.Token == longOrder.Token))
{
if (debugging)
Print("Placing stop order...");
// longOrder filled... put in my stop order.
stopOrder = ExitLongStop(0, true, config.NumShares, holdPrice * stopMultiple, "", "");
return;
}
if ((stopOrder != null) && (order.Token == stopOrder.Token))
{
// Stop order has been filled....
stopOrder = null;
}
}
heech is offline  
Reply With Quote
Old 11-26-2008, 12:40 PM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

And have you isolated out the scenario when you reach these messages? Reproducible at will? What is the code doing right before it happens? The nature of these things is complicated. You need to do it step by step. Keep things very simple. One order at a time. Until you can isolate out exactly what is happening with your code we cannot assist much. Unfortunately we just don't have the bandwidth to be going through everyone's code in depth. What we need to see to further assist is the code you have isolated out (in this instance it may even be best to see the complete code of the isolated case so only show us the code that is absolutely necessary to reproduce), the behavior you think it should be doing, the behavior you are seeing, and all relevant evidence you have showing the contrary.

The key here is that you need to be able to reproduce it and inform us as to the steps to reproduce it and then we can proceed from there.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-26-2008, 12:48 PM   #12
heech
Senior Member
 
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
Lightbulb

Quote:
Originally Posted by NinjaTrader_Josh View Post
And have you isolated out the scenario when you reach these messages? Reproducible at will? What is the code doing right before it happens? The nature of these things is complicated. You need to do it step by step. Keep things very simple. One order at a time. Until you can isolate out exactly what is happening with your code we cannot assist much. Unfortunately we just don't have the bandwidth to be going through everyone's code in depth. What we need to see to further assist is the code you have isolated out (in this instance it may even be best to see the complete code of the isolated case so only show us the code that is absolutely necessary to reproduce), the behavior you think it should be doing, the behavior you are seeing, and all relevant evidence you have showing the contrary.

The key here is that you need to be able to reproduce it and inform us as to the steps to reproduce it and then we can proceed from there.
Josh,

I think you're barking up the wrong tree here. There's no way that this is remotely related to my code. Your last theory was that this is a race condition in the Ninja Trader order handling code, I don't know how it jumped to my application.

No, I have no way of reproducing the error... it isn't even an error generated by the strategy itself, and I have no intention of entering into positions and setting up stop orders just in hopes that I'll get multiple fills, and the platform will throw an alert. And just to be clear, it's not just a "log" message... I actually get a modal MessageBox with the alert (and not generated by my strategy).

I think the most likely explanation is that whatever logic is in place (perhaps linked to TDAmeritrade - I take it it's not a common choice for the execution broker) for handling order fulfillment is confusing partial fills with full order fills.
heech is offline  
Reply With Quote
Old 11-26-2008, 01:10 PM   #13
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

The situation is this:

- This error message pops up when NT receives (for example) a "Filled" state for an order that has generated multiple part fills
- In this example, we expect to see multiple "PartFilled" order states to be in sycn with the actuall executions reported in the OnExecution() method
- This means that you can't rely on using OnOrderUpdate() with this particular broker since sometimes they may provide all order state changes and sometimes they may not

The net result is that we would advise you not to use OnOrderUdpate() when trading through TDA. This occured before with IB (which is why I asked before) but this was an issue on our send that we fixed. I can see from your log info you posted that we really did not receive "PartFilled" states generated from the TDA adapter.
NinjaTrader_Ray is offline  
Reply With Quote
Old 11-26-2008, 01:36 PM   #14
heech
Senior Member
 
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
Default

Ray,

That's about what I figured was happening.

I'm not too concerned about OnOrderUpdate... if I get you correctly, my use of the function isn't the cause of the alert. You're just warning me about other consequences. I understand I might confuse a partial fill with a full fill, but at the time scales I'm trading at, it really shouldnt' be an issue 99.99% of the time. Regardless, I'll look into OnExecute().

In the mean time... are the Alert messages an issue? If I step away from my desk all day, and all hell breaks loose on the markets and I hit a lot of stop orders... am I going to end up with 50 messageboxes, and do you see that possibly breaking anything (like on-going execution of strategies)?

And if *it* is an issue... can I pleasepleaseplase get a patched version of the software that gives me the option to turn off that messagebox alert?
heech is offline  
Reply With Quote
Old 11-26-2008, 01:40 PM   #15
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Depending on what the Alert message shows, if its an rejected order, the strategy will terminate immediately, if its some warning then there is the possibility that you can get an unwanted number of message boxes although I don't ever recall a situation where anyone has raised an issue due to an offensive number of message boxes. At this time, these boxes can't be surpressed.
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving strategy "state" heech Miscellaneous Support 6 11-19-2008 04:44 PM
Unable to match order state to execution nfeldberg Strategy Development 21 09-24-2008 12:14 PM
the forum can not remember the settings of "Sorted by" and "Sort Order" clearpicks Suggestions And Feedback 1 05-23-2008 12:05 PM
"unable to connect to level2 server" for E-signal MikeB Miscellaneous Support 8 02-03-2006 08:38 AM
"Invalid execution data from patssystems" QuahTrader Miscellaneous Support 10 03-16-2005 10:46 AM


All times are GMT -6. The time now is 01:47 AM.