Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rejected Order Resubmit Code Not Working?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Rejected Order Resubmit Code Not Working?

    Hi all,

    Recently I've built some strategies that use StopMarket and StopLimit orders for entry. However, there have been occasions during high volatility where we are noticing order rejection popups that say something to the effect of "Order Rejected: Buy stop price must be above current market price"

    So, I'm playing around with some different ways of managing this case and re-submitting the order upon rejection if an entry signal is still valid.

    However, even with this new order rejection and resubmit code, I'm still noticing the error popup. Cand a member of the support team have a look at my approach and let me know what I'm missing?

    The core idea is simple,

    1) Define a global variable for keeping track of the current order
    HTML Code:
    private Order _order;


    2) Assign that variable during the entry call
    HTML Code:
    _order = EnterLongStopMarket(0, true, 1, BO_Level, "RatioBreakoutStrategy");
    3) Then, in OnOrderUpdate(), check if the order was rejected and has the same name as our previously submitted order. If so, resubmit using the current ask price + 2 ticks

    HTML Code:
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
    {
    
    if (orderState == OrderState.Rejected)
    {
    
    if (_order.Name == "RatioBreakoutStrategy") {
    _order = EnterLongStopMarket(GetCurrentAsk() + (2*TickSize),GetCurrentAsk() + (2*TickSize), "RatioBreakoutStrategy");
    
    }
    
    
    }
    }​
    Anything jump out to you all as to why we would still be getting multiple order rejections in a given day?
    Attached Files
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    Hello jaybedreamin,

    Thank you for your post.

    There are different approaches to avoiding the invalid order price.

    For the examples below, consider a variable holding your calculated stop price. This could be a price from a custom calculation, or one obtained from an indicator. In these examples 100 will be used as a place holder.

    Code:
    ​stopPrice = 100; // ← price you have calculated to use as the stop price
    Using Math.Max() / Math.Min() to ensure the calculated stopPrice is above/below the ask/bid:​

    Code:
    // ensure sell stop order is below the bid
    stopPrice = Math.Min(stopPrice, GetCurrentBid() - 1 * TickSize);
    ExitLongStopMarket(stopPrice);
    Code:
    // ensure buy stop order is above the ask
    stopPrice = Math.Max(stopPrice, GetCurrentAsk() + 1 * TickSize);
    ExitShortStopMarket(stopPrice);
    Using a condition to submit a market order to exit immediately, instead of a stop order, if the stopPrice is ahead of the market:
    Code:
    // if calculated exit sell stopPrice is less than the bid use stopPrice for stop
    // otherwise exit long position immediately with a market order
    if (Position.MarketPosition == MarketPosition.Long)
    {
    // if the stopPrice value is a valid price, use the stopPrice
    if (stopPrice < GetCurrentBid())
    {
    ExitLongStopMarket(stopPrice);
    }
    // otherwise exit immediately with a market order
    else
    {
    ExitLong();
    }
    }
    
    // if calculated exit buy stopPrice is greater than the ask use stopPrice
    // other wise exit short position immediately with a market order
    if (Position.MarketPosition == MarketPosition.Short)
    {
    if (stopPrice > GetCurrentAsk())
    {
    ExitShortStopMarket(stopPrice);
    }
    else
    {
    ExitShort();
    }
    }
    ​
    However, please note that if the error occurred due to market volatility, then there is no way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this would occur.

    Please let me know if we can assist further.​​

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X