Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnOrderUpdate() not working in Market PlayBack

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

    OnOrderUpdate() not working in Market PlayBack

    Hey guys,

    I have this indicator that is working fine in Sim and Live accounts but for some reason not working in Playback session.

    The function OnOrderUpdate() doesn't seem to work in playback.

    Is there a way I can make the indicator detect when I place a market order so that the indicator can place stops and limits by itself?

    When I use the function OnOrderUpdate(), it doesn't print the statement I am trying print.

    I would like to keep the codes in the indicator as the indicator is working fine for Sim and Live markets just not in Playback.

    Thank you.

    #2
    Hello IDumpedCinderella,

    Thank you for your post.

    OnOrderUpdate() it meant for strategy scripts, not indicators. If you want to use the AddOn approach, consider changing the method name to OrderUpdate() to avoid conflicts as a precaution.

    If the script is specifically not working in Playback, I recommend using prints to debug.

    It is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

    TraceOrders will also allow us to see when an order is submitted so we can check that there is an update from OnOrderUpdate. Make sure to print out the actual order object from OnOrderUpdate as well.

    I am happy to assist you with analyzing the output from the output window.

    Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

    https://support.ninjatrader.com/s/ar...nd-TraceOrders

    Comment


      #3
      ​If you look at the image attached, I tried changing to orderupdate() but the result is the same. The print is not printing anything in the output screen.

      I tried setting traceorders to true but the error I get is shown below.

      Are these not going to work on indicators? Only strategy scripts?

      Comment


        #4
        Hello,

        Thank you for your response.

        OrderUpdate does work in an indicator script.

        Are you subscribing to the event on the account?

        Code:
        if (account != null)
        account.OrderUpdate += OnOrderUpdate;​
        The Help Guide page below has sample code which demonstrates how to subscribe to the OrderUpdate event.

        Comment


          #5
          Yes! That worked for me. Thank you so much. Haha. I had to subscribe.

          Comment


            #6

            Hello!
            I have a similar issue as well. I'm trying to subscribe to the OnOrderUpdate event in a strategy, but I can't seem to get the OnOrderUpdate print event to occur when running playback data. Below is a quick example of what I'm attempting. Can you tell me what I'm missing to get my order tested and work during a market replay?

            Code:
            [FONT=Courier New]private Account DamAccount { get; set; }
            
            ...
            
            case State.Configure:
            
               if (account == null)
               {
                  account = Account.All.FirstOrDefault(x => x.Name == "Playback101");
                  Print("account.Name: " + account.Name);
               }
            
               // Subscribe to order updates
               if (account != null)
               {
                  account.OrderUpdate += OnOrderUpdate;
               }
            break;
            
            ...
            
            protected void OnOrderUpdate(object sender, OrderEventArgs e)
            {
               Print("OnOrderUpdate Order Name: " + e.Order.Name);
            }​[/FONT]
            Thanks!

            Comment


              #7
              Hello Jimmathy,

              Welcome to the NinjaTrader forums!

              Was the script added to the chart after the Playback101 account was connected?

              Were orders placed to the Playback101 account after the Playback101 account was connected and the script was added to the chart?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea, and thanks for the help!

                I think the answer to your first question is yes, the script was added to the chart after the Playback101 account was connected. More specifically, I started Ninjatrader, downloaded today's playback data, set the playback time to this morning at 9:30am, opened my strategies and enabled the strategy I coded, then pressed play in the playback to see if it would issue the orders I have in my strategy. I see the prints of the orders being created, but I can also see in the orders tab no order is actually created.
                Is this a symptom of using the market replay? I'm generally trying to figure out how I can enter and exit orders to test my strategy using the market replay feature.

                To your second question, yes, orders would be placed after the Playback101 account is connected. I'm connecting the Playback101 account at State.Configure before any order has the chance to be made. I confirmed this with some prints of the method showing the name of the associated account.

                Thanks again for your help! I greatly appreciate it!

                Comment


                  #9
                  Where is account defined in your script? I see an Account "DamAccount" defined, but not account which is what is being used throughout the code.

                  private Account account;

                  Additionally, which is there a "break" statement in your code in State.Configure?

                  I recommend taking a look at the example code from the Help Guide:



                  Comment


                    #10
                    Hi Gaby,
                    I had some success by adding the constructor similar to what is in your example.

                    However, I can only see orders that are generated by EnterShort(orderName) and EnterLong(orderName). I am trying to submit orders using EnterShortStopLimit(quantity, limityPrice, stopPrice, orderName) and EnterLongStopLimit(quantity, limityPrice, stopPrice, orderName), but these orders do not show up during OnOrderUpdate.

                    What is the difference between orders generated with and without stops and limits? And more directly for my strategy development, how to I subscribe to order events which occur from EnterShortStopLimit and EnterLongStopLimit?

                    Lastly, another issue I'm seeing is the strategy doesn't seem to update completely when I modify the script and re-run the strategy. I see prints from both versions when I reload the chart data. I still see prints from old versions after removing and adding the strategy back to the chart and clearing the output log. I have to reload NinjaTrader entierly to get that to work. Is there a better way to see changes without having to restart NinjaTrader?

                    Thanks again!
                    Last edited by Jimmathy; 10-30-2024, 11:43 AM. Reason: Added question about seeing older versions of prints after reloading a strategy.

                    Comment


                      #11
                      Hello,

                      All order events should cause an update in OnOrderUpdate().

                      Where are these orders being generated from? Are they all being submitted to the same account?

                      Comment


                        #12
                        Yes, they're all generated from the same account in the same strategy.

                        HTML Code:
                        if (IsBullish)
                        {
                            Print("EnterShortStopLimit - quantity: " + quantity + " | entryPrice: " + entry + " | entryOrderName: " + orderName);
                            //EnterShort("EnterShort-" + entry);                                // Produces Orders
                            //EnterShortLimit(quantity, entry, orderName);               // Does not produce orders
                            EnterShortStopLimit(quantity, entry, stop, orderName); // Does not produce orders
                        }
                        else
                        {
                            Print("EnterLongStopLimit - quantity: " + quantity + " | entryPrice: " + entry + " | entryOrderName: " + orderName);
                            //EnterLong("EnterLong-" + entry);                                // Produces Orders
                            //EnterLongLimit(quantity, entry, orderName);               // Does not produce orders
                            EnterLongStopLimit(quantity, entry, stop, orderName); // Does not produce orders
                        }
                        As you can see in the comments above, when I run the EnterShort or EnterLong methods, orders are created, and I can get updates. However, no orders are created for the EnterLongLimit, EnterShortLimit, EnterLongStopLimit, or EnterShortStopLimit methods.

                        I can't see what would have changed for any of these methods.

                        I also tried setting the entry and stops to the current bar's price and still no orders are generated.

                        Why would they not generate an order?

                        Thanks again for your help!​

                        Comment


                          #13
                          Is this an indicator or a strategy?

                          I'm assuming this is a strategy script as indicators can't use enter/exit methods - have you enabled TraceOrders to confirm the strategy is submitting the orders?

                          TraceOrders will also let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

                          Comment


                            #14
                            Correct, this is a strategy.
                            And I do have TraceOrders set to True at the configure state.

                            HTML Code:
                            case State.Configure:
                                TraceOrders = true;​
                            Here is what I see in the output for a given stop limit order entry:

                            HTML Code:
                            EnterLongStopLimit - quantity: 1 | entryPrice: 20419 | entryOrderName: OrderNameHere
                            10/22/2024 9:30:59 AM Strategy 'DamStrategy/341775945': Entered internal SubmitOrderManaged() method at 10/22/2024 9:30:59 AM: BarsInProgress=0 Action=Buy OrderType=StopLimit Quantity=1 LimitPrice=20389.00 StopPrice=20389.00 SignalName='OrderNameHere' FromEntrySignal=''​
                            When the strategy begins, there are some ignore messages stating there aren't enough enough bars to trade. But nothing seems obvious here of why an order wouldn't be updated after being issued.

                            What else can I look at to test why I see orders updating from market orders like EnterLong and EnterShort but not these stop limit orders?

                            Thanks again!

                            Comment


                              #15
                              Can you please post the full output? You can save the output by right-clicking within the output window > Save As.

                              Along with TraceOrders, print the Order object from OrderUpdate.

                              Comment

                              Latest Posts

                              Collapse

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