Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Stop Loss and profit target
Collapse
X
-
Hello Zinger357,
Thank you for your post.
Are you using Set methods from the Stops and Targets screen, or exit methods to submit the sl and tp?
Can you provide more detail about what behavior you are seeing? What exactly go you mean by the stop loss "goes away and doesn't work"?
Are you seeing any errors in the Log tab of the Control Center?
In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.
I'm also including a link to a forum post with further suggestions on debugging a script.
https://support.ninjatrader.com/s/ar...nd-TraceOrders
Enable TraceOrders, print the time of the bar and all values used in the conditions that submit entry orders. Include labels for all values and comparison operators.
Let me know if you need any assistance creating a print or enabling TraceOrders.
Save the output from the output window to a text file and provide this with your reply.
I'll be happy to assist with analyzing the output.
-
I'm sorry I should have included more details. The stop loss is set as a variable from the upper/lower on a bollingers bands plus/minus an input. This updates as the price moves higher or lower as a kind of trailing stop. Which if I stop compile and test in playback it works. Then if I add a profit target that function doesn't work. I'll follow your suggestions when I'm back home and let you know the results.
Comment
-
Ok so the 1st two I've included were my general stop within a simple program. The 3rd I'm including is just a simple program with profit target set in strategy builder and the trailing stop set in strategy builder. No matter what I do only one will work at a time. Clearly, I'm doing something wrong but as soon as I put the profit target in my stop loss goes away. It works great before I put the profit target in but once it's there there is no stop loss.
Comment
-
-
Hello Zinger357,
If you're setting your stop loss with Exit methods in the Conditions and Actions, that's fine and is possible in the Builder.i'm setting the stop loss in the conditions and actions that is causing my issues?
However, we still need the output from prints which I am not seeing in your output, I'm only seeing the results from TraceOrders.
The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.
If you are using the Strategy Builder in NinjaTrader 8, you can build prints in the Actions window under Misc -> Print. I recommend watching this video that demonstrates creating prints from the builder:
Additionally, what is the date/time stamp that we are examining for the ignored stop loss order?
Comment
-
NinjaScript Output 7_7_2024 8_12 PM.zip The log is giving me an Internal order handling rules that reduce unwanted positon in the help guide. I'm currently looking that up. But it doesn't do this until I enable the profit target. the stop loss works in playback fine.
Comment
-
Hello Zinger357,
This means the strategy is breaking one of the order handling rules below. From the Help Guide:
"Methods that generate orders to exit a position will be ignored if:
•A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
•A position is open and an order submitted by a set method (SetStopLoss() for example) is active"
https://ninjatrader.com/support/helpGuides/nt8/index.html?managed_approach.htm#InternalOrderHandl ingRulesThatReduceUnwantedPositions
Comment
-
The first zip is just the trailing stop using the SMA of a bollinger it works fine until I add the Profit target the second zip (sorry it's long). I read through stop loss guide and I don't believe I'm violating anything. But the stop loss always goes away when I compile with the profit target. NinjaScript Output 7_16_2024 7_51 PM.zip NinjaScript Output 7_16_2024 8_04 PM_after_profit_target_set.zip
Comment
-
Hello Zinger357,
Thank you for your post.
What date/time stamp are we looking at for the ignored stop loss?
I am seeing the following in your output:
7/10/2024 1:48:17 AM Strategy 'AANextAtempt/302491320': Ignored SubmitOrderManaged() method at 7/10/2024 1:48:17 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=5635.00 SignalName='Sell' FromEntrySignal='' Reason='Invalid order price, please see log tab'
It looks like the stop is getting submitted to an invalid price, leading to the order being ignored. What are you seeing in the Log tab of the Control Center?
Comment
-
Hey Gaby V. I'm including the log entries. Forgive me it's hard for me to understand this log. All the entries at 7:07:18 are the execution. NinjaTrader Grid 2024-07-17 07-10 PM.csv
Comment
-
Zinger357,
I am not seeing any entries in your output timestamped 7:07:18. Can you provide both the date and timestamp of the entry we are looking at?
I am seeing this is the Log:
Strategy 'AANextAtempt/302491319': An order has been ignored since the stop price 5614.5 near the bar stamped 7/07/2024 22:55:00 is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.
The message is letting you know that a stop order was ignored because the strategy submitted the order to an invalid price level. Buy stop orders must be placed above the current ask price. Sell stop orders must be placed below the current ask price.
When the order is submitted, is the stop price parameter greater than the GetCurrentAsk() for a buy stop order? Or, is the stop price parameter less than the GetCurrentAsk() for a sell stop order?
I would recommend you add prints to the strategy to determine why the stop order is being ignored. One line above where the stop order is placed, print the GetCurrentAsk() and print the price being submitted to the order method.
Below is a link to a forum post that demonstrates using prints to understand behavior.
Please see the help guide documentation below for more information about GetCurrentAsk() and GetCurrentBid().
We should also note that there is no intrabar movement with historical processing. If the strategy is using Standard Order Fill Resolution, it will create "virtual bars" based on the OHLC of the next bar to simulate how market data moved and then fill the order. If you use Order Fill Resolution set to High and use a 1 tick data series, the order will be filled with intrabar granularity because it is submitted to the single tick data series. The cases where this error is seen could be resolved using Order Fill Resolution set to High or adding a single tick data series to the strategy and submitting orders to that strategy.
Below is a video demonstration showing the debugging steps that would be taken to analyze how the error was received.
Demo - https://drive.google.com/file/d/14pT...w?usp=drivesdk
You could find the script used to test this on the this forum thread: https://ninjatrader.com/support/foru...82#post1104682
Let us know if you have any questions.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
557 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment