![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
Hello,
I am trying to exit a position with ExitLongLimi(). This is what I coded: protected override void OnBarUpdate() if (Closes[1][0] > SMA(BarsArray[1], 250)[0] && !HasTradedLong) { HasTradedLong = true; OpenStop = Open[0]; EnterLongLimit(100, Close[0], ""); } if (Close[0] < OpenStop) { ExitLongLimit(Close[0]); } My entry orders are working, but exits do not. Am I doing something wrong here? Thanks |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Hi strategy1, are you sure your exit condition evaluates to true?
You could add Print() statements at critical points to your code to doublecheck your conditions hit home, here's a tip about this topic - http://www.ninjatrader-support2.com/...ead.php?t=3418
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
I added:
Print(Time[0].ToString()); Print(OpenStop); and it does evaluate to True, but doesn't execute. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Since you try to place a exit limit order at the Close[0] you may not get filled and the order expires at the end of the bar. Did you enable TraceOrders to debug - http://www.ninjatrader-support2.com/...ead.php?t=3627
Also: did you get any errors in the Log tab of the Control Center?
Bertrand
NinjaTrader Customer Service
Last edited by NinjaTrader_Bertrand; 01-15-2009 at 11:11 AM.
|
|
|
|
|
|
#5 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
It makes sense if the sell order doesn't execute because it is trying to get the price of Close[0], which may no longer be at that point.
It also makes sense that the order expires at the end of the bar. But it once again becomes an active order on the next bar that the condition is true, Which in my case is 5 bars later. And if the price is there at this point it should work. Yet it still doesn't execute. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Hi, have you checked the TraceOrders feedback in the Control Center output window? Please post the results here, so we can take a look - Thanks!
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
Here is the trace log.
The condition for the exit is true on the very next bar, but the price is not there already, thus it doesn't execute. But at 1:30 the condition is true and the price is there yet it still doesn't execute. Is there anything else I am missing or coding wrong? |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
You forgot the attachment.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
The file is too big to be attached. Will this be OK?
1/15/2009 5:31:21 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=0 Currency=500 Simulated=False 1/6/2009 12:50:00 PM Entered internal PlaceOrder() method at 1/6/2009 12:50:00 PM: Action=Sell OrderType=Limit Quantity=0 LimitPrice=34.32 StopPrice=0 SignalName='' FromEntrySignal='' 1/6/2009 12:50:00 PM Ignored PlaceOrder() method at 1/6/2009 12:50:00 PM: Action=Sell OrderType=Limit Quantity=0 LimitPrice=34.32 StopPrice=0 SignalName=Sell' FromEntrySignal='' Reason='An Exit() method to submit an exit order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.' 1/6/2009 12:55:00 PM Entered internal PlaceOrder() method at 1/6/2009 12:55:00 PM: Action=Sell OrderType=Limit Quantity=0 LimitPrice=34.27 StopPrice=0 SignalName='' FromEntrySignal='' 1/6/2009 1:40:00 PM Entered internal PlaceOrder() method at 1/6/2009 1:40:00 PM: Action=Sell OrderType=Limit Quantity=0 LimitPrice=34.30 StopPrice=0 SignalName='' FromEntrySignal='' 1/6/2009 1:45:00 PM Entered internal PlaceOrder() method at 1/6/2009 1:45:00 PM: Action=Sell OrderType=Limit Quantity=0 LimitPrice=34.35 StopPrice=0 SignalName='' FromEntrySignal='' 1/6/2009 3:55:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00001/Back101' Name='Profit target' State=Working Instrument='ABX' Action=Sell Limit price=35.09 Stop price=0 Quantity=1,000 Strategy='MorningBreakout' Type=Limit Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='9ef1593b47a9493ebb8f5c0a9d41ca37' Gtd='12/1/2099 12:00:00 AM' |
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
This is the problem: "An Exit() method to submit an exit order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation."
You need to debug why you are hitting one of the rules. Please review all of them in the Help Guide: http://www.ninjatrader-support.com/H...verview36.html
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
I've read the article a few times and tried to debug.
Still can't get it to work. There must be something else that I am missing... Thanks |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
Maybe this link will help with debugging: http://www.ninjatrader-support2.com/...ead.php?t=3418
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
I read it and added DrawDot,
I still can't get a handle on why it doesn't execute that line of code. One thing I did notice (although I do not think related) is that I get a wrong entry price and time (completely wrong) on the first day of the backtest only. Why would this be? Also, why would the ExitLongLimit order be ignored in my code? I would greatly appreciate anyone's help on this. |
|
|
|
|
|
#14 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
strategy1,
The Internal Order Handling Rules states this: Code:
Methods that generate orders to exit a position will be ignored if a strategy position is open and:
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Member
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
|
Josh,
That is not what it is. I have commented out my SetStopLoss when I first read the article on order handling, as per your suggestion. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Plotting issue | SystemTrading | Miscellaneous Support | 9 | 12-23-2008 06:54 AM |
| ExitLongStop, ExitLongLimit and OCO | bigtrade5 | Strategy Development | 27 | 05-16-2008 04:58 AM |
| ExitLongLimit from different strategy | MindSabre | Strategy Development | 3 | 07-11-2007 08:16 AM |
| ExitLongLimit order with Signal Name | Nathamus | Strategy Development | 5 | 03-13-2007 04:14 AM |
| ExitLongLimit order with Signal Name | Nathamus | Automated Trading | 4 | 12-31-1969 06:00 PM |