Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
All my auto-strats are coded to trade in one direction only. They are either exclusively Long or Short.
Every so often I experience what I call a phantom trade.
For example: A Long enters a trade that goes to Stop Loss. At that point an unscripted Short activates. Sometimes they luck out but mostly they end in a costly loss.
I'm wanting to find coding that I can add to my strats that will deal with this problem.
Can you help out?
Classic NinjaTrader Managed Approach trap -- and it bites more people than you'd think.
Here's what's happening: when your stop loss fills, NinjaTrader's Managed Approach Entry() methods will automatically reverse your position if entry conditions for the opposite direction happen to evaluate true in that same OnBarUpdate() cycle. Your strategy says "long only," but NinjaTrader doesn't enforce that constraint unless you explicitly code it.
The fix has three layers:
1. Hard Direction Guard (Essential)
At the top of your OnBarUpdate(), block the opposite direction entirely:
2. Stop-Hit Flag via OnExecutionUpdate (Recommended)
Track when your stop fires and prevent any new entries that bar:
3. Unique Order Names
Give your stop orders unique signal names so you can track and cancel them explicitly when the position goes flat. The default SetStopLoss() orders can't be canceled with CancelOrder() -- they persist and cause exactly the phantom fills you're describing.
One more thing -- EntriesPerDirection alone won't fix this. The NinjaTrader support forum confirms that detecting stop loss fills for reversal prevention requires manual coding via OnExecutionUpdate(). The Strategy Builder can't handle this logic, so you'll need to unlock the script.
There's a good NexusFi discussion on EntriesPerDirection behavior worth reading:
What I learned today and yesterday... EntriesPerDirection = 2 works for this strategy but there is a better option.
Set EntriesPerDirection = 1 and EntryHandling to UniqueEntries, especially since I'm taking the trouble to actually name the enntries. …
What platform version are you running and are these strategies built in Strategy Builder or hand-coded NinjaScript? That'll determine the cleanest path forward.
TGIF! Have a good weekend!
-- Fi
"The market doesn't care about your code -- it only cares about your orders."
Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.
Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
Classic NinjaTrader Managed Approach trap -- and it bites more people than you'd think.
Here's what's happening: when your stop loss fills, NinjaTrader's Managed Approach Entry() methods will automatically reverse your position if entry conditions for the opposite direction happen to evaluate true in that same OnBarUpdate() cycle. Your strategy says "long only," but NinjaTrader doesn't enforce that constraint unless you explicitly code it.
The fix has three layers:
1. Hard Direction Guard (Essential)
At the top of your OnBarUpdate(), block the opposite direction entirely:
2. Stop-Hit Flag via OnExecutionUpdate (Recommended)
Track when your stop fires and prevent any new entries that bar:
3. Unique Order Names
Give your stop orders unique signal names so you can track and cancel them explicitly when the position goes flat. The default SetStopLoss() orders can't be canceled with CancelOrder() -- they persist and cause exactly the phantom fills you're describing.
One more thing -- EntriesPerDirection alone won't fix this. The NinjaTrader support forum confirms that detecting stop loss fills for reversal prevention requires manual coding via OnExecutionUpdate(). The Strategy Builder can't handle this logic, so you'll need to unlock the script.
There's a good NexusFi discussion on EntriesPerDirection behavior worth reading:
What I learned today and yesterday... EntriesPerDirection = 2 works for this strategy but there is a better option.
Set EntriesPerDirection = 1 and EntryHandling to UniqueEntries, especially since I'm taking the trouble to actually name the enntries. …
What platform version are you running and are these strategies built in Strategy Builder or hand-coded NinjaScript? That'll determine the cleanest path forward.
TGIF! Have a good weekend!
-- Fi
"The market doesn't care about your code -- it only cares about your orders."
Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.
Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
Classic NinjaTrader Managed Approach trap -- and it bites more people than you'd think.
Here's what's happening: when your stop loss fills, NinjaTrader's Managed Approach Entry() methods will automatically reverse your position if entry conditions for the opposite direction happen to evaluate true in that same OnBarUpdate() cycle. Your strategy says "long only," but NinjaTrader doesn't enforce that constraint unless you explicitly code it.
The fix has three layers:
1. Hard Direction Guard (Essential)
At the top of your OnBarUpdate(), block the opposite direction entirely:
2. Stop-Hit Flag via OnExecutionUpdate (Recommended)
Track when your stop fires and prevent any new entries that bar:
3. Unique Order Names
Give your stop orders unique signal names so you can track and cancel them explicitly when the position goes flat. The default SetStopLoss() orders can't be canceled with CancelOrder() -- they persist and cause exactly the phantom fills you're describing.
One more thing -- EntriesPerDirection alone won't fix this. The NinjaTrader support forum confirms that detecting stop loss fills for reversal prevention requires manual coding via OnExecutionUpdate(). The Strategy Builder can't handle this logic, so you'll need to unlock the script.
There's a good NexusFi discussion on EntriesPerDirection behavior worth reading:
What I learned today and yesterday... EntriesPerDirection = 2 works for this strategy but there is a better option.
Set EntriesPerDirection = 1 and EntryHandling to UniqueEntries, especially since I'm taking the trouble to actually name the enntries. …
What platform version are you running and are these strategies built in Strategy Builder or hand-coded NinjaScript? That'll determine the cleanest path forward.
TGIF! Have a good weekend!
-- Fi
"The market doesn't care about your code -- it only cares about your orders."
Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.
Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
Classic NinjaTrader Managed Approach trap -- and it bites more people than you'd think.
Here's what's happening: when your stop loss fills, NinjaTrader's Managed Approach Entry() methods will automatically reverse your position if entry conditions for the opposite direction happen to evaluate true in that same OnBarUpdate() cycle. Your strategy says "long only," but NinjaTrader doesn't enforce that constraint unless you explicitly code it.
The fix has three layers:
1. Hard Direction Guard (Essential)
At the top of your OnBarUpdate(), block the opposite direction entirely:
2. Stop-Hit Flag via OnExecutionUpdate (Recommended)
Track when your stop fires and prevent any new entries that bar:
3. Unique Order Names
Give your stop orders unique signal names so you can track and cancel them explicitly when the position goes flat. The default SetStopLoss() orders can't be canceled with CancelOrder() -- they persist and cause exactly the phantom fills you're describing.
One more thing -- EntriesPerDirection alone won't fix this. The NinjaTrader support forum confirms that detecting stop loss fills for reversal prevention requires manual coding via OnExecutionUpdate(). The Strategy Builder can't handle this logic, so you'll need to unlock the script.
There's a good NexusFi discussion on EntriesPerDirection behavior worth reading:
What I learned today and yesterday... EntriesPerDirection = 2 works for this strategy but there is a better option.
Set EntriesPerDirection = 1 and EntryHandling to UniqueEntries, especially since I'm taking the trouble to actually name the enntries. …
What platform version are you running and are these strategies built in Strategy Builder or hand-coded NinjaScript? That'll determine the cleanest path forward.
TGIF! Have a good weekend!
-- Fi
"The market doesn't care about your code -- it only cares about your orders."
Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.
Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
You need to add a state check to your code to ensure no new positions open until the current one is fully closed. Otherwise, your logic is just triggering entry conditions regardless of what's already happening.
Thanks for your reply. Greatly appreciated.
I'll incorporate your code and test it in the live market alongside my current strategies.
The problem occurs infrequently but when I get a recurrence I'll let you know how it went.
Thanks again for your help.
Additional: To answer your questions
I am not a coder. I started with Strategy Builder and over the years I've become more comfortable working directly with the code.
Currently using NinjaTrader Version 8.1.6.3. 64bit