I hope that makes sense. Thanks for any help.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
One Order Per Bar
Collapse
X
-
One Order Per Bar
Is there code that I can put in my strategy that makes it only enter a new order on a bar that hasn't just closed on a trade without it being set on calculate on bar close? I want the setting of calculate on bar close = false because I get better entries but I don't want it to put in a new order right after it closes a trade on the same bar because that can really screw things up sometimes. I want it to wait until the next bar to enter the new order after the close of the previous order.
I hope that makes sense. Thanks for any help.Tags: None
-
cre8it8, you can work with BarsSinceExit() in your entry conditions to avoid reentering on the same bar then - http://www.ninjatrader-support.com/H...SinceExit.html
-
Is there a reason this is not running correctly? Is there something I need to add in order to use BarsSinceExit? This ran fine before I added it. Thanks.
if (SMA(9)[0] -0 * TickSize > SMA(20)[0])
{
if (Position.MarketPosition == MarketPosition.Flat
&& BarsSinceExit() >0 )
{
EnterLong(1, "Long 1a");
}
Comment
-
Odd, I created a strategy with the example from the link you gave me and it didn't work when I ran it. Is there something that needs to be put into the variables section or somewhere to make the below work.
protected override void OnBarUpdate()
{
if (CurrentBar < 20)
return;
// Only enter if at least 10 bars has passed since our last exit
if (BarsSinceExit() > 10 && CrossAbove(SMA(10), SMA(20), 1))
EnterLong();
}
Comment
-
cre8it8,
If your strategy has never traded yet, BarsSinceExit() would never be greater than 10. This would mean you would also never trade so you have a catch-22 situation there. You will need to allow for the first trade before using that type of condition.Josh P.NinjaTrader Customer Service
Comment
-
So I tried a couple of things like have the code without the BarsSinceExit and then have the code below that with it but to no result. Can you give me an example of how you would get it to allow the first trade and then after that trade go to the code with the BarsSinceExit. Thanks Josh
Comment
-
Not that you asked me... But, here is what I've done.
In variables...
private bool OneBarSinceExit = true;
Then inside the OnBarUpdate:
if (BarsSinceExit() > 1)
OneBarSinceExit = true;
Prior to initiating a trade and along with your other checks, make sure OneBarSinceExit is true.
After a trade is sent, reset OneBarSinceExit back to false. It is important that OneBarSinceExit is set to true in the variables. Or else it never makes that first trade.
Comment
-
Thanks for jumping in "look out below" your opinion is valued. I tried to do what you suggested on some easy code but I couldn't get it to work. I am fairly amateur at programming and most of what I am able to do is from looking at others sample codes and figuring out how to create what I need. Here is what I tried to do with what you told me below. Am I even close? Thanks for your help.
#region Variables
private bool OneBarSinceExit = true;
#endregion
protected override void Initialize()
{
EntriesPerDirection = 1;
CalculateOnBarClose = false;
SetProfitTarget("Long 1a", CalculationMode.Ticks, 5);
ExitOnClose = false;
}
protected override void OnBarUpdate()
{
if (BarsSinceExit() > 1)
OneBarSinceExit = true;
if (SMA(9)[0] > SMA(20)[0]&& OneBarSinceExit == true)
{
EnterLong(1, "Long 1a");
OneBarSinceExit == false;
}
}
}
#region Properties
#endregion
}
}
Comment
-
I think if you left everything you did the same, but change:
EnterLong(1, "Long 1a");
OneBarSinceExit == false;
to
EnterLong(1, "Long 1a");
OneBarSinceExit = false;
You have an extra "=" in there. I haven't had much sleep lately, so I may be overlooking something. But, that should work.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
647 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
367 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
571 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment