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

Bar out of range

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

    Bar out of range

    As a test and to learn, I am trying to create a Custom Series, assign values to it, and then Print() those values back out from inside of OnRender(). I am getting the error:
    Code:
    Time	Category	Message
    9/10/2018 5:40:16 PM	Default	Indicator 'Sample custom series': Error on calling 'OnRender' method on bar 342: 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.
    Any help would be appreciated.
    Attached Files

    #2
    Hello swooke,

    Thanks for your post.

    In your code you are using a barsAgro reference in OnRender which would throw the error you are receiving.

    Code:
    for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
    {
    	Print(xlkClose[idx]);	// This is a barsAgo reference and not a reference to an absolute index.
    }
    In OnRender, it would be recommended to use absolute bar indexes (similar to CurrentBar) than relative barsAgo references like we use in OnBarUpdate().

    From the OnRender documentation:
    5. Unlike market data events and strategy order related events, there is NO guarantee that the barsAgo indexer used for Series<T> objects are in sync with the current bars in progress. As a result, you should favor using an absolute index method to look up values (e.g., <series>.GetValueAt(), Bars.GetOpen(), etc)
    OnRender - https://ninjatrader.com/support/help.../?onrender.htm

    Values from absolute indexes can be retrieved from Series<t> objects by using the GetValueAt method. To observe the differences you may see in OnBarUpdate that Close.GetValueAt(CurrentBar) would be the same as Close[0];

    GetValueAt - https://ninjatrader.com/support/help...getvalueat.htm

    I have included a link to an Ichimokou Cloud indicator I wrote that processes 2 custom Series<doubles> to draw a region. You can observe how this indicator uses absolute references in place of barsAgo index.

    Ichimokou Cloud - https://ninjatrader.com/support/foru...tid=-1&lpage=1

    I've also provided a link to our Using SharpDX for custom rendering page of the help guide for important tips and best practices while using SharpDX.

    Using SharpDX for custom rendering - https://ninjatrader.com/support/help..._rendering.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by swestendorf, Today, 11:14 AM
    2 responses
    5 views
    0 likes
    Last Post NinjaTrader_Kimberly  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    4 responses
    13 views
    0 likes
    Last Post xiinteractive  
    Started by Mupulen, Today, 11:26 AM
    0 responses
    2 views
    0 likes
    Last Post Mupulen
    by Mupulen
     
    Started by Sparkyboy, Today, 10:57 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by TheMarlin801, 10-13-2020, 01:40 AM
    21 responses
    3,917 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Working...
    X