Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I need to prevent strategy from being thrown at me.

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

    I need to prevent strategy from being thrown at me.

    By means of a strategy that I develop, I place orders Buy Stop Limit, and Sell Stop limit, but sometimes the market is faster than the code to place the order, and when that happens, it shows me the following two messages, and it removes me the strategy, my question is, how can I do that if that happens, it doesn't take away my strategy ?, because when this happens I lose time while I activate it again, clicking on the check.

    (See the attached images)
    Attached Files

    #2
    Hello AdSeque,

    Thank you for your post.

    It is possible to tell your strategy to remain running when an order error is encountered. Setting RealTimeErrorHandling to IgnoreAllErrors will allow your strategy to keep running when errors like these are encountered (the popups will still appear to let you know an error was encountered).

    However, setting RealtimeErrorHandling to IgnoreAllErrors can have serious adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method. You would need to monitor for any rejected orders and then resubmit or otherwise handle the rejection.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thanks for your prompt response, how can I tell the strategy to continue executing even if it finds any errors?

      Comment


        #4
        Hello AdSeque,

        Thank you for your reply.

        I apologize, I neglected to link the help guide page going over RealTimeErrorHandling which is how you would tell it to ignore errors:



        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Can you explain to me what this error in the image I send you is about.
          Attached Files

          Comment


            #6
            Hello AdSeque,

            Thank you for your reply.

            This error can be seen for a number of reasons both within a strategy and when manually placing OCO (One Cancels Other) linked orders. In a strategy, we would usually see this in cases where a stop and profit target are submitted together for an order but one is rejected. Since these would be OCO linked to each other so that if one is filled the other one is cancelled, one getting rejected causes the other to not be accepted since there's an OCO id for the orders to link them together but the other order doesn't exist now.

            Basically, it's an additional error telling you that it couldn't place the profit target when you have an initial error in which your stop was rejected.

            Please let us know if we may be of further assistance to you.

            Comment


              #7
              How did you avoid that mistake?

              Comment


                #8
                Hello AdSeque,

                Thank you for your reply.

                There wouldn't be a way to completely avoid this - in a fast moving market there's always the chance the market will move far enough so quickly that in the time between you placing the order and it arriving to the broker that it could be on the wrong side of the market and be rejected. Turning on IgnoreAllErrors will simply allow you to handle what occurs in the script when a rejection is seen. For example, you could monitor in OnOrderUpdate and if your stop and target get rejected you could then attempt to resubmit the orders at a new price. Moving your stop and target further from the current price in the first place may reduce the chances of this occurring.

                Please let us know if we may be of further assistance to you.

                Comment


                  #9
                  protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                  {
                  // check if the current order matches the orderName passed in "EnterLong"()
                  // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
                  // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
                  if (order.Name == "BuyOrder")
                  BuyOrder = order;

                  // if entry order exists
                  if (BuyOrder != null && BuyOrder == order)
                  {
                  Print(order.ToString());
                  if (order.OrderState == OrderState.Cancelled)
                  {
                  // Do something here
                  BuyOrder = null;
                  }
                  }
                  //

                  if (order.Name == "SellOrder")
                  SellOrder = order;

                  // if entry order exists
                  if (SellOrder != null && SellOrder == order)
                  {
                  Print(order.ToString());
                  if (order.OrderState == OrderState.Cancelled)
                  {
                  // Do something here
                  SellOrder = null;
                  }
                  }




                  }

                  ---------------------------------------------------------------------------------------------------------------

                  Following the example of the tutorial, what this does is cancel the order, but the strategy would continue to work, if it meets the criteria again?

                  Comment


                    #10
                    Hello AdSeque,

                    Thank you for your reply.

                    This code would not cancel an order - this would check to see if an order is in a cancelled state and if so reset the order object to null. Further, these errors are likely coming through as OrderState.Rejected, so you would want to check for that state and then try resubmitting an order at a new price, or simply closing the open unprotected position directly by submitting an order to close it.

                    Also, unless you have changed the RealTimeErrorHandling in State.SetDefaults to IgnoreAllErrors the strategy would be stopped on a rejection.

                    Please let us know if we may be of further assistance to you.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    633 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    567 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X