![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Junior Member
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
HI,
See my comments below: Quote:
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.
|
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
Is there an example one can provide me using the unmanaged approach to enter a trade and manage stop losses and take profits?
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Jan 2011
Posts: 21
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |