NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM 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 02-22-2012, 10:06 AM   #1
rmaron
Junior Member
 
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default Inconsistent behavior when updating an ExitLongStop order

Hi
I have a strategy that enters a trade and manages the take profits and stop loss using the ExitLongStop and ExitLong orders
When my first take profit hits, I update the stop loss quantity and then take the profit.
For example: Once entering a trade with 600 stocks. When the first take profit hits, I decrease the quantity of the stop loss to 400 stocks and exit 200 stocks as follows
// Update stop loss quantity
stopOrder = ExitLongStop(0, true, 400 , stopOrder.StopPrice , "STOP_LOSSS" , "ENTRY");
// Take profit
ExitLong(200 , "FIRST_TAKE_PROFIT" , "ENTRY");

In some cases, I've noticed that the stop loss order doesn't get updated and my trade is left without any stop loss.
(The order of the stop loss is canceled instead of being updated with the right quantity).
It is important to mention that this is not consistent. Sometimes the stoploss order igets updated properly.
Can someone help me understand what I'm doing wrong?
Is there a race condition between the ExitLongStop and ExitLong orders (I know that the stop order should be updated prior to taking the profit).

Regards,
Ron
rmaron is offline  
Reply With Quote
Old 02-22-2012, 10:16 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

In Ron,

In order to scale out of a position, you must first scale in with distinct entry names. Matching signal names is what is used to determine exit quantity and will take priority over the quantity you have specified in the method. This is part of our managed framework. A basic scale out sample strategy is available here:
http://www.ninjatrader.com/support/f...ead.php?t=3751

If you wanted more control on the scaling behavior, you could work with unmanaged framework. With this there is no built in position/order management and can scale in/out they way you're looking to do.
http://www.ninjatrader.com/support/h...d_approach.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-22-2012, 10:32 AM   #3
rmaron
Junior Member
 
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default

HI,

See my comments below:

Quote:
Originally Posted by NinjaTrader_RyanM View Post
In Ron,

In order to scale out of a position, you must first scale in with distinct entry names. Matching signal names is what is used to determine exit quantity and will take priority over the quantity you have specified in the method. This is part of our managed framework. A basic scale out sample strategy is available here:
http://www.ninjatrader.com/support/f...ead.php?t=3751
I don't want to enter the trade via multiple orders since this will increase my commission. See the following thread I sent quite a while ago: http://www.ninjatrader.com/support/f...ad.php?t=46473

Yet, I am still unclear why my code doesn't work properly: I match the signal name of both the stop loss order and the take profit order to the entry name (i.e. "ENTRY").
Prior to taking the profit, I decrease the stop loss order quantity and then issue an exit long order. Both orders "are linked" to the same entry order (*ENTRY").

Please clarify.
Last edited by rmaron; 02-22-2012 at 10:35 AM.
rmaron is offline  
Reply With Quote
Old 02-22-2012, 10:43 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

It sounds like you'll want to consider unmanaged approach for this. Scaling out in a managed system will only work if you first scale in. Unmanaged approach is the alternative to this, with complete control on order submission.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-22-2012, 10:48 AM   #5
rmaron
Junior Member
 
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Ryan

Thank you for the quick response.
I don't want to be difficult. However, I'm still unclear why my code doesn't work properly.

I understand I can use the unmanaged approach.
However, I don't understand why Ninja Trader doesn't allow me to update my trade stoploss and then take profit on the rest of the quantity.

Ron
rmaron is offline  
Reply With Quote
Old 02-22-2012, 11:07 AM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

It's just how the managed framework is designed to determine exit quantity. The NinjaTrader strategy framework does order/position management "under the hood" to simplify order submission for you. In this case you disagree with how your orders are handled by the managed layer. You're not able to change how this managed layer behaves, but you are able to create your preferred handling with unmanaged approach.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-22-2012, 11:27 AM   #7
rmaron
Junior Member
 
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default

Is there an example one can provide me using the unmanaged approach to enter a trade and manage stop losses and take profits?
rmaron is offline  
Reply With Quote
Old 02-22-2012, 12:21 PM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

I'm sorry we don't have this specific example. You can read more about unmanaged order methods here:
http://www.ninjatrader.com/support/h...d_approach.htm

There are only three methods for submitting, changing, and cancelling orders. To get the most use of unmanaged orders, take a look at our advanced handlers topic here:
http://www.ninjatrader.com/support/h...n_program2.htm

And IOrder page here for exposing order properties and working with the objects needed for these methods:
http://www.ninjatrader.com/support/h...nt7/iorder.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-22-2012, 04:29 PM   #9
rmaron
Junior Member
 
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
Default

I wonder what would be the right approach when changing the stoploss quantity and taking profit:
1) Should I first change the stop loss, wait for acknowledge that the stop loss quantity changed (i.e. In the OnExecution() method), and then send the take profit command. or
2) Send both the stop loss quantity change order and the take profit order (without waiting to the acknowledgement).

I hope someone could provide me with the better approach.

Ron
rmaron is offline  
Reply With Quote
Old 02-23-2012, 07:34 AM   #10
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

This is for unmanaged approach, right? There's not one answer here as it depends how you design your strategy and the conditions it runs in. I would update the stop order quantity after receiving confirmation of limit order fill, but other approaches could certainly work.
NinjaTrader_RyanM 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
Strategies behavior inconsistent and unreliable naxo79 Automated Trading 4 06-30-2011 04:56 AM
Why exitlongstop order didin't work? Danielj Strategy Development 5 10-28-2010 10:05 AM
Not able to replace ExitLongStop order rahulkalgunde Strategy Development 1 08-02-2010 02:14 PM
Modify ExitLongStop Order kcsystemtrader Strategy Development 3 03-16-2009 01:51 PM
Inconsistent behavior for drawing parameters astrolobe General Programming 1 03-18-2008 10:42 PM


All times are GMT -6. The time now is 11:54 PM.