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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    89 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X