What can I do to get the program to stop trying to place buy stop orders below the market; which is causing my program to disable itself?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Buy Stop Orders
Collapse
X
-
Buy Stop Orders
Hello,
What can I do to get the program to stop trying to place buy stop orders below the market; which is causing my program to disable itself?Tags: None
-
Hello AdeptistJune,
Thanks for your post.
This error message means that the strategy attempted to change an order to the wrong side of the market. If this is due to market volatility then there isn't really a way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this would occur.
Something you could consider is using GetCurrentBid() and GetCurrentAsk() to offset orders so that they are more likely to land on the correct side of the market.
See these help guide pages for more information.
GetCurrentBid(): https://ninjatrader.com/support/help...currentbid.htm
GetCurrentAsk(): https://ninjatrader.com/support/help...currentask.htm
You could also consider using RealtimeErrorHandling.IgnoreAllErrors to trap order errors in OnOrderUpdate.
Please note that setting this property value to IgnoreAllErrors can have serious adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method. You could consider trapping the rejected order by checking if the OrderState is Rejected within OnOrderUpdate() followed by defining your own order rejection handling behavior for the rejected order.
Please see the example in the help guide link below that demonstrates using RealtimeErrorHandling and trapping a rejected order in OnOrderUpdate().
RealtimeErrorHandling — https://ninjatrader.com/es/support/h...orhandling.htm
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Comment
-
Hello AdeptistJune,
Thanks for your note.
The sample code on the RealtimeErrorHandling help guide page demonstrates trapping a rejected order in OnOrderUpdate().
RealtimeErrorHandling — https://ninjatrader.com/es/support/h...orhandling.htm
Based on the sample code in the help guide link above, to resubmit the Exit order, you would call ExitLongStopMarket(); in the region that says '// Do something about it here' and offset the Exit order more, such as ExitLongStopMarket(Position.AveragePrice - 20 * TickSize, "myStopLoss", "myEntryOrder"); to ensure the order is submitted to the correct side of the market. For example:
Let us know if we may assist further.Code:private Order stopLossOrder = null; private Order entryOrder = null; protected override void OnStateChange() { if (State == State.Configure) { RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors; } } protected override void OnBarUpdate() { if (entryOrder == null && Close[0] > Open[0]) EnterLong("myEntryOrder"); if (stopLossOrder == null) stopLossOrder = ExitLongStopMarket(Position.Aver agePrice - 10 * TickSize, "myStopLoss", "myEntryOrder"); } protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity , int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { // Assign stopLossOrder in OnOrderUpdate() to ensure the assignment occurs when expected. // This is more reliable than assigning Order objects in OnBarUpdate, // as the assignment is not guaranteed to be complete if it is referenced immediately after submitting if (order.Name == "myStopLoss" && orderState == OrderState.Filled) stopLossOrder = order; if (stopLossOrder != null && stopLossOrder == or der) { // Rejection handling if (order.OrderState == OrderState.Rejected) { // Stop loss order was rejected !!!! // Do something about it here ExitLongStopMarket(Position.AveragePrice - 20 * TickSize, "myStopLoss", "myEntryOrder"); } } }Last edited by NinjaTrader_BrandonH; 05-13-2022, 09:19 AM.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Thanks,
How would write the code buystop entry order. I keep trying last night but the order would not resubmit
Comment
-
Hello AdeptistJune,
Thanks for your note.
EnterLongStopLimit() could be used to place a buy stop limit order to enter a long position.
EnterLongStopMarket() could be used to place a buy stop market order to enter a long position.
See the help guide documentation below for more information and sample code.
EnterLongStopLimit(): https://ninjatrader.com/support/help...gstoplimit.htm
EnterLongStopMarket(): https://ninjatrader.com/support/help...stopmarket.htm
Managed Approach Order Methods: https://ninjatrader.com/support/help...d_approach.htm
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Thanks Brandon,
I was talking about how to code the EnterLongStopMarket() when using RealtimeErrorHandling. The sample shows how to code the ExitLongStopmarket(), but not how resubmit the canceled EnterLonStopMarket().
Comment
-
Hello AdeptistJune,
Thanks for your note.
This would be done similarly to the ExitLongStopMarket() in the example. If the canceled order is an EnterLongStopMarket() order, you would check for the rejected order similar to the sample in post #4 and call EnterLongStopMarket() inside the condition that checks if the OrderState == OrderState.Rejected.
You would need to assign the entry order to an order object similar to how the example assigns the stop loss order to an order object. This is done by checking if the order.Name is equal to the signal name of your order, such as "myEntryOrder".
See the help guide documentation below.
RealtimeErrorHandling — https://ninjatrader.com/es/support/h...orhandling.htm
Let us know if we may assist further.
<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
71 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
143 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
76 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
47 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
51 views
0 likes
|
Last Post
|

Comment