Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

calling a funtion in an ontimed event

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

    calling a funtion in an ontimed event

    i have a an on timed event and I know that part is working , but how to I call my function

    I am getting an Object reference required for a non static field



    private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
    {
    MyFunction();

    }

    Do I create an event handler?
    Last edited by ballboy11; 07-18-2019, 12:34 PM.

    #2
    Hello ballboy11,

    You would need to remove the static modifier from your OnTimedEvent method. You made a Static method, that means to access MyFucntion it would also need to be static. In almost all cases static is not the right choice and you should instead use an instance.

    If this event was in an Indicator or Strategy, it should look similar to the following:




    Code:
    private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
    {
        MyFunction();
    }
    
    private void MyFunction()
    {
    
    }
    
    protected override void OnBarUpdate()
    {
    
    }
    There is also a sample which has a Timer and Event listed in the following page, you can ignore the TriggerCustomEvent part and focus on the Timer and its event handler: https://ninjatrader.com/support/help...ghtsub=trigger



    Comment


      #3
      Thanks Jesse. It worked perfectly. I need to research more c# I can code quite a bit but the static etc is where I need more research. THanks again.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      80 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X