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

Error help please

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

    Error help please

    I get the following error message sometimes at the start of the trading day. Always with the same symbols. most symbols are fine. The error occurs with symbols with very few trades the previous day.

    Error Message:
    Indicator 'aBDS': Error on calling 'OnRender' method on bar 0: 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.

    BarsRequiredToPlot = 5;
    Bars2Avg = 5;

    if (BarsRequiredToPlot < 5 || CurrentBar < Bars2Avg)
    return;

    if (CurrentBar > Bars2Avg && CurrentBar > BarsRequiredToPlot && ToTime(Time[1]) > ToTime(9, 30, 00) && ToTime(Time[0]) <= ToTime(16, 00, 00) && GetCurrentBid() > 0 && GetCurrentAsk() > 0)
    {
    // My Indicator logic
    }

    Max bars back used is 4


    What am I missing?

    #2
    Hello CKnudsen,

    Thank you for the post.

    My first question related to this error would be, are you using the OnRender override in the script?
    If so, is the syntax provided being used in OnRender? If not can you provide the syntax in OnRender?

    The error seems to be coming from OnRender, or an item that utilizes OnRender during the execution of bar 0.

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

    Comment


      #3
      I don't find OnRender in the script. Should I be using it?

      Comment


        #4
        Hello CKnudsen,

        Only if you need to, OnRender is for more complex rendering but is not required to be used in your scripts.

        The reason I had asked is that the error you are seeing is coming from OnRender, but if you are not using OnRender the error is likely coming from something else that does use OnRender like a DrawingTool for example.

        As you noted this occurs sometimes, it would likely be best to wait for the next occurrence of this and note the time and instrument used along with other chart settings or relevant details to set the script up. If you could then test that time period in the Playback connection to see if the error is generated that would be very helpful if you can recreate it. If you cannot download data for the instrument, you may try enabling recording for playback so you can try to recreate the error.

        Once you find a case where you can recreate it at least sometimes at command, what I would likely suggest is to further reduce your syntax until the problem goes away to locate what specifically causes the error in the syntax used. We could then look at that syntax to see why that may be happening.

        From what you have provided, I don't see what would be causing the error as there is nothing using OnRender in that sample. If you are using other indicators, drawing objects or anything else external to the script you might try commenting out those items while testing first.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Christopher_R, Today, 12:29 AM
        0 responses
        9 views
        0 likes
        Last Post Christopher_R  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,235 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        3 views
        0 likes
        Last Post thread
        by thread
         
        Started by jclose, Yesterday, 09:37 PM
        0 responses
        8 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,415 views
        0 likes
        Last Post Traderontheroad  
        Working...
        X