I'm having trouble with my stops constantly cancelling, and I can't work out if its a bug in my code of me misunderstanding the behavior in Ninjatrader.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Does SetStopLoss() Cancel on Next Bar ?
Collapse
X
-
Does SetStopLoss() Cancel on Next Bar ?
Just wanted to clarify something. If I am in a position via EnterLong() or EnterShort(). And I have called SetStopLoss(). Do I need to keep calling it on every bar?
I'm having trouble with my stops constantly cancelling, and I can't work out if its a bug in my code of me misunderstanding the behavior in Ninjatrader.Tags: None
-
Hello kevinenergy,
Thank you for the post.
This is likely related to the specific logic you have used, if you are simply using SetStopLoss with an entry, it should remain active. You can create small tests to confirm items like this, here is an example you could apply to a 10 second chart to see what the expected outcome is.
This type of test just submits a single order, waits for a bar then submits the stop which you can then watch as bars elapse to see if it cancels. I did not see it cancel but remained active.Code:protected override void OnBarUpdate() { if(State != State.Realtime) return; if(Position.MarketPosition == MarketPosition.Flat) { EnterLong(); } if(Position.MarketPosition == MarketPosition.Long && BarsSinceEntryExecution() == 1) { Print("called SetStopLoss"); SetStopLoss(CalculationMode.Ticks, 10); } }
You can also form other samples like this to be more like what you have created to see if the logic you used is part of the problem. If you are unsure why something is happening still after reducing the logic or making a sample like this, I would be happy to review that with you.
I look forward to being of further assistance.
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
111 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
59 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
38 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
41 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
78 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment