Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to access historical Bar values in my ninja strategy code 4 real time data feed

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

    How to access historical Bar values in my ninja strategy code 4 real time data feed

    hi All,
    I need some help here, where I need to access the previous day's bar values (like high . low, EMA values ) when my strategy code is being executed on real time data.
    How do I access it?

    when I use lets say for example
    Close [10] or Close[16] on hourly chart, i get below error:
    Error on calling 'OnBarUpdate' method on bar 100: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.



    #2
    Hello sjpande,

    Thanks for your post and welcome to the NinjaTrader Forums!

    This error message indicates that you are trying to access a BarsAgo value that is not valid. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

    A CurrentBar check could be used in your indicator's logic to ensure that a certain number of bars have been processed before the indicator begins calculation. A CurrentBar check would look something like this.

    Code:
    if (CurrentBar < 10)
        return;
    This would check to make sure that 10 bars have been processed before the indicator begins its calculations.

    See the help guide documentation below for more information.

    CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
    CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X