• 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

  • johnchouston@gmail.com
    started a topic Volume of barsAgo clarification

    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.

  • NinjaTrader_PaulH
    replied
    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.

    Leave a comment:


  • johnchouston@gmail.com
    replied
    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.

    Leave a comment:


  • johnchouston@gmail.com
    replied
    Thank you Paul. Your feedback provides the answer I was looking for. Much appreciated.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    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

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by xinepev, Today, 12:33 AM
0 responses
3 views
0 likes
Last Post xinepev
by xinepev
 
Started by sun0781, Yesterday, 05:02 PM
0 responses
7 views
0 likes
Last Post sun0781
by sun0781
 
Started by ronhb107, 09-12-2019, 10:09 AM
4 responses
43 views
0 likes
Last Post Mr.Trader  
Started by rwilliam, Yesterday, 03:55 PM
0 responses
4 views
0 likes
Last Post rwilliam  
Started by asmmbillah, Yesterday, 03:42 PM
2 responses
9 views
0 likes
Last Post asmmbillah  
Working...
X