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

Load data based on Days: WORKS | Load data based on Bars: DOES NO WORK

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

    Load data based on Days: WORKS | Load data based on Bars: DOES NO WORK

    Hi there, this one is a head-scratcher.
    I developed a Ninjascript that works exactly as I expect... sometimes. Unfortunately, there are quite a few scenarios in which it does not work. My hope is I can get a little direction based on my notes below.
    1. Scenario in which it works is on a 240-minute MNQ chart. If I RMB and select Data Series, the drop-down labeled "Data loaded based on" is Days. I have 365 days loaded. Varying numbers of days works as well.
    2. I added multiple timeframes. Currently my code lives in the 240-minute time frame. So all dalcs and decisions are made there. This seems to work as expected, because when I change the previously mentioned configuration from a 240 to a 15-minute chart, everything works as expected.
    3. Scenario in which it DOES NOT work. 240-minute EURUSD chart. In Data Series window, I leave "Data loaded based on" as Days (still 365 days loaded), and the chart does not load, and in NinjaScript Output window I get
      Indicator 'MarketStructure': Error on calling 'OnBarUpdate' method on bar -1: 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.
      I should also note, when I put in a bunch of Print's to debug, it runs through everything once, and then stops as soon as it gets into the Plots section of my code. That resides at the end of my OnBarUpdate() method. It throws the error at the line
      if (RunningHighPrice[0] > 0)
      Where RunningHighPrice is a data series of doubles, that I added in state.dataloaded section of the OnStateChange method
    4. Another scenario in which it does not work. It's the configuration described in number 1 above --> MNQ, 240-minute chart. I change "Data loaded based on " to Bars. That's it. I load 1000 bars, and it throws the same error as described in Line 3
    I am about to go on another perilous debugging quest, but if anyone's ever seen such a thing, a little help would be greatly appreciated. Thank you!

    Nathan.

    #2
    Okay, so I got it to work.

    Before my Plots section, I said:
    if (CurrentBars[2] > 20)
    PlotPlots();

    And it works!!! So it makes sense to me that it does work. However... why does it work without this line in Line 1 as noted in original post? Anyone??​

    Comment


      #3
      Originally posted by Nate G View Post
      Okay, so I got it to work.

      Before my Plots section, I said:
      if (CurrentBars[2] > 20)
      PlotPlots();


      And it works!!! So it makes sense to me that it does work. However... why does it work without this line in Line 1 as noted in original post? Anyone??​
      Hello Nate G,

      Thanks for your note.

      I am glad to hear you got it to work! We have a page about the type of error you were receiving and how to prevent it by making sure there are enough bars in the series you are accessing in the help guide here:


      You had mentioned that the error seems to be related to the following line:
      Code:
      [I]if (RunningHighPrice[0] > 0)[/I]​
      If the value for RunningHighPrice has to access data for any previous bars to calculate its assigned value, then you would need to check that at least that number of bars already exists on the chart before accessing the value for RunningHighPrice. Additionally, since it is a multi-series script, you might need to consider which BarsInProgress is calling OnBarUpdate() at the time that the error is thrown and how many bars are on the chart for that BarsInProgress at the time of the error. You could certainly consider adding information such as BarsInProgress and CurrentBar to your debugging prints if you have not already in the case that you would like to debug and understand the cause of the error further. For more tips on using prints for debugging, please see the following post:


      Please let us know if we may be of further assistance.
      Emily C.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by futtrader, 04-21-2024, 01:50 AM
      6 responses
      57 views
      0 likes
      Last Post futtrader  
      Started by sgordet, Today, 11:48 AM
      0 responses
      1 view
      0 likes
      Last Post sgordet
      by sgordet
       
      Started by Trader146, Today, 11:41 AM
      0 responses
      3 views
      0 likes
      Last Post Trader146  
      Started by jpapa, 04-23-2024, 07:22 AM
      2 responses
      17 views
      0 likes
      Last Post rene69851  
      Started by funk10101, Today, 11:35 AM
      0 responses
      1 view
      0 likes
      Last Post funk10101  
      Working...
      X