Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error: Submitted an order that has generated the following error: Order Rejected

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

    Error: Submitted an order that has generated the following error: Order Rejected


    Upon testing my code in playback mode, I get error:

    Buy stop or buy stop limit orders can't be placed below the market.
    Strategy submitted an order that generated the following error: "Order rejected" Strategy has sent cancel request, attempted to close the position and terminated itself.

    My code is:

    if (state == state.configure) {
    SetProfitTarget(6 ticks)
    SetStopLoss(6 ticks)
    }

    OnBarUpdate{
    ...if (condition1) EnterLong();
    if (condition2) EnterShort();
    }

    This leads to a couple of questions:

    1) Searching the forum, I see this question keep on coming up - and the answer is not consistent. Sometimes they ask to send log files of the environment. Other times they ask to change the environment. Why is this?


    2) As I understand the issue, this is caused when the current price moves so much just after the order is requested, either the profit target or stop loss becomes out of range. I'm using a 6 tick spread most of the time, so I find it difficult that as soon as I submit EnterLong or EnterShort, the market suddenly moves 6 ticks in one direction or the other, that my profit target or stop loss is now out of range - all within microseconds. I suspect something else is up? Can you explain?


    3) Is there any way this error can be captured, instead of terminating the program? It's irritating when I set up a large run on Playback, and then near the end, the strategy craps out on this error. Really, when this condition occurs, why can't NT simply cancel the order? This seems like something for a future enhancement request.

    As always, thanks for your help,










    #2
    Hello timmbbo,

    Thanks for your post.

    "Buy stop or buy stop limit orders can't be placed below the market.
    Strategy submitted an order that generated the following error: "Order rejected" Strategy has sent cancel request, attempted to close the position and terminated itself."


    ​This error message means that the strategy attempted to place 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 by checking error == ErrorCode.OrderRejected.

    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. To do this you could trap 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
    Brandon H.NinjaTrader Customer Service

    Comment


      #3

      Brandon, thanks for your reply (on a Sunday no less). Here's where I'm having mental block - how can you get out of range, when you're entering at the market price?


      I'm using EnterLong() and EnterShort() to enter the market. As I understand it, this will generate a market order - at the current market price. Therefore, if I'm entering the market at the current price, and I have a 6 tick profit margin / stop loss, then how is my order moving outside of these bounds? Let's put some numbers on this to clarify:

      I have a 6 tick profit margin / stop loss. The market is at 100. I specify EnterLong(). In my experience, this usually means I under a tick over the market, so I'll enter at 101. So, I'd expect my stop loss to be at 95, and my profit margin to be at 106. Given this, it's really unclear to me how, when the market is at 100, it moves so dramatically, in less than a second, to be outside of the profit margin / stop loss range.

      Furthermore, it's unclear to me how your proposed solution of using GetCurrentBid() remedies this issue? It seems like I'm stuck in the exact same quandary. I can go ahead and get the current price, and then submit an order to go long at that current price. Inbetween these two calls, the market could make a drastic move, where my profit target / stop loss again are out of bounds.

      I hope I explained myself clearly. I appreciate your extra assistance, and I hope you enjoy your 4th of July.
      Last edited by timmbbo; 07-02-2023, 06:44 PM.

      Comment


        #4
        Hello timmbbo,

        Thanks for your notes.

        The error could possibly be caused when the stop/target orders are submitted instead of being caused by the entry order.

        It could be possible for the market to move very quickly from the time your entry order is placed to the time the stop/target orders are placed.

        You could print out the order object in OnOrderUpdate() to see how the orders are being submitted. Add prints in OnOrderUpdate() that print out the order object to see how it is behaving.

        OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121

        RealtimeErrorHandling could be used to ​trap order errors in OnOrderUpdate by checking error == ErrorCode.OrderRejected and then you could define your own order rejection handling behavior for the rejected order. See the RealtimeErrorHandling information on post # 2.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Patlpp, 08-16-2021, 03:10 PM
        10 responses
        498 views
        0 likes
        Last Post Joerg
        by Joerg
         
        Started by AdamDJ8, 05-07-2024, 09:18 PM
        2 responses
        17 views
        0 likes
        Last Post -=Edge=-  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        46 responses
        4,101 views
        3 likes
        Last Post tradgrad  
        Started by usasugardefender, Today, 01:42 AM
        0 responses
        1 view
        0 likes
        Last Post usasugardefender  
        Started by haas88, 03-21-2024, 02:22 AM
        15 responses
        182 views
        0 likes
        Last Post haas88
        by haas88
         
        Working...
        X