![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
|
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"); |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
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 ? |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
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
|
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Yes you can. Keep them separate with their own IDs.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
Excellent - I'll have a play. Thanks for the great support.
|
|
|
|
|
|
#10 | |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Quote:
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 |
|
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
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 |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Dec 2008
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |