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

Force Update()

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

    Force Update()

    My indicator gets data from an Action and calls Update() after all calculations are done.
    However, Update() thinks that the bars are already uptodate and does nothing.
    How do I force Update() to actually run the OnBarUpdate() method again for all bars? Similar to ForceRefresh() for OnRender().

    #2
    Hello Bobin,

    I believe in the described use case you would want to just use a loop inside your action to do whatever calculation you needed on the existing bar data. Update is used for a parent script to tell a child to update, for example an indicator with no plots that exposes only a public bool property. If a parent script wanted the bool property to be populated for the CurrentBar then the child will have Update() inside that public property so that when the parent calls it the script runs the OnBarUpdate logic. That use case assumes that the child wasn't up to date when the parent called it (no plot being accessed) so it runs the bars. Your script is already up to date so that wont be useful for that use case.

    You would need to review what your OnBarUpdate logic is currently doing and see if that can be split into a method or if not you may need to just duplicate some of the logic inside your action and use a loop. If the action is not a NinjaScript event you may additionally need to surround the price data code inside that action with a TriggerCustomEvent: https://ninjatrader.com/support/help...ghtsub=trigger



    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,
      thank you.
      I tried to iterate through all bars after State.DataLoaded, however I get an error when accessing Time[]. I debuged and found out that I can't even access Time[20] even if the CurrentBar is 50.
      I was expecting Time to be ready for every bar in this state?

      Comment


        #4
        Hello Bobin,

        Did you try that in State.DataLoaded directly or from your action? If you are trying this from OnStateChange you can't use BarsAgo, bars aren't processing yet. You can use the GetValueAt and indexes at that point, for simplicity I would suggest to use OnBarUpdate instead. The error you are seeing is expected inside your action based on the reason I provided in the last post, in the action you need to use a TriggerCustomEvent for NinjaScript series and to use BarsAgo.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ChastiJose, Today, 03:37 AM
        0 responses
        3 views
        0 likes
        Last Post ChastiJose  
        Started by Klaus Hengher, Today, 03:13 AM
        0 responses
        3 views
        0 likes
        Last Post Klaus Hengher  
        Started by ewileznwpods, Today, 02:57 AM
        0 responses
        1 view
        0 likes
        Last Post ewileznwpods  
        Started by 1001111, Today, 01:35 AM
        0 responses
        6 views
        0 likes
        Last Post 1001111
        by 1001111
         
        Started by ETFVoyageur, Yesterday, 07:05 PM
        1 response
        16 views
        0 likes
        Last Post ETFVoyageur  
        Working...
        X