• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volume of barsAgo clarification

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

    Volume of barsAgo clarification

    How do I properly use Vol()[x] ?
    Where is a larger integer, say 1440.

    When I use an int greater than 5, my Indicator errors.

    My ultimate goal is to chart a comparison of current bar volume and volume of bar 24 hours ago to the minute.
    So volume of bar 2018-10-23 10:00:00 compared to 2018-10-22 10:00:00

    Example code:

    //double value1 = VOL()[10];

    //Print("The last week's VOL value is " + value1.ToString());

    I have over 20000 bars loaded.

    Thank you in advance - jch
    Last edited by [email protected]; 10-23-2018, 07:52 PM.

    #2
    Hello John,

    Thanks for your post and welcome to the forums.

    For your own protection, you may want to change your forum name to not be an e-mail address as you are likely to receive unwelcome e-mails from bots that scan forums for e-mail addresses.

    The error that you are running into occurs when your lookback exceeds the number of bars the indicator has processed. When an indicator is started it will load the first bar of data and execute the code in OnBarUpdate(), then the next bar is loaded and so on. If you are accessing VOL()[10] when there are only 5 bars loaded then the indicator would error out and an error message would appear in the "log" tab of the control center.

    To prevent this, you can add a condition to prevent code execution until the appropriate minimum number of bars has been processed by the indicator.

    If your lookback is a static value, such as [10] then at the top of OnBarUpDate() you can add code to prevent execution by checking to see if the current bar count is less than 10. NinjaTrader provides the property CurrentBar which contains the number of bars processed at the moment. for example:

    if (CurrentBar < 10) return; // prevent code below this line from running until first 10 bars loaded.

    Reference: https://ninjatrader.com/support/help...currentbar.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Paul. Your feedback provides the answer I was looking for. Much appreciated.

      Comment


        #4
        Click image for larger version

Name:	2018-10-29_10Bars.png
Views:	1
Size:	197.0 KB
ID:	1037591Click image for larger version

Name:	2018-10-29_20Bars.png
Views:	1
Size:	213.7 KB
ID:	1037592 Paul et al,

        In the attached, when I reference 10 barsAgo, I get the first result as expected.

        However, in the second image, I changed the barsAgo to 20 and the script errors.

        How can this be if me CurrentBar is greater than 117580?

        Maybe I do not understand the CurrentBar variable. Is this not how many bars are available to my indicator?

        Again, my goal is to compare the most current bar volume to the volume 1400 bars ago.

        I am open to any suggestion or recommendations for further research/study.

        Comment


          #5
          Hello John,

          Thanks for your reply.

          Please add the current bar check I previously advised and make sure that the bar check matches your longest bars ago reference.

          If your lookback is a static value, such as [10] then at the top of OnBarUpDate() you can add code to prevent execution by checking to see if the current bar count is less than 10. NinjaTrader provides the property CurrentBar which contains the number of bars processed at the moment. for example:

          if (CurrentBar < 10) return; // prevent code below this line from running until first 10 bars loaded.
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jecoyeko, Today, 12:45 AM
          0 responses
          3 views
          0 likes
          Last Post jecoyeko  
          Started by Newtrader101, Yesterday, 06:31 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_EricB  
          Started by Tyler7498, Yesterday, 07:34 PM
          0 responses
          4 views
          0 likes
          Last Post Tyler7498  
          Started by Woomera, Yesterday, 07:24 PM
          2 responses
          9 views
          0 likes
          Last Post Woomera
          by Woomera
           
          Started by Newtrader101, Yesterday, 12:31 PM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_EricB  
          Working...
          X