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 Submission in OnOrderUpdate

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

    Order Submission in OnOrderUpdate

    Hello staff,

    I would like to submit an order when a different order is filled.
    Should I do this in OnOrderUpdate or somewhere else?
    What is the best approach to this?

    Thank you in advance for your response.

    All the best,
    GLFX

    #2
    Hello GLFX005,

    Thank you for your note.

    If submitting the second order is dependent on the first order being filled, I would definitely suggest monitoring in OnExecutionUpdate() instead of OnOrderUpdate().

    From our help guide:
    Critical: If you want to drive your strategy logic based on order fills you must use OnExecutionUpdate() instead of OnOrderUpdate(). OnExecutionUpdate() is always triggered after OnOrderUpdate(). There is internal strategy logic that is triggered after OnOrderUpdate() is called but before OnExecutionUpdate() that can adversely affect your strategy if you are relying on tracking fills within OnOrderUpdate().

    I would take a look at this example from our help guide - in this case it submits the protective orders only after the order is filled, but you could easily modify it to just submit a second order instead.



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello Kate,

      Thank you for providing me with this information, it has helped me enormously.

      Comment


        #4
        Hello Kate, or any other staff member,

        What would be the best method to cancel Working orders that have not been filled yet when certain conditions are met?
        Currently I am doing this in OnBarUpdate but it doesn't seem to have any effect on the order.

        And am I correct in thinking that assigning orders is best done in OnOrderUpdate?
        Example:

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

        I'm looking forward to your reply.
        Last edited by GLFX005; 12-13-2019, 08:45 AM. Reason: Added a second question

        Comment


          #5
          Hello GLFX005,

          Thank you for your reply.

          Working orders that have not yet been filled may be cancelled with the CancelOrder() method. Here's a link to the help guide:



          And here is an example of its use:



          How are you trying to cancel the order in OnBarUpdate() currently?

          Thanks in advance; I look forward to assisting you further.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Hello Kate,

            Currently I am cancelling the order like this

            if (Position.MarketPosition == MarketPosition.Long)
            {
            if (Close[1] > Open[1] && Close[0] > Open[0])
            {
            CancelOrder(L1E);
            }
            }


            and the order (L1E) that it is trying to cancel is this

            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
            if (L1 != null && execution.Order.Name == "L1")
            {
            if (execution.Order.OrderState == OrderState.Filled)
            {
            L1E = ExitLongStopLimit(0, true, 1, Open[0] - 1 * TickSize, Open[0] - 1 * TickSize, @"L1E", @"L1");
            }
            }


            L1E does trigger and fill when it does get filled, but the conditions in OnBarUpdate have not been able to cancel L1E when those conditions are filled.

            Another thing I would like to know is the following

            How can I make StopLimit orders trigger on the Ask/Bid instead of the Last Price?
            I tried to put my Data Series "Price Based On" to Ask or Bid, but this doesn't make a difference as I can still see the Last price line which is triggering the trades.
            Last edited by GLFX005; 12-13-2019, 12:09 PM.

            Comment


              #7
              Hello GLFX005,

              Thank you for your note.

              Setting a stop limit order will define the price at which you want the order to trigger, and the limit price will allow you to set a limit on the price at which you would want to be filled.

              Once the order is triggered, the Bid/Ask will contribute to determining whether or not the order is filled.

              Buy orders get filled at the ask and sell orders get filled at the bid. Technically, it's possible to rest a buy order at the bid or a sell order at the ask, but ultimately, these orders must each still fill at the ask price or the bid price, respectively. The Sell Stop order may be placed where you would like it but to fill it would have to be touched by the bid.

              As for why the order isn't cancelling, the first thing I would recommend would be to turn on the Order Trace function:

              Strategy Builder > Default Properties > More Properties > Trace Orders, or:

              if (State == State.SetDefaults)
              {
              TraceOrders = true;
              }

              Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

              Here is a link to our help guide that goes into more detail on tracing orders:



              Trace orders alone may not give you the full picture of whether or not a trade should have been entered or cancelled on a given bar, so adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful.

              This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.



              If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently, or make sure it prints something when it's about to try to cancel so you can tell it's even getting to that point in the code. With the printout information you can assess what is different between the two.

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hello Kate,

                Thank you for your detailed response, this will certainly be helpful in rooting out the problems that I am experiencing.
                I will let you know in this thread if any further issues occur.

                All the best,
                GLFX

                Comment

                Latest Posts

                Collapse

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