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.
- 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.
- 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.
- 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 - 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
Nathan.
Comment