PDA

View Full Version : Bars.GetSessionBar Comparison results in Object Reference error


bani789
06-12-2008, 01:44 PM
Hello, I'm trying to compare 2 values using Bars.GetSessionBar in an if statement under OnBarUpdate(), example being as follows:

protected override void OnBarUpdate()


{if (Bars.GetSessionBar(1).Close < Bars.GetSessionBar(1).Open){EnterLong();}
}


When backtesting that section of code I get the following error in the log: "Error on calling 'OnBarUpdate' method for strategy 'Strategy2': Object reference not set to an instance of an object."

The entries however still seem to be taken regardless of the error, so I'm not sure whether it's causing any real problems. Any help would be appreciated.

NinjaTrader_Dierk
06-12-2008, 01:46 PM
http://www.ninjatrader-support.com/HelpGuideV6/GetSessionBar.html

You must check for a null reference since null is returned if there is not sufficient intraday data to build a session bar.

bani789
06-12-2008, 01:54 PM
What a blunder on my part, thanks a lot.