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

Count Bar Volume

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

    Count Bar Volume

    Hello,

    I would like to make a simple modification to the "ruler" drawing tool, to display cumulative bar volume counted.

    Currently, the standard "ruler" tool (Ctrl+F3) displays number of Bars, Time, and Y-Value.

    I would like to add that it displays the cumulative value of the volume of the bars being "ruled".

    Hence it would display (as an example):

    # bars: 5
    Time: 01:15:00
    Y-Value: 20
    Volume: 20,500

    [This could be done as a separate volume-counter drawing tool if for some reason that would more simple, but it just seems logical it would be included with the existing "ruler"]

    Could someone show me how to do this (or if it has already been created as a separate indicator). I have gone through the file-sharing section of the forum but did not notice anything.

    Regards

    #2
    Hello ctgry8,

    You could certainly do this by duplicating the tool, while I couldn't walk you through the entire process I can provide a short video on how to duplicate this tool and where to start looking at modifying the code. Please note the video may be loud so please adjust the volume as needed.

    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


    Drawing tools by nature are fairly complex, but modifications to existing tools can be fairly straightforward after copying the initial tool.

    Once copied, you would likely need to look into using items like GetVolume and a for loop to iterate over the bars selected. This tool already has some logic in place to know what is the first bars index and the last bars index so you already have a range of bars. You would mainly need to look into modifying the rectangle that draws the text, and accumulating the volume for the selected range.

    In the script, you can likely use the following syntax to get the volume of a bar at a specific index: chartBars.Bars.GetVolume(0);



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thanks for the detailed response. I've gone through your screencast but I am still struggling to make any progress, aside from copying the drawing tool and looking through the sections you highlighted!

      I can see that in the existing "ruler" tool it using the logic of "endIdx - startIdx" for calculating the X,Y distances (time and price) being ruled. I cannot just copy this logic though and use the getvolume(), as I need to Sum the volume between the startidx and and endidx.

      The code I'm trying to type is:

      store the datetime of the start of the trendline
      store the datetime of the end of the trendline
      sum the cumulative volume for the bars greater than or equal to the first bar and less than or equal to the last bar.

      I appreciate your patience.

      Regards

      Comment


        #4
        Hello ctgry8,

        Yes, you would need create new logic to do the actions you want. The existing logic does not account for getting the volume between the range of bars so this would be the logic you need to create and append.

        If you need the Times of the bars rather than the indexes, you would need to use the indexes to get the times using GetTimeByBarIdx



        You can then get the volume of each bar still using GetVolume as you have the bars Index.

        What you do with the volume of each of these bars between the start and end selection would be up to how you want to handle that data. I had previously suggested using a for loop and loop over the region using GetVolume. This would allow you to accumulate the volume of each bar to a variable and then later use that value how you want.
        If you are unsure how to accumulate a value in C# you could use the following as an example:

        Code:
        double accumulatedValue = 0; 
        
        for(int i = 0; i < 10; i++)
        {
            accumulatedValue += 1;
        }
        This will add 1 to the existing value of accumulatedValue each time this loop occurs. The help guide example for GetVolume also uses a range of bars and is a more suitable sample for what you are trying to do, mainly you would just need to accumulate the volume instead of just setting a variable to the volume each iteration.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          floor pivots

          has ninja8 offered floor pivots yet or just pivots?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ursavent, Today, 12:54 PM
          0 responses
          1 view
          0 likes
          Last Post ursavent  
          Started by Mizzouman1, Today, 07:35 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by RubenCazorla, Today, 09:07 AM
          2 responses
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by i019945nj, 12-14-2023, 06:41 AM
          7 responses
          82 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by timmbbo, 07-05-2023, 10:21 PM
          4 responses
          158 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X