Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Passing values from OnRender to OnBarUpdate

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

    Passing values from OnRender to OnBarUpdate

    I want to calculate number of bars visible on the chart and I found it being possible using OnRender.

    However, it is able to Print correct value, BUT I cannot pass it to OnBarUpdate, in which I run my calculations. [1- calculations don't work, 2- Print command run in OnBarUpdate returns 0]

    I could add, that I want this to work not just in RealTime, but also in any mode, like Backtest, Simulation and all that. 95% of my work is done "behind the scenes", so I want to test it properly before going Live.

    How can this be fixed?

    #2
    Hello UltraNIX,

    As far as I know, ChartBars.FromIndex and ChartBars.ToIndex can be used in OnBarUpdate().
    https://ninjatrader.com/support/help..._fromindex.htm

    To confirm, you are printing ChartBars.FromIndex and nothing is printing?
    Are you printing the time of the bar with it? Does the time appear?

    Further, I would not recommend doing any calculations in OnRender() to use in OnBarUpdate(). In fact, don't do any calculations in OnRender() unless its specific to rendering and absolutely cannot be done outside of OnRender().

    See 'Precomputing values instead of calculating in OnRender()' in the help guide.
    Last edited by NinjaTrader_ChelseaB; 04-10-2022, 03:15 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Time prints, value, if printed from OnBarUpdate is 0, while if I print the same value from OnRender - it prints correct value (not 0).

      From the help guide, if I understand correctly, especially, in State.Historical, OnBarUpdate precedes OnRender and not the other way around. What I mean is that if I set a value for variable in OnRender and want it to pass it to OnBarUpdate - it, as in my example, returns 0. However, if I set a value for variable in OnBarUpdate and want to pass it to OnRender - it should work.

      So can you suggest a workaround to pass OnRender values to OnBarUpdate?

      Comment


        #4
        Hello UltraNIX,

        "Time prints, value, if printed from OnBarUpdate is 0, while if I print the same value from OnRender - it prints correct value (not 0)."

        I'm not not certain if you are saying the Time[0] is printing a 0, or if ChartBars.FromIndex is printing a 0.
        I am not able to reproduce either behavior.

        Attached is a test script. Below is a link to a video of the test.


        The ChartBars, ChartPanel, ChartScale values update in State.Realtime only.


        As far as pass OnRender values to OnBarUpdate(), you can make a class level variable and read that value. You will have to wait in OnBarUpdate until after OnRender() has run.

        Note that OnRender() is running when the chart is rendering, which is not in sequence with OnBarUpdate().
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I am using
          Code:
          chartControl.SlotsPainted

          Comment


            #6
            Hello UltraNIX,

            If you just want a number of bars visible, this value will be greater than 0 if there are bars visible in real-time.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I understand, but I need it also in Historical, as most of my coding, testing and adapting happens in Historical (via backtest and just looking at "offline" chart), and not in RealTime.

              Comment


                #8
                Hello UltraNIX,

                Visual information is not available in historical. OnRender() will not have even run until the script reaches real-time.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for your help anyway, I structured it to be conditional, and, even without limitations, I am happy with the result.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  647 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  369 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  108 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  572 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  573 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X