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

Order rejected on live trading strategy

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

    Order rejected on live trading strategy

    Case 1:
    The order terminated itself, I'm no idea.

    Submitted an order that generated the following error 'Order rejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
    Case 2:
    When the strategy should submit the ExitLongLimit() to exit the current position but no signal show on the platform. How can i know the strategy had submit the request to the broker or not?

    ExitLongLimit(1, true, entryOrder.Quantity, Open[0], LIMIT, OPEN_LONG);

    #2
    Hello matrixxx,
    Thanks for your post.

    We would need to see the reason given by the platform for the order rejection. You will likely find it in the immediate vicinity of the message you posted.

    In regards to "case 2":

    Does the strategy show an error when it is supposed to submit its exit order?

    Do you see that the order was submitted on the 'Orders' tab of your Control Center?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Hi JoshG,

      Case 2, No order submitted on the order tab.

      Comment


        #4
        Have you confirmed (with Print statements) that your conditions are becoming true to submit the ExitLongLimit order?
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Hi JoshG,


          The conditions is true and printed the time before submit the order function but no order and no error show on the platform. I'm using Ninjatrader FXCM trial account.

          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
          {
          if (order.Name == OPEN_LONG || order.Name == OPEN_SHORT)
          {
          entryOrder = order;
          }
          else
          {
          if (order.OrderState == OrderState.Filled)
          {
          entryOrder = null;
          }
          }

          if (entryOrder != null && entryOrder == order)
          {
          if (order.OrderState == OrderState.Filled)
          {
          if (order.Name == OPEN_LONG)
          {
          Print("=========================================== ===");
          Print("");
          Print(Time[0]);
          Print("ExitLongStopMarket()");
          Print("");

          ExitLongStopMarket(1, true, quantity, Low[0], STOP, OPEN_LONG);
          }
          }
          else if (order.OrderState == OrderState.Cancelled)
          {
          entryOrder = null;
          }
          }
          }


          Is it different if i use the demo account to execute the strategy like live account?
          Is it use same api to process the order?


          After add some code to get the reference to the stop order and add more print log.

          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
          {
          if (order.Name == OPEN_LONG || order.Name == OPEN_SHORT)
          {
          entryOrder = order;
          }
          else
          {
          if (order.OrderState == OrderState.Filled)
          {
          entryOrder = null;
          }
          }

          if (entryOrder != null && entryOrder == order)
          {
          if (order.OrderState == OrderState.Filled)
          {
          if (order.Name == OPEN_LONG)
          {
          Print("=========================================== ===");
          Print("");
          Print(Time[0]);
          Print("ExitLongStopMarket()");
          Print("");

          Order stopOrder = ExitLongStopMarket(1, true, quantity, Low[0], STOP, OPEN_LONG);

          Print("StopOrder: " + Time[0]);
          Print("stopOrder.OrderId: " + stopOrder.OrderId);
          Print("stopOrder.Name: " + stopOrder.Name);
          Print("stopOrder.OrderType: " + stopOrder.OrderType);
          Print("stopOrder.OrderState: " + stopOrder.OrderState);
          Print("");
          }
          }
          else if (order.OrderState == OrderState.Cancelled)
          {
          entryOrder = null;
          }
          }
          }
          I got the following error.

          Error on calling 'OnOrderUpdate' method on bar 3552: Object reference not set to an instance of an object.
          The platform didn't throw the order submit fail if i didn't add the "Order stopOrder = ExitLongStopMarket()" to get the object reference to throw the error. I'm using 1 min time frame.


          Please advise. Thanks.


          William
          Last edited by matrixxx; 05-16-2018, 03:01 AM.

          Comment


            #6
            That error looks like the result of attempting to access an order object without checking to see if it is null first. You should always check if an object variable is null before attempting to access the object.

            The following forum post goes into detail on checking for null references.


            Running your strategy on the demo data feed will not impact your strategies logic or executions.
            Last edited by NinjaTrader_JoshG; 05-16-2018, 09:01 AM.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Dear JoshG,

              My problem is why the submit order return null. The ExitLongStopMarket() not submit the order to broker and no submit log show on the platform.

              I would like to set the stop loss when the long/short order filled.

              Please advise.

              William
              Last edited by matrixxx; 05-16-2018, 09:25 AM.

              Comment


                #8
                My problem is why the order is null
                The order variable is null because it has not been assigned an Order object yet. Thus when trying to access the object properties it fails and yields the “Object reference not set…” error since the variable is null. The order being null is not an issue. You just need to check for it to be null before accessing it.
                The ExitLongStopMarket() does not submit the order
                Your strategies orders are not submitting because of the object reference error.
                I would like to set the stop loss when the long/short order is filled
                We have a sample in our help guide that demonstrates how to implement this in your strategy.
                Help Guide - Using OnOrderUpdate() and OnExecution() methods to submit protective orders
                Josh G.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by matrixxx View Post
                  Case 1:
                  The order terminated itself, I'm no idea.

                  Case 2:
                  When the strategy should submit the ExitLongLimit() to exit the current position but no signal show on the platform. How can i know the strategy had submit the request to the broker or not?
                  Last year, I realized that there was some issue with Forex Limit orders, regardless was FXCM or another broker. It seemed that whenever you submitted a limit order ( with that fast quotes in 1/10 pips ) with a price a little off, the order was rejected. I've brought that issue up to NT support attention. I'm still not sure if this is cause Brokers only accept orders in HalfPips or cause a little mismatch with bid-ask prices triggers a bug. I'll be listening to the findings of support team.

                  Comment


                    #10
                    Originally posted by pstrusi View Post
                    Last year, I realized that there was some issue with Forex Limit orders, regardless was FXCM or another broker. It seemed that whenever you submitted a limit order ( with that fast quotes in 1/10 pips ) with a price a little off, the order was rejected. I've brought that issue up to NT support attention. I'm still not sure if this is cause Brokers only accept orders in HalfPips or cause a little mismatch with bid-ask prices triggers a bug. I'll be listening to the findings of support team.

                    I fixed the issue by move the exit order to OnExecutionUpdate.

                    Comment


                      #11
                      Hi i realized having the same issue with limit orders trading forex so i decided to go with StopLimit orders but still they are rejected at some occasion.


                      The iorders routine i created don't work and i would be interested to get your solution.


                      What have you done to solve the rejected orders??

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bortz, 11-06-2023, 08:04 AM
                      47 responses
                      1,606 views
                      0 likes
                      Last Post aligator  
                      Started by jaybedreamin, Today, 05:56 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post jaybedreamin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      13 views
                      0 likes
                      Last Post Javierw.ok  
                      Working...
                      X