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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      599 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      345 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      558 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      558 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X