![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jul 2007
Posts: 225
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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();
}
Last edited by NinjaTrader_Josh; 08-16-2007 at 03:55 PM.
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2007
Posts: 225
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
Member
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
|
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 ! |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Member
Join Date: Jun 2010
Posts: 35
Thanks: 0
Thanked 0 times in 0 posts
|
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
Last edited by nt2010; 01-10-2011 at 02:34 PM.
|
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| BarsSinceExit() | dgregor5 | Strategy Development | 2 | 08-06-2007 12:40 PM |