NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


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 01-29-2009, 01:44 PM   #1
SystemTrading
Senior Member
 
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
Default Simultaneous orders

I am trying to place a simultaneous buy and sell order, but it is ignoring the second order. My code looks like this. Am I doing something wrong?

Code:
LE=EnterLongStop(lprice,"LE");
SE=EnterShortStop(sprice,"SE");
SystemTrading is offline  
Reply With Quote
Old 01-29-2009, 01:52 PM   #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

You cannot place simultaneous orders in the opposite direction for the same instrument. Please use TraceOrders = true to see reasons for why your orders are rejected or ignored.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-29-2009, 03:08 PM   #3
scottyboy
Junior Member
 
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

I was about to ask the same question... how is it if you don't have an ATM selected in chart trader that you can have both a Long Stop order and a Short Stop order active. You can also have 2 separate strategies active - one placing a Long Stop order and the other placing a Short Stop order.

I'm not nit picking deliberately - I would genuinely like to have a Longstop and shortstop order active at the same time from within the same strategy -- when one gets filled the other gets cancelled.

If one strategy fills an order can another active strategy on the same instrument see that it has been filled ?
scottyboy is offline  
Reply With Quote
Old 01-29-2009, 03:17 PM   #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

Chart Trader is different. Each group of orders are managed independently of each other. From a single NinjaScript strategy you cannot place simultaneous entry orders in opposite directions for the same instrument. If you read the TraceOrders output when you try to do this it will tell you to review the Internal Order Handling Rules.

You can review them here: http://www.ninjatrader-support.com/H...verview36.html

Cross-strategy communication is not supported.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-29-2009, 03:35 PM   #5
scottyboy
Junior Member
 
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post

Cross-strategy communication is not supported.
Quick response - thanks. Had a quick read of the link.

Can a strategy tell if an instrument has got an active order OR if there is a position in the market ?

My requirement is very simple - have a longstop strategy and a shortstop strategy - if one gets filled the other cancels itself when it sees that there is a position in the market.
scottyboy is offline  
Reply With Quote
Old 01-29-2009, 03:38 PM   #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

Unfortunately, no, a strategy only knows what is calculated based off of the strategy. What you want to do requires cross-strategy communication. It is possible through more advanced C#. You can search the forums for other users who have tried, but this is an endeavor we cannot offer you any support on.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-29-2009, 03:47 PM   #7
scottyboy
Junior Member
 
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

Before I try it - Is it possible to call up 2 ATM Strategies from within a single strategy -- one to "buy" and one to "sell" - when one is filled cancel the other.

Clutching at straws I guess
scottyboy is offline  
Reply With Quote
Old 01-29-2009, 03:49 PM   #8
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

Yes you can. Keep them separate with their own IDs.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-29-2009, 03:52 PM   #9
scottyboy
Junior Member
 
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

Excellent - I'll have a play. Thanks for the great support.
scottyboy is offline  
Reply With Quote
Old 01-29-2009, 04:39 PM   #10
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
Originally Posted by scottyboy View Post
...If one strategy fills an order can another active strategy on the same instrument see that it has been filled ?...
scottyboy,

Cross-strategy communication could be achieved by implementing static data members/methods in the strategy class or designing a strategy base class containing the static data. When multiple strategies are instantiated, they all share the static elements.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 01-29-2009, 04:50 PM   #11
scottyboy
Junior Member
 
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ralph - I will have to look into that but I suspect it's going to make me scratch my head a bit. I found a post that shows how to call up StreamWriter and create a text file -- this quick and dirty method will allow me to easily flag up what the other strategy is doing.

http://www.ninjatrader-support2.com/...5&postcount=12

If you get a quiet moment in the next few days I would appreciate you pointing me in the right direction with...

implementing static data members/methods in the strategy class or designing a strategy base class containing the static data.


Off to bed for me - getting very late.
scottyboy is offline  
Reply With Quote
Old 01-30-2009, 03:26 AM   #12
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Hi scottyboy,

in reference to the link you mentioned, here is an example how to code a similar concept with a static data flag:

Define a static strategy variable:

private static longPosFlag;

If your entry conditions are met:

if (!longPosFlag) {
EnterLong...
longPosFlag = true;
}

If your exit conditions are met:

ExitLong...
longPosFlag = false;

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 01-30-2009, 05:56 AM   #13
scottyboy
Junior Member
 
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello Ralph, I tried this but when I ran the same strategy twice longPosFlag did not seem to be affected by the value in the other strategy.

I had to use private static bool longPosFlag;

I put it in #region Variables

I suspect I have mis-understood what you intended.

Thanks for your help with this.
scottyboy is offline  
Reply With Quote
Old 01-30-2009, 06:04 AM   #14
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

What you did is correct scottyboy. It is a typo, and I am too ment a static boolean variable. I am not sure what the default type for a variable is, if the type is not declared and if the compiler accepts that (perhaps an int?).

Regards
Ralph
Ralph 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
multiple strategies simultaneous on one instrument mrlogik Strategy Development 7 01-21-2009 07:52 AM
simultaneous trades lindsayf ATM Strategies (Discretionary Trading) 3 01-20-2009 07:07 AM
Multi Broker Simultaneous Use SalientTrader Installation and Licensing 3 09-29-2008 02:35 PM
Simultaneous Orders on the same side cttsc Automated Trading 3 07-07-2008 07:20 AM
Simultaneous Orders cttsc Automated Trading 2 06-27-2008 08:10 PM


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