View Full Version : BarsSinceExit()
dgregor5
08-16-2007, 02:50 PM
Hi.
Any hints on the following would be useful.
As part of a condition for trade entry, would like to implement following:
BarsSinceExit() > 1
However, to have this line of code, it would appear that there is a need to have a reference somewhere else in the strategy that a trade has been executed previously otherwise the above does not work, & if the above line is one of the conditions of entry, no trades are executed. Hope this makes since.
if use BarsSinceEntry() as a condition of exit, however, it executes as would expect since trade has already been entered!
Hope you are able to assist here with some general direction.
thx
David
NinjaTrader_Josh
08-16-2007, 03:49 PM
Like you have noticed if you never entered before then BarsSinceExit() will never be greater than 1. To address this you need to have a separate set of entry conditions for your first entry.
if (BarsSinceEntry() > 0)
{
if (BarsSinceExit() > 1) //All entries after first entry has to be at least 1 bar since last exit
EnterLong();
}
else //First entry
{
EnterLong();
}
dgregor5
08-18-2007, 07:25 AM
Hey thx for the response. Greatly appreciated. I also found another way when hunting through the support forum.....this appears to work also.
BarsSinceExit() > 1 || BarsSinceExit() == -1
thx. David
nt2010
01-10-2011, 01:17 PM
Hello Josh,
i used your attached samplefile to create my strategy.
The conditions do work perfect, but i have the problem, that its only working on one day.
e.g. i use in the data series "day to load" 10 days, then i only get shown the results on the second day of the period, in this case day 2 of 10.
every following day no trade gets executed.
Do i have to reset anyting somehow that the strategy does work again on the following day ?
The code i implemented is:
protected override void OnBarUpdate()
if (BarsSinceEntry() > 0)
if (BarsInProgress == 0 && BarsSinceExit() == 1 && conditons
else
if (BarsInProgress == 0 && conditions
...do something...
It would be great if you could give me a hint how i could get it working.
Thank You !
NinjaTrader_RyanM
01-10-2011, 01:42 PM
Hello nt2010,
You'll have to verify the values for your conditions, to make sure they're what you expect. Print() all values for your entry conditions so you know what's used.
http://www.ninjatrader-support.com/vb/showthread.php?t=3418
You also might want to look at your branching structure. Some basic examples to work from are available here:
http://www.ninjatrader.com/support/helpGuides/nt7/branching_commands.htm
nt2010
01-10-2011, 02:32 PM
Hi Ryan,
thank you for your fast answer. Its less the result of the strategy but more the point that it only shows an effect on one day. I attached a picture and the simple code file for the problem. I dont know what i have to do, that it makes/shows the trades each day.
It would be great if you could have a look at it.
Thank you for your help
NT2010
NinjaTrader_RyanM
01-10-2011, 03:02 PM
I took a look at your strategy code. I also gave it a run here and get orders beyond only the second day. I see only one series - is there any reason your strategy checks for specific BarsInProgress? This is typically only used for multiseries strategy.
The process for identifying strategy behavior still comes down to printing all values, verifying them and tracking any messages related to order submission.
Your entry condition works with BarsSinceEntry and and BarsSinceSession. These are the properties you'll want to check with print statements.
Print(BarsSinceEntry());
Print(Bars.SinceSession);
Check your branching structure to make sure the code is flowing the way you expect. Add print statements at various points to verify code is executed.
else
{
Print("Else Block Executed");
if (BarsInProgress == 0 && Bars.BarsSinceSession == 0 )//First entry
{
EnterLong();
Print("if Condition after else block executed");
}
}
You should also consider adding a signal name tag so you can see which order statements are the ones placing order on that day.
If all your values check out, then look at the flow of order submission with TraceOrders output. (http://www.ninjatrader.com/support/helpGuides/nt7/traceorders.htm)