Above is a segment of code in the onbarupdate function as you can see from the execution I should be stopped out according to the price action. However, Even when I set this to 1 tick. It never stops me out? What gives?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SetStopLoss() not triggering as expected
Collapse
X
-
SetStopLoss() not triggering as expected
Above is a segment of code in the onbarupdate function as you can see from the execution I should be stopped out according to the price action. However, Even when I set this to 1 tick. It never stops me out? What gives?Tags: None
-
Hello RISKYBUSINEZZ,
Thank you for your post.
Are you seeing any errors in the log tab of the Control Center?
Set methods cannot be unset and will continue to hold their values for new entry orders.
This means it is important to reset Set methods using a number of Ticks, Percent, or Currency before placing a new entry (or using a unique signalName for each new entry). (Setting to a specific price may be an invalid price when the entry order fills, especially for entry limit and stop orders)
Please note your fromEntrySignal "Stop Out" does not match the signalName of the entry "DON Long 1".
Before calling a new entry call the Set methods first, one line above the entry method.
Code:if (Position.MarketPosition == MarketPosition.Flat) { // reset the stop loss before entry, so this is no longer set to a specific price which may be invalid when the entry fills SetStopLoss(CalculationMode.Ticks, 20) EnterLong(); } // after the entry fills, the stop loss can be moved to any desired valid price if (Position.MarketPosition == Market Position.Long && Close[0] > Position.AveragePrice + 10 * TickSize) { // after 10 ticks of profit, set the stop loss to the maximum valid price SetStopLoss(CalculationMode.Price, GetCurrentBid() - TickSize); }
The help guide notes:
“Notes:
Since they are submitted upon receiving an execution, the Set method should be called prior to submitting the associated entry order to ensure an initial level is set.“
“Tips:
You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position
Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position”
NinjaScript > Language Reference > Strategy > Order Methods > Managed Approach > SetStopLoss()
-
Just want to reply back that this has been solved, the issue was that the stop loss was looking for an order name to set the stop loss from. Instead of the last order like it was supposed to.
Comment
-
Hi,
I have the same issue with SetStopLoss not triggered as expected. Is it because the entry order was placed manually from Chart Trader ?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
55 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
132 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment