NinjaTrader Support Forum  
X

Attention!

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


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 06-07-2012, 09:11 AM   #1
sandeshrai
Member
 
Join Date: Jan 2010
Location: Irvine, CA
Posts: 58
Thanks: 12
Thanked 0 times in 0 posts
Default Exit code disables all exit

I am using the following code to exit my trade:

// Using the end of bar exit
if(this.iUseEOBExit)
{
if(

// After 5 bars have passed since entry, exit the position
BarsSinceEntry() >= 5

)
{
if(this.iQuantity1 != 0 && tVars.iOrder[1] == null)
tVars.iOrder[
1] = ExitShort("eob", string.Empty);

return;
}
}

However, when I back test, not only does the above exit not work, it appears to disable all other exit modes as well. I get one single trade which enters at the start of the back test period and ends at the end of the back test period.

I have other exit modes which is based on profit target, loss target and time based targets. All of these get disabled.
sandeshrai is offline  
Reply With Quote
Old 06-07-2012, 09:50 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

sandeshrai,

Are there any messages in log tab when you run the strategy?

Is it performing according to the logic you set? For example, after 5 bars since the first entry you set to return; This means it will exit OnBarUpdate() routine and not process any logic further down.

Code:
if (BarsSinceEntry() >= 5)
{ 
return;
}
Last edited by NinjaTrader_RyanM; 06-07-2012 at 10:01 AM.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 06-08-2012, 09:26 AM   #3
sandeshrai
Member
 
Join Date: Jan 2010
Location: Irvine, CA
Posts: 58
Thanks: 12
Thanked 0 times in 0 posts
Default

Hello Ryan,

Here is the message I am getting in the Log "Error on calling 'OnBarUpdate' method for strategy 'sSandeshV3B/93e8de2f6b634adcaa208befa8d479d9': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntry() method in the context of a multi-time frame and instrument strategy."
sandeshrai is offline  
Reply With Quote
Old 06-08-2012, 09:39 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

Thanks for the reply. The code you posted matches your description of the strategy behavior. You should correct the issue reported in log tab, and then look into why you are returning out 5 bars after the first entry. Here's where you can see supported overloads for BarsSinceEntry()
http://www.ninjatrader.com/support/h...sinceentry.htm
NinjaTrader_RyanM is offline  
Reply With Quote
The following user says thank you to NinjaTrader_RyanM for this post:
Old 06-08-2012, 01:28 PM   #5
sandeshrai
Member
 
Join Date: Jan 2010
Location: Irvine, CA
Posts: 58
Thanks: 12
Thanked 0 times in 0 posts
Default

Thanks Ryan. That helped
sandeshrai is offline  
Reply With Quote
Reply

Tags
exit logic

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
'This was an exit order but no position exists to exit' on Iexecution daxtrading Strategy Development 3 07-05-2011 10:59 AM
Partial Exit - named signal exit stop not updated MicroTrends Strategy Development 5 02-08-2011 10:17 AM
Exit code does not work for some unknown reason MJUK05 Strategy Development 3 01-03-2011 12:59 PM
code exit half way to target Stem1 General Programming 4 10-09-2010 07:20 AM
New scale-out exit being ignored after a partial, then complete fill on previous exit vjsworld Strategy Development 11 05-18-2009 12:59 PM


All times are GMT -6. The time now is 10:52 AM.