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

Custom Event in Indicator does not work?

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

    Custom Event in Indicator does not work?

    Hi,

    i tried to create a custom event in my indicator, that should handle buy or sell trigger. I want to use that event in my custom strategy to enter a trade. so that's what i want to do.

    but the problem is, that the custom event handler is always null (not initialized), and i don't know why. i've read several c# tutorials with event handler examples and i did it 1:1 but it does not work.

    is it not possible to create own events in indicators?

    here my short example code:

    Event Handler:
    Code:
            protected virtual void OnEventMessage(EventArgs e)
            {
    	    Print("OnEventMessage ...");
    	    EventHandler handler = EventMessage;
                if (handler != null)
                {				
                    handler(this, e);
    		Print("Handler sent EventMessage ...");
                }
    	    else
    	    {
    		Print("Handler is null @ EventMessage ...");
    	    }
            }
    	
            public event EventHandler EventMessage;
    And the call:
    Code:
    OnEventMessage(EventArgs.Empty);
    The Handler is always null and i don't know how to get it work ...


    Best Regards,
    Tom

    #2
    Hello Tom,

    Thank you for your post.

    You would use the TriggerCustomEvent(): http://ninjatrader.com/support/helpG...ustomevent.htm

    Comment


      #3
      Thank you Patrick for the link,

      but i don't understand how that should work. how can i register my strategy to the indicators event? the example in the link is working only in the same class i think. or i don't understand the example.

      do you have a short code snippet how to use this TriggerCustomEvent with the use of 2 classes?

      Comment


        #4
        Hello Tom299,

        Attached is an example.
        Attached Files

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bmartz, 03-12-2024, 06:12 AM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by Aviram Y, Today, 05:29 AM
        4 responses
        13 views
        0 likes
        Last Post Aviram Y  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        28 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X