NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 09-25-2009, 06:04 AM   #1
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Question NT's Internal Order Handling Issue?

Guys,

I have a strategy that onBarUpdate() determines the market position before trading so as to exit any opposite position first. However, during a backtest a long trade was ignored because a short was open, or so I believe. Here's the trace order output:

3/17/2009 1:23:00 AM Entered internal PlaceOrder() method at 3/17/2009 1:23:00 AM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.3014 StopPrice=0 SignalName='LongX' FromEntrySignal=''
3/17/2009 1:23:00 AM Ignored PlaceOrder() method at 3/17/2009 1:23:00 AM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.3014 StopPrice=0 SignalName=LongX' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'


My OnBarUpdate() code is this:
if (Position.MarketPosition == MarketPosition.Short) {
if (someCondition) // long entry signal
{
exitOrder = ExitShort(Position.Quantity, "XShrtOnLongX", "ShortX");
if (stopOrder != null)
CancelOrder(stopOrder);
entryOrder = EnterLongLimit(simLotsTraded, GetCurrentBid(), "LongX");


As you can see, it should exit before entering and ususally does. However this time it did not. How can I deal with this?
Attached Images
File Type: jpg $EURUSD 3_17_2009 (1 Min).jpg (90.1 KB, 7 views)
crmcwi is offline  
Reply With Quote
Old 09-25-2009, 06:21 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

crmcwi, please try entering code to confirm the order reached indeed 'cancelled' state (confirmed) before you place the opposing order.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 09-25-2009, 06:37 AM   #3
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default while loop?

Good idea Bertrand, but let me ask you something that only an experienced NT coder would know.

Can I or should I use a while() loop to wait for the cancelling?

In pseudo code, it might be something like:

While (stopOrder.OrderState != OrderState.Cancelled) {
do something like increment a counter;
}

the reason I ask is becuase I thought NT should do this in the background and if this should typically be done, it should be documented, yes?
Last edited by crmcwi; 09-25-2009 at 06:39 AM. Reason: forgot something
crmcwi is offline  
Reply With Quote
Old 09-25-2009, 06:44 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

I don't think you would need a loop for this, as it's all event based - just make sure you received the confirmed cancelled orderstate - this is also a good preparation to take the strategy live as order confirmations would take a bit longer in real life than possibly on the internal Sim101.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 09-25-2009, 09:46 AM   #5
crmcwi
Senior Member
 
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok, thanks Bertrand,

But I'm still confused. My code goes like this:

ExitOrder = .....
if stopOrder !=null, cancelOrder (stopOrder)

EntryOrder = ....


the problem is that the EntryOrder is ignored because the stop order exitorder isn't filled.

If I just put a condition to the EntryOrder = , won't the code just process the condition, calculate that the stopOrder is not null, and then proceed past the EntryOrder? In other words, don't I have to make the code wait for the stopOrder to be filled?
crmcwi is offline  
Reply With Quote
Old 09-25-2009, 09:54 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

You want to wait for the fill confirmation in the OnOrderUpdate(), this way you know it's updated / received before you issue your following entry.

http://www.ninjatrader-support2.com/...ead.php?t=7499
NinjaTrader_Bertrand 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
Quick Question on Internal Order Handling Rules trader_rick Automated Trading 1 03-19-2009 07:30 AM
Trouble understanding the Internal (interal?) Order Handling Brian1 Strategy Development 9 02-13-2009 09:13 AM
OCO Order Handling issue sammano Strategy Development 3 12-12-2008 06:48 AM
Same order is getting fired twice. order state and handling problem Rocket130713 Automated Trading 19 09-22-2008 06:58 AM
Internal Order Handling Rules for Stop Limits wayneFH Strategy Development 7 06-14-2008 06:39 PM


All times are GMT -6. The time now is 04:12 PM.