![]() |
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 |
|
Junior Member
Join Date: Jul 2010
Posts: 29
Thanks: 3
Thanked 0 times in 0 posts
|
I have read through the documentation on internal order handling and am still a little confused. I am trying to use the managed approach, with a setstoploss and I'm calling an exitlonglimit inside OnExecution (of an entry). With my criteria for setstoploss and exitlonglimit, they could never happen simultaneously.
Question 1: Based on the documentation I believe I cannot have a static setstoploss order and an exitlonglimit order occurring simultaneous, correct? Question 2: Is there a way to accomplish this within the managed approach, somehow setting when one is executed, the other is automatically cancelled? Or calling the setstoploss within the OnExecution of the entry? Question 3: If not possible, what would be the best way of accomplishing having a stoploss and exitlong limit? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello wallabee13,
Thanks for your post and I am happy to assist you. 1 - Yes correct. If SetStopLoss is in place you cannot place ExitLongLimitorders. 2 & 3 – Simply reassign the SetStopLoss again. Please refer to this sample code for further reference http://ninjatrader.com/support/forum...ead.php?t=3222 Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2010
Posts: 29
Thanks: 3
Thanked 0 times in 0 posts
|
Thanks for that, but I am still having problems with it. It works before any position are entered (when stoploss has not been called yet in OnBarUpdate). Then when a second position attempts to enter I get an object reference not set to instance of object for my exitlonglimit.
I have a print command to determine if myLongExitOrder1 is null for debugging purposes, which does print. protected override void OnExecution(IExecution execution) { if (myLongEntryOrder1 != null && myLongEntryOrder1 == execution.Order) { Print(execution.ToString()); Print("Entry 1 Filled"); myLongEntryOrder1 = null; Print("Entry 1 null"); if(myLongExitOrder1 == null) { Print("Exitisnullandentereing"); myLongExitOrder1 = ExitLongLimit(0,true,DefaultQuantity,(Low[0] + (tickRange+1)*TickSize),"MyLongExitOrder1","My Long Entry Order 1!!!"); Print("placingLongExitOrder at " + myLongExitOrder1.LimitPrice + ToTime(Time[0])); Print(myLongExitOrder1.ToString()); } } Here is the output window: "Execution='f17e61d3fde245d19ea86b50de62c9e5' Instrument='ES 03-12' Account='Replay101' Name='My Long Entry Order 1!!!' Exchange=Default Price=1218 Quantity=1 Market position=Long Commission=1.1 Order='781ae9b50ad14257a23dc323c5ae20ab' Time='12/14/2011 8:50:44 AM' Entry 1 Filled Entry 1 null Exitisnullandentereing **NT** Error on calling 'OnExecution' method for strategy 'BlackBarManagedLongs2/8c512878c6fa4f769d490f5045516597': Object reference not set to an instance of an object." |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello wallabee13,
Please check for null orders in your code. For example. Code:
protected override void OnExecution(IExecution execution)
{
If (execution.Order == null)
{
//do stuffs or return
}
//do rest of the stuffs
}
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jul 2010
Posts: 29
Thanks: 3
Thanked 0 times in 0 posts
|
That's exactly what
"if(myLongExitOrder1 ==null) { //stuff" is there for. Is that syntax wrong? It enters the logic, prints "exitisnullandentereing" and then comes up with an error that myLongExitOrder1 is not null. Everything worked perfectly before I tried to add the setstoploss order. It's something with the stoploss. Is there a way to declare "SetStopLoss==null;"?
Last edited by wallabee13; 02-03-2012 at 12:06 PM.
|
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Jul 2010
Posts: 29
Thanks: 3
Thanked 0 times in 0 posts
|
Ok, Sorry. There's nothing wrong with the stop loss. It's something about calling the print statements after the exitlong entry. Thanks for the help. Will continue to work on it.
Last edited by wallabee13; 02-03-2012 at 12:45 PM.
|
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Jul 2010
Posts: 29
Thanks: 3
Thanked 0 times in 0 posts
|
Well, after a second run on it, it is still coming up with the same problem. After the first time a setstoploss and a exitlonglimit are set, the exitlonglimit does not get triggered again in the code posted previously.
There is no error, it just never gets set again. |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Wallabee13,
Once a SetStopLoss is set it cannot be undone, i.e. for the subsequent entries, you cannot use ExitLongLimit() orders. You have to use the Set orders only. As such, if you wish to use exit limit orders, then don’t use Set orders, replace Set orders with ExitLongStop for the first case. Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
Thanks very much, Joydeep. I’ve had to a look at the ‘SampleMACrossover’ strategy and at the Managed Approach page. I’ve taken some time studying both of these in some detail.
But I wonder if you could answer this question: could you kindly explain how the Managed Approach to strategies differs from those which are worked out using the Strategy Wizard alone? Looking at the code for ‘SampleMACrossover’, it must very similar to one for the same strategy worked out with the Wizard alone. If there is a difference, could you kindly point it out? Again, much obliged in advance for your reply. |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello arbuthnot,
Thanks for writing in and I am happy to assist you. The strategy wizard uses the Managed approach only to submit the orders. Strategy Wizard is mainly for users who not have coding experience and want a simple interface to construct their strategies. Code wise there is no difference whether you code your strategy via the Strategy wizard or code it via the NinjaScript editor using Managed approach. Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Feb 2012
Posts: 178
Thanks: 42
Thanked 13 times in 11 posts
|
Thanks again, Joydeep. It was obvious that I posted my last reply in the wrong thread! This won't be the first time this has happened, I'm sure.
Anyway, I'm only a novice at coding but I'll try to get to grips with the Managed Approach. |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Arbuthnot,
The main difference between managed approach and unmanaged approach is that with the former (i.e. managed approach) NinjaTrader takes care of the bells and whistle that might affect an order. With Unmanaged approach you have to take care of everything. Please go through our help guide to get more idea on managed approach http://www.ninjatrader.com/support/h...d_approach.htm Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#13 | |
|
Senior Member
|
Quote:
- overfill? - order errors? - entries per direction? - competing orders? - position management -> only submit exit if there is a position? Is there a detailed list anywhere? And some detail about required considerations for dealing with these issues in unmanaged approach? So that I can build up a checklist of stuff to look at when using unmanaged approach...
Last edited by AnotherTrader; 07-03-2012 at 02:12 AM.
|
|
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello AnotherTrader,
Unfortunately there is no comprehensive list but basically the Managed approach reduces unwanted position. It can be competing orders or position management etc. Please refer to our help guide to know more about the Managed approach. http://www.ninjatrader.com/support/h...d_approach.htm
Joydeep M.
NinjaTrader Customer Service |
|
|
|
![]() |
| Tags |
| exitlonglimit, managed approach, setstoploss |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ExitLongLimit ignored | Walter | Strategy Development | 1 | 04-28-2011 12:47 PM |
| HOW!!?? Turn SetStopLoss into a ExitLongLimit | Trader.Jon | Strategy Development | 5 | 03-24-2011 12:03 PM |
| ExitLongLimit is ignored. | istavnit | Automated Trading | 5 | 04-01-2009 02:50 PM |
| ExitLongLimit issue. | strategy1 | General Programming | 35 | 01-22-2009 11:18 AM |
| ExitLongLimit from different strategy | MindSabre | Strategy Development | 3 | 07-11-2007 08:16 AM |