I created a class with a list of properties to store values in my indicator. I created an instance of the class, and started assigning values to these properties. I decided it would be very useful to employ a property changed event in my class, so that when any of the properties are changed in my instance I can have my instance subscribe the the event and handle the event. I subscribed to the event (added the handler method to the event delegate using +=) in the initialize method. I put my event handler just before the OnBarUpdate method. Is this the correct place for these elements to go in my indicator, or would you recommend a different location for these? I'm having issues getting my event to fire, and I'm thinking I just don't have things in the right place.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Event handling in My Code
Collapse
X
-
Event handling in My Code
Hello,
I created a class with a list of properties to store values in my indicator. I created an instance of the class, and started assigning values to these properties. I decided it would be very useful to employ a property changed event in my class, so that when any of the properties are changed in my instance I can have my instance subscribe the the event and handle the event. I subscribed to the event (added the handler method to the event delegate using +=) in the initialize method. I put my event handler just before the OnBarUpdate method. Is this the correct place for these elements to go in my indicator, or would you recommend a different location for these? I'm having issues getting my event to fire, and I'm thinking I just don't have things in the right place.Tags: None
-
Hello CaptainAmericaXX, and thank you for your question.
C# is a near superset of C. This means that your code is location independent. You can verify this by moving your OnBarUpdate method physically above your Initialize routine. When you compile, you will notice that your indicator's function has not been changed. Physical position is only important within a method. You do not have control over when OnBarUpdate is being added to Ninja's internal event dispatchers.
If you would like to implement a PropertyChanged handler, I would recommend the approach taken in this publicly available MSDN reference,
Enable your properties to automatically notify a binding source when the property value changes in Windows Presentation Foundation (WPF).
You can do this in NinjaTrader by modifying your property's set method to hook into your handler with whatever message you would like to pass to it.
Please let us know if there are any other ways we can help.Jessica P.NinjaTrader Customer Service
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
157 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
91 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
143 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
130 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
107 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment