Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unsubscribing OnOrderUpdate not working

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

    Unsubscribing OnOrderUpdate not working

    deleted...
    Last edited by defa0009; 09-20-2024, 03:47 PM.

    #2
    Hello defa0009,

    Thank you for your post.

    The code posted looks like an account unsubscribing from OrderUpdate. Note that OrderUpdate on accounts is not the same as OnOrderUpdate for strategies.

    AddOn - https://ninjatrader.com/support/help...rderupdate.htm
    Strategy - https://ninjatrader.com/support/help...rderupdate.htm

    Is this a strategy script, or an AddOn?

    That said, I wouldn't expect order updates to occur on a disabled script. Can you provide output showing the script has hit State.Terminated but still continuing to run OrderUpdate events?

    Comment


      #3
      Hello defa0009,

      OnOrderUpdate() is already a strategy method and this is ambiguous, which is likely why you are getting the compile error.

      Use a different name like Account_OrderUpdate as the custom event handler name.

      I've tested this code out on my end in a strategy script, and when the strategy is disabled I am no longer getting any prints from the OrderUpdate method even when I continue to place orders on the account.

      Can you post a reduced test script that demonstrates the issue so we can test?

      To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
      1. Click Tools -> Export -> NinjaScript Add-on...
      2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
      3. Click the 'Export' button
      4. Enter a unique name for the file in the value for 'File name:'
      5. Choose a save location -> click Save
      6. Click OK to clear the export location message
      By default your exported file will be in the following location:
      • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
      Below is a link to the help guide on Exporting NinjaScripts.


      Once exported, please attach the file as an attachment to your reply.

      I look forward to receiving the export.​

      Comment


        #4
        Hello defa0009,

        Thank you for sharing that.

        You'll need to move this code from State.SetDefaults to State.DataLoaded:

        Code:
        lock(Account.All)
        account = Account.All.FirstOrDefault(a => a.Name == "Sim101");
        
        if(account != null)
        account.OrderUpdate += OrderUpdate;
        After moving that code, remove the old instance from the chart or Strategies tab then restart NinjaTrader. Add a new instance and test again.

        ​What is likely happening is that many instances are being created with your event handler assigned in State.SetDefaults, these instances are empty clones used for populating the UI which are not being terminated when expected.

        This is explained in a bit more detail on this Help Guide page:



        Please let us know if you need further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        597 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 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
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X