![]() |
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 |
|
Member
Join Date: Jan 2010
Location: Irvine, CA
Posts: 58
Thanks: 12
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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;
}
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 06-07-2012 at 10:01 AM.
|
|
|
|
|
|
#3 |
|
Member
Join Date: Jan 2010
Location: Irvine, CA
Posts: 58
Thanks: 12
Thanked 0 times in 0 posts
|
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." |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
Ryan M
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_RyanM for this post: |
|
|
|
#5 |
|
Member
Join Date: Jan 2010
Location: Irvine, CA
Posts: 58
Thanks: 12
Thanked 0 times in 0 posts
|
Thanks Ryan. That helped
|
|
|
|
![]() |
| Tags |
| exit logic |
| Thread Tools | |
| Display Modes | |
|
|
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 |