I am running a long only strategy that has different conditions to trail my stop-loss. However I've noticed that in very rare market conditions the logic of my script would trail the stop-loss lower rather than higher. I don't want this to happen and therefore I was wondering if there is any condition I can use to check the level of my current stop-loss in order to condition my order to trail the stop-loss to this. Please advise if I haven't been clear in what I am looking for.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
StopLoss Query
Collapse
X
-
StopLoss Query
Hi guys,
I am running a long only strategy that has different conditions to trail my stop-loss. However I've noticed that in very rare market conditions the logic of my script would trail the stop-loss lower rather than higher. I don't want this to happen and therefore I was wondering if there is any condition I can use to check the level of my current stop-loss in order to condition my order to trail the stop-loss to this. Please advise if I haven't been clear in what I am looking for.Tags: None
-
I am using IOrder, with mystoploss = ExitLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)Originally posted by NinjaTrader_Matthew View PostCan you please clarify which stop loss method you're using? Are you using SetStopLoss/SetTrailStop?
Comment
-
Hello,
Thanks for the clarification. If you're using an IOrder object, you can simply call the StopPrice property of that object:
This would allow you to confirm the price and if it is not what you expect you can add whichever logic you require to get the stop at the desired level.Code:protected override void OnOrderUpdate(IOrder order) { if (stopOrder != null) { Print(order.StopPrice); } }MatthewNinjaTrader Product Management
Comment
-
You could use a Math.Max() for long, or Math.Min() for short to compare the current stop with the proposed new stop.Originally posted by sburtt View PostHi guys,
I am running a long only strategy that has different conditions to trail my stop-loss. However I've noticed that in very rare market conditions the logic of my script would trail the stop-loss lower rather than higher. I don't want this to happen and therefore I was wondering if there is any condition I can use to check the level of my current stop-loss in order to condition my order to trail the stop-loss to this. Please advise if I haven't been clear in what I am looking for.
Comment
-
this isn't really what I meant, but thanks to your reply and koganam's I might have the solution. Assume I am long AAPL at 465 and my current stop is 460, lets say that OnBarUpdate my new stop condition is triggered and newStop = Low[0] - TickSize;Originally posted by NinjaTrader_Matthew View PostHello,
Thanks for the clarification. If you're using an IOrder object, you can simply call the StopPrice property of that object:
This would allow you to confirm the price and if it is not what you expect you can add whichever logic you require to get the stop at the desired level.Code:protected override void OnOrderUpdate(IOrder order) { if (stopOrder != null) { Print(order.StopPrice); } }
Would something like this work:
Code:if(stopOrder != null && order.StopPrice < (Low[0] - TickSize)) { mystoploss = ExitLongStop(..) // adjust stop-loss to newStop }
Comment
-
That looks workable, if your trigger is the Low of the CurrentBar. But, will you instantly understand what you wrote, when you come to look at it 6 months from now, when your logic is no longer fresh in your mind?Originally posted by sburtt View Postthis isn't really what I meant, but thanks to your reply and koganam's I might have the solution. Assume I am long AAPL at 465 and my current stop is 460, lets say that OnBarUpdate my new stop condition is triggered and newStop = Low[0] - TickSize;
Would something like this work:
Code:if(stopOrder != null && order.StopPrice < (Low[0] - TickSize)) { mystoploss = ExitLongStop(..) // adjust stop-loss to newStop }
You may want to make your program logic follow the structure of your data.
Code:double NewStop = ??? ; //calculate new stop value if (NewStop >CurrentStop) { CurrentStop = NewStop; //adjust stop price mystoploss = ExitLongStop(... CurrentStop,...); }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment