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

What is the best way to implement a second method?

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

    What is the best way to implement a second method?

    I am currently using an TimerEvent with intervals of one second with a Task method, I have tried using it on OnBarUpdate() but it continuously hangs.
    The timer event method seems to be working fine, until I just started receiving the exception shown. I am not sure if the root of the issue is the timer itself.

    1. Is there a better implementation to have a continuous await task than a timer?
    2. Is my error in fact because it is a timer event?

    #2
    Hello lakersfan,

    Thank you for your post.

    Errors like this would be seen with incorrect management for the timer. For example, if you make a timer in State.Configure in a Strategy instead of State.DataLoaded, there will be 2 times State.Configure gets passed (Opening the strategies dialog and then enabling the strategy) and if there is no null check, another timer can be added and fail. The timer example on the help guide illustrates how to set up the timer in State.DataLoaded so that doesn't occur. I'd compare the structure of your timer to what's in this example:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Kate View Post
      Hello lakersfan,

      Thank you for your post.

      Errors like this would be seen with incorrect management for the timer. For example, if you make a timer in State.Configure in a Strategy instead of State.DataLoaded, there will be 2 times State.Configure gets passed (Opening the strategies dialog and then enabling the strategy) and if there is no null check, another timer can be added and fail. The timer example on the help guide illustrates how to set up the timer in State.DataLoaded so that doesn't occur. I'd compare the structure of your timer to what's in this example:



      Please let us know if we may be of further assistance to you.
      I am currently using marketreplay.
      is there perhaps a way to implement an await task after onbarupdate? Currently, it hangs when i have the function implemented onbarupdate. Timer event seems to work, but if theres a better fix, then im all ears.

      Yes, i have it on state.configure, I tried state.dataloaded, but my functions don't function on state.dataloaded. Is there another alternative?

      Comment


        #4
        Hello lakersfan,

        Thank you for your reply.

        Implementing an await task would be outside the realm of what we would be able to support, as that's outside the scope of NinjaScript.

        You would need to set up the timer in State.DataLoaded as that's the state that occurs after State.Configure. If you want to understand when the script enters a specific state, you can print the current State from within OnStateChange(). As in the example, just the initial setup would need to be in State.DataLoaded.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by warreng86, 11-10-2020, 02:04 PM
        7 responses
        1,360 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Perr0Grande, Today, 08:16 PM
        0 responses
        5 views
        0 likes
        Last Post Perr0Grande  
        Started by elderan, Today, 08:03 PM
        0 responses
        9 views
        0 likes
        Last Post elderan
        by elderan
         
        Started by algospoke, Today, 06:40 PM
        0 responses
        10 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        14 views
        0 likes
        Last Post maybeimnotrader  
        Working...
        X