Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsFistTickOfBar inside of OnRender

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

    IsFistTickOfBar inside of OnRender

    I have an indicator that displays some variables within the OnRender. It works fine but I would like to reduce the CPU Utilization.
    I inserted an If Statetement "if (IsFirstTickOfBar==true)", but the indicator stills running several times inside of a formation of the bar.
    the code is as follows:
    Click image for larger version

Name:	image.png
Views:	139
Size:	36.4 KB
ID:	1248121
    and the output is as shown in the next screeenshot
    Click image for larger version

Name:	image.png
Views:	88
Size:	4.7 KB
ID:	1248122
    the goal is to ONLY pass though only one time per Current bar.
    Any ideas??
    Thank you !!!
    FVJ

    #2
    You should not be doing calculations in OnRender, only displaying things. Calculations should be done in OnBarUpdate, unless there is a truly special reason to put them somewhere else. There's no such notion as IsFirstTickOfBar during OnRender, because an OnRender event is not about a specific tick. OnRender is called when the chart control needs to be repainted, which is not every tick since that would be way too slow. The most important thing by far is you need to reframe your thinking about what you're doing here. OnRender runs whenever it needs to repaint the chart and that has nothing to do with a tick or a bar being completed or anything else like that - it repaints when it needs to repaint because time has passed, because you scrolled the scroll bar, or for any number of other reasons. Your calculations that might possibly be affected by IsFirstTickOfBar should be done in OnBarUpdate().
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hi efeuvejota01, You should capture the data you need from the first tick of the bar in OnBarUpdate and then use the data in OnRender. OnRender is not a data-driven event so its likely it can be called more than once per incoming tick.

      Kind regards,
      -ChrisL​

      Comment


        #4
        Thank you for your answers

        Do you have any clue on how to pass through this process only once per currentbar??
        FVJ

        Comment


          #5
          You cannot make OnRender run only once per bar - use OnBarUpdate for that.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          653 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X