Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Resubmit Order if Rejected

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

    Resubmit Order if Rejected


    Hello Ninja Trader Support,

    I have created an Automated Strategy which executes as expected but there are times when my ProfitTarget order is rejected due to price movement or for being outside of High or Low Band.

    I have set RealtimeErrorhandling to IgnoreAllErrors and have tried to implement an section in my script for OnOrderUpdate to resubmit the SetProfitTarget order if the OrderState is Rejected. I found some examples in the forum and documentation but it just isn't working.

    I have attached my OnOrderUpdate code as well as the Error Log lines that show the error. I ended up having to submit the order manually via ChartTrader.

    Thanks for all your help,


    Attached Files

    #2
    Hi

    No where in code you attached do I see you submit the replacement order.

    You were on the right track before you commented out this line..
    "//ExitShortLimit(0, true, Position.Quantity ...."

    Hedge


    Code:
    if (targetOrder != null && order.OrderState == OrderState.Rejected)
    {
    
    //ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - (ProfitTarget * TickSize), "Profit target", @"RSICrossShort");
    
    }

    Comment


      #3
      Hi Hedgeplay,

      Thanks for your help.

      I am using the SetProfitTarget order entry since I am using the managed approach. Does that command not work in the OnOrderUpdate section? I can switch to ExitShortLimit but just want to make sure it will still be tied to my strategy "RSICrossSort"

      Thanks again

      Comment


        #4
        Hi jakaniss, thanks for posting. We have a full example on how to monitor orders made with the Set methods here:


        When the order is rejected, and only in the rejected state, resubmit the profit target order.

        Kind regards,
        -ChrisL

        Comment


          #5
          Chris,

          Thank you very much for this. I have incorporated the same code into my strategy. When you have a moment could you please verify that my methodology changes (in bold below) to the sample code look appropriate. It seemed pretty straight forward but I could use a second set of eyes.

          Thanks again,

          Jason

          // Process profit target orders
          if (profitTargetOrders.Contains(order))

          {
          // Check order for terminal state

          if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled)

          {

          // Print out information about the order
          Print(order);

          // Remove from collection

          profitTargetOrders.Remove(order);
          }

          // If the target order is rejected then resubmit the order
          else if (order.OrderState == OrderState.Rejected)
          {

          Print("The order " + order.Name + " was rejected!");

          profitTargetOrders.Remove(order);

          SetProfitTarget(@"R",CalculationMode.Ticks, ProfitTarget);


          }

          else
          {
          // Print out the current stop loss price
          Print("The order name " + order.Name + " limit price is currently " + limitPrice);
          }
          }

          Comment


            #6
            HI Jason, this looks fine to me. It is a bit difficult to test in playback, so it will need to be monitored to make sure this works in real time trading.

            Kind regards,
            -ChrisL

            Comment


              #7
              Thanks Chris,

              Yea, I don't see a way to "test a rejection" so I am just watching a waiting. The upside is I feel my code is much more streamlined and the stops and targets are submitted much quicker and more accurately. Thanks again.

              Comment


                #8
                Originally posted by jakaniss View Post
                Thanks Chris,

                Yea, I don't see a way to "test a rejection" so I am just watching a waiting. ...
                I think you can test your rejection response code (without risky real money) by using the simulator to forward testing your strategy with live data but trading against a Sim account.

                Then in your code use a simple int counter to once every x bars or every x trades intentionally submit a StopLimit order on the wrong side of the Market

                .. the error popups will start flying at you and OnOrderUpdate() should show your order with a Rejected status which will allow you to test all of your Rejected error response scenarios.

                Hedge

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                70 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                143 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                76 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                47 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                51 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X