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

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 DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        12 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        12 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        11 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        7 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Working...
        X