NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-16-2007, 02:50 PM   #1
dgregor5
Senior Member
 
Join Date: Jul 2007
Posts: 225
Thanks: 0
Thanked 0 times in 0 posts
Default BarsSinceExit()

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
dgregor5 is offline  
Reply With Quote
Old 08-16-2007, 03:49 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.

Code:
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();
}
Attached Files
File Type: zip SampleBarsSinceExit.zip (650 Bytes, 18 views)
Last edited by NinjaTrader_Josh; 08-16-2007 at 03:55 PM.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-18-2007, 07:25 AM   #3
dgregor5
Senior Member
 
Join Date: Jul 2007
Posts: 225
Thanks: 0
Thanked 0 times in 0 posts
Default

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
dgregor5 is offline  
Reply With Quote
Old 01-10-2011, 01:17 PM   #4
nt2010
Member
 
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
Default

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 !
nt2010 is offline  
Reply With Quote
Old 01-10-2011, 01:42 PM   #5
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 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/v...ead.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/h...g_commands.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-10-2011, 02:32 PM   #6
nt2010
Member
 
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
Default

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
Attached Images
File Type: jpg upload.jpg (290.4 KB, 5 views)
File Type: jpg uploadv2.jpg (455.0 KB, 6 views)
Attached Files
File Type: zip SampleBarsSinceExitv2.zip (936 Bytes, 3 views)
Last edited by nt2010; 01-10-2011 at 02:34 PM.
nt2010 is offline  
Reply With Quote
Old 01-10-2011, 03:02 PM   #7
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

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.
NinjaTrader_RyanM 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
BarsSinceExit() dgregor5 Strategy Development 2 08-06-2007 12:40 PM


All times are GMT -6. The time now is 06:11 PM.