Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Unsubscribing OnOrderUpdate not working
Collapse
X
-
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?
-
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:- Click Tools -> Export -> NinjaScript Add-on...
- Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
- Click the 'Export' button
- Enter a unique name for the file in the value for 'File name:'
- Choose a save location -> click Save
- Click OK to clear the export location message
- (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Once exported, please attach the file as an attachment to your reply.
I look forward to receiving the export.
Comment
-
Hello defa0009,
Thank you for sharing that.
You'll need to move this code from State.SetDefaults to State.DataLoaded:
After moving that code, remove the old instance from the chart or Strategies tab then restart NinjaTrader. Add a new instance and test again.Code:lock(Account.All) account = Account.All.FirstOrDefault(a => a.Name == "Sim101"); if(account != null) account.OrderUpdate += OrderUpdate;
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
556 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
555 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment