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 > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 01-15-2009, 09:42 AM   #1
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default ExitLongLimit issue.

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

strategy1 is offline  
Reply With Quote
Old 01-15-2009, 09:53 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-15-2009, 10:46 AM   #3
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default Evaluates to True - but doesn't execute.

I added:

Print(Time[0].ToString());
Print(OpenStop);

and it does evaluate to True, but doesn't execute.
strategy1 is offline  
Reply With Quote
Old 01-15-2009, 10:51 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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?
Last edited by NinjaTrader_Bertrand; 01-15-2009 at 11:11 AM.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-15-2009, 11:31 AM   #5
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
strategy1 is offline  
Reply With Quote
Old 01-15-2009, 11:46 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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!
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-15-2009, 03:44 PM   #7
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default TraceLog

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?
strategy1 is offline  
Reply With Quote
Old 01-15-2009, 03:48 PM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

You forgot the attachment.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-15-2009, 04:19 PM   #9
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default Will this be OK?

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'
strategy1 is offline  
Reply With Quote
Old 01-15-2009, 04:21 PM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

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
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-17-2009, 08:03 PM   #11
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default Still doesn't work.

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
strategy1 is offline  
Reply With Quote
Old 01-18-2009, 11:18 AM   #12
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

Maybe this link will help with debugging:
http://www.ninjatrader-support2.com/...ead.php?t=3418
NinjaTrader_Ben is offline  
Reply With Quote
Old 01-19-2009, 07:27 PM   #13
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default Still Can't Figure it out.

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.
strategy1 is offline  
Reply With Quote
Old 01-20-2009, 07:48 AM   #14
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

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:
  • An order submitted by a set method (SetStopLoss() for example) is active
That is what you are hitting. You have SetStopLoss active so you cannot use an explicit exit method unless that method was for a market order.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-20-2009, 09:56 AM   #15
strategy1
Member
 
Join Date: Mar 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default That's not it.

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.
strategy1 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
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


All times are GMT -6. The time now is 02:53 AM.