Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Initial Balance Total Volume

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

    Initial Balance Total Volume

    I need calculate the total volume on first hour of the day.
    This is my code, but the volume reset on each bar update. I need accumulate and works en any type of chart.

    Code:
    private double ib_volume=0;
    
    protected override void Initialize()
            {
                CalculateOnBarClose	= true;
            	 Overlay = true;
    			
            }
    protected override void OnBarUpdate() {
       
        if (Bars.FirstBarOfSession)
                {
    				
    				ib_volume =  0;
    				
              }
        if (ToTime(Time[0]) >= 90000&& ToTime(Time[0]) < 10000) {
    
            ib_volume += Volume[0];
        }
    
    
        Font f = new Font("Courier New", 9, FontStyle.Regular);
    
        DrawTextFixed("tag22", "IB Volume: " + ib_volume, TextPosition.TopLeft, Color.Lime, f, Color.Transparent, Color.Black, 3);
    
    }

    #2
    Hello nekroart,

    When you add the code

    Code:
    if (Bars.FirstBarOfSession)
    {
    ib_volume =  0;
    }
    This would reset on the first bar close of the session.

    What is the bar type and interval of your chart?

    Are you wanting to trigger the reset after the first bar of the session has fully closed?

    Are you wanting to trigger the reset on the first tick of a new bar once a new bar has opened in a new session?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I use 30 minute bar and 6 renko bars.
      I want to calculate the total volume from 9 AM to 10 AM and show on the chart until the next day. When a new day begins, go back to 0 and start over.

      Comment


        #4
        Hello nekroart,

        Your logic will need to be specific.

        Are you wanting to reset on the first tick of the session or after the close of the first bar of the session?

        Is this running in historical data or real-time data?

        Currently, your code will wait until the first 30 minute bar has closed and then will reset the value.

        If you are wanting to trigger something on the first tick, you will need to add a 1 tick series and then trigger the action on the first tick of a new session.

        Below is a link to a forum thread on intra-bar granularity.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X