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

Event handling in My Code

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

    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.

    #2
    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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kevinenergy, 02-17-2023, 12:42 PM
    117 responses
    2,766 views
    1 like
    Last Post jculp
    by jculp
     
    Started by Mongo, Today, 11:05 AM
    5 responses
    15 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by SightCareAubetter, Today, 12:55 PM
    0 responses
    3 views
    0 likes
    Last Post SightCareAubetter  
    Started by traderqz, Today, 12:06 AM
    8 responses
    16 views
    0 likes
    Last Post traderqz  
    Started by SightCareAubetter, Today, 12:50 PM
    0 responses
    2 views
    0 likes
    Last Post SightCareAubetter  
    Working...
    X