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

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



    JesseNinjaTrader Customer Service

    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 rocketman7, Today, 02:12 AM
      5 responses
      23 views
      0 likes
      Last Post rocketman7  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      7 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by samish18, 04-17-2024, 08:57 AM
      17 responses
      66 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by briansaul, Today, 05:31 AM
      1 response
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PaulMohn, Today, 03:49 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X