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

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 01-26-2012, 07:23 AM   #1
irish9293
Junior Member
 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default Strategy "Startup" Needed

I've programmed a strategy that is "always in" the market based on crossovers. I also need to operate with COBC=false. To get around the problem of having more than one bar per entry, I've set the "BarsSinceEntry" to >0 for both entry triggers. It works fine once I get the system started. The problem is when I actually enable the system, the strategy does not make an opening entry -- because there is no "Entry" to refer to in the BarsSinceEntry part of the triggers. In other words, how can I tell the strategy to "just take a position" at some point many bars back so that it cabn calculate where it would be now? I've tried a couple things -- but they are not perfect, because there is still a remote chance of an overfill condition. (One such idea is telling it to enter a position coming out of a session break if I am flat -- but it occurs to me that if a session break leads to a major move, the crossover trigger could hit (and I'd be flat for a split second) and then the "starter" would also hit giving me an overfill). Also I would very much like to do this in Strategy Wizard. I can't seem to tell it "If i've been flat for three bars, go long". If I could do that, my problem would be solved.
irish9293 is offline  
Reply With Quote
Old 01-26-2012, 07:39 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

Hello irish9293,

Thanks for the post and welcome to our forums.

A nice feature of BarsSinceExit() is that it returns -1 before the first exit has taken place. So you could structure your entries like this to allow it to trigger for the first entry, and then still enforce BarsSinceEntry() > 0.

Code:
if(yourCrossOverConditions && (BarsSinceExit() == -1 || BarsSinceEntry() > 0)) 
{
//doSomething
}
To set this up in the wizard, you would essentially have to duplicate your entry methods using two sets.

One set would include crossover condition && BarsSinceExit == -1. The other set would have your crossover condition && BarsSinceEntry > 0.
Last edited by NinjaTrader_RyanM; 01-26-2012 at 07:43 AM.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-26-2012, 08:29 AM   #3
irish9293
Junior Member
 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default

Ryan: Thanks -- that should work.

One last glitch/issue. I actually think "BarsSinceEntry > 0" doesn't work the way i thought -- I'm getting multiple orders on a single bar. I think maybe I should use "BarsSinceEntry >=1"? Do you think this was the cause of the multiple orders (which caused overfills and crashed the strategy)?
irish9293 is offline  
Reply With Quote
Old 01-26-2012, 08:40 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

BarsSinceEntry > 0 and BarsSinceEntry >=1 should be the same.

The most likely reason for overfill in this type of strategy would be if you had like ExitLong(), EnterShort() in the same action section. If this is the case, you would want to remove the separate Exit method. Enter methods would take care of the reversal for you.

If that's not it, I'm happy to take a look if you can post the code here.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-26-2012, 08:53 AM   #5
irish9293
Junior Member
 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default

Actually, I haven't had those superfluous Exits, so I'm stumped. I will try the >=1 and see what happens.
irish9293 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
Awkward resolution of runtime error "256 barsAgo needed" tulanch Suggestions And Feedback 1 12-11-2010 02:18 PM
Bug in "Connect at Startup" TheCatMan Connecting 1 12-03-2010 08:48 AM
summary of "strategy realized" is not equal "account performance, total net profit"" Fragolino Miscellaneous Support 1 02-19-2009 04:12 AM
Add to ATM Strategy "Trailing "Limit"" shawnj Suggestions And Feedback 2 10-10-2008 08:01 PM
"'OrderRejected'. Strategy has sent cancel requests" & "There is no market data..." Elliott Wave Strategy Development 6 04-12-2008 12:03 AM


All times are GMT -6. The time now is 03:00 AM.