I know this has been answered before but I am unable to find the post. Within my strategy, it is possible to exit a position while the entry criteria are still valid. The obviously causes issues with multiple entries and exits inter bar. There was a post regarding a method to stop this, I believe it's probably something simple with bars since entry/exit but I seem to be chasing my tail because without an entry or exit to satisfy the condition I get nowhere. Your assistance is appreciated.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Stop multiple entry and exit orders on same bar
Collapse
X
-
Stop multiple entry and exit orders on same bar
Hello
I know this has been answered before but I am unable to find the post. Within my strategy, it is possible to exit a position while the entry criteria are still valid. The obviously causes issues with multiple entries and exits inter bar. There was a post regarding a method to stop this, I believe it's probably something simple with bars since entry/exit but I seem to be chasing my tail because without an entry or exit to satisfy the condition I get nowhere. Your assistance is appreciated.Tags: None
-
Hello jhjhawkins,
Thanks for your post.
You can use an int variable that you create to limit your orders to once per bar.
For example, if you create like this private int entryBar;
You could use like this:
if (Your conditions to enter && CurrentBar != entryBar) // is the current bar NOT equal to entryBar
{
// entry order
entryBar = CurrentBar; // set the variable the same as the system bar counter CurrentBar
}
The first time your entry conditions are true the CurrentBar will not be equal to the entryBar which then allows the order to be placed AND the variable entryBar is set to the value of CurrentBar. If your entry conditions remain true on the subsequent calls to OnBarUpdate(), further orders cannot happen because entryBar IS equal to CurrentBar which makes the if condition set false regardless of your entry conditions.
- Likes 1
-
Paul
That makes perfect sense, I figured it would be fairly simple. Is there a way to set the variable entryBar = CurrentBar within the Strategy Builder or I would need to do that in the code via ninjascript editor? I'm still learning the coding within Ninjatrader.
Comment
-
Hello jhjhawkins,
Thanks for your reply.
Yes, you can do that in the strategy builder.
Here is a short video: https://paul-ninjatrader.tinytake.co...Nl8xNDc5OTg3Mg
Going forward, when you create a forum thread, you might want to identify that you are using the Strategy Builder so that we can provide the answer to you in a form that you using as we tend to answer everything in Ninjascript by default.
Comment
-
Paul,
Thank you for the assistance, noted regarding identifying using strategy builder. I'll get Ninjascript figured out at some point.
- Likes 1
Comment
-
Hi Paul,
I need help with the same issue as above. I'm using NinjaScript, but the above code you have I don't understand - I'm new to NinjaScript. I would understand it better if I could put it in Strategy Builder first, see how it's coded and then put it in NinjaScript. However, the above link with the video showing this concept in Strategy Builder no longer works. Can you repost the video or can you explain how I can input this concept into the Strategy Builder? Thanks for any help you can provide.
Comment
-
Originally posted by NinjaTrader_PaulH View PostHello jhjhawkins,
Thanks for your post.
You can use an int variable that you create to limit your orders to once per bar.
For example, if you create like this private int entryBar;
You could use like this:
if (Your conditions to enter && CurrentBar != entryBar) // is the current bar NOT equal to entryBar
{
// entry order
entryBar = CurrentBar; // set the variable the same as the system bar counter CurrentBar
}
The first time your entry conditions are true the CurrentBar will not be equal to the entryBar which then allows the order to be placed AND the variable entryBar is set to the value of CurrentBar. If your entry conditions remain true on the subsequent calls to OnBarUpdate(), further orders cannot happen because entryBar IS equal to CurrentBar which makes the if condition set false regardless of your entry conditions.
Thank you for this pointer! I've been wrestling with multiple entries in a loop because my long closes and short enters on the same bar. This addition fixed the issue!
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
51 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
129 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment