![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
}
One set would include crossover condition && BarsSinceExit == -1. The other set would have your crossover condition && BarsSinceEntry > 0.
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 01-26-2012 at 07:43 AM.
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
|
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)? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
|
Actually, I haven't had those superfluous Exits, so I'm stumped. I will try the >=1 and see what happens.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |