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-24-2008, 02:40 PM   #1
malbeth35
Junior Member
 
Join Date: Sep 2008
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default Market Trades don't always execute

In my strategy script, I am using two instruments. I usually enter and exit both instruments on the same tick. In fact, the Enter calls are on adjacent lines in the code, and the Exit calls are on adjacent lines in the code.

What I am finding, though, is that one of the Exit calls (occassionally) doesn't appear to submit an order, and thus never gets executed to close the position.

For example, on one tick, we execute this code:
if ( doTrade )
{
EnterLong( 0, 10, "Long Primary" );
EnterShort( 1, 10, "Short Secondary" );
}

on a subsequent tick, we execute this code:

if ( exitTrade )
{
ExitLong( 0, 10, "Exit Primary", "Long Primary" );
ExitShort( 0, 10, "Exit Secondary", "Short Secondary" );
}

on subsequent ticks, I check the Positions[0 and 1] to make sure I've gone flat. But, one or the other the Exits will still be a full position (not even partially closed) after well more than 10 1-minute bars have gone by.

Is there a race condition or other problem that may occur when submitting orders on two instruments literally back-to-back? What can I do to guarantee that both orders are submitted and confirmed as received before continuing my strategy?

Thanks!
malbeth35 is offline  
Reply With Quote
Old 09-24-2008, 02:45 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

That is because you are submitting both Exit() orders to the same barsInProgress index instead of to the two separate instruments.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-24-2008, 03:51 PM   #3
malbeth35
Junior Member
 
Join Date: Sep 2008
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default

Ooops! My bad on the original post. I double-checked the code just now, and it uses the correct indices. The post should have read:

f ( exitTrade )
{
ExitLong( 0, 10, "Exit Primary", "Long Primary" );
ExitShort( 1, 10, "Exit Secondary", "Short Secondary" );
}

So, my question still stands.

Also, I running now with the simulator (earlier today was with paper trading on live quotes), and I am getting the same results. It appears to be the second Exit that never fills. And, again, it goes okay on the first round trip, but the second round trip is where it fails.
Last edited by malbeth35; 09-24-2008 at 03:56 PM.
malbeth35 is offline  
Reply With Quote
Old 09-24-2008, 04:12 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

You will need to debug as per these tips then: http://www.ninjatrader-support.com/v...ead.php?t=3627
http://www.ninjatrader-support.com/v...ead.php?t=3418
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-24-2008, 05:36 PM   #5
malbeth35
Junior Member
 
Join Date: Sep 2008
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Smile

Excellent! Thanks, Josh, that did the trick.

I was using the wrong trade name in one of my exit conditions, so it was unable to match up the entrySignalName I was passing into the Exit... call with the actual entrySignalName.
malbeth35 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
Market Replay error: Failed to execute DB Job 'StrategyUpdateJob': .... scriabinop23 Historical NinjaTrader 6.5 Beta Threads 1 01-25-2008 05:02 AM
Order won't execute? edgeliner General Programming 11 12-12-2007 09:01 AM
What bar does order execute? Folls Strategy Development 1 05-15-2007 01:22 PM
Failed to execute DB job errors Antraman Miscellaneous Support 2 05-04-2006 10:44 AM
Failed to execute DB job ratherBgolfing Automated Trading 7 04-14-2006 05:18 AM


All times are GMT -6. The time now is 04:52 AM.