This one is blowing my mind. I've created a data type using a class I named Event. I use it to mark an occurrence, and I want to track the bar at which it occurred and a state that indicates true or false. I'm using 1 or 0 so I can plot it on a separate pane when it occurs.
My intention is to set priceAboveExtUpperHotZone[0].state = 0, and to eventually assign a bar value (priceAboveExtUpperHotZone[0].bar) at which an Event occurs. I am using an array so I can compare .state's 0-index with the 1-index so I know when it changes.
Here's the relevant code:
namespace NinjaTrader.NinjaScript.Strategies { public class HotZone2HotZone_Panel : Strategy { private Event[] priceAboveExtUpperHotZone = new Event[2]; private Event[] priceBelowExtUpperHotZone = new Event[2]; protected override void OnBarUpdate() { if (CurrentBar < 20) return; Print(182); Print("Length of array: " + priceAboveExtUpperHotZone.Length); priceAboveExtUpperHotZone[0].state = 0; Print(185); } private class Event { public int state = 0; public int bar = 0; } } }
Length of array: 2
Strategy 'HotZone2HotZone_Panel': Error on calling 'OnBarUpdate' method on bar 20: Object reference not set to an instance of an object.
I am yet to figure this out... It compiles just fine. When I go to assign a value to the array's field state, it seems to get angry. Does anyone see anything that is simply a no-no for what I'm doing above?
Please let me know if you need any additional information. Thank you for your help in advance!!
Nathan.
Comment