Crashed in Positions.Opened Null reference, only during backest.
09 Dec 2016, 12:28
Hi,
I have a problem where during backtest I get a null reference exception error when using OnPositionedOpened event:
The strange thing is during live testing the code works perfectly, just during backtest I get an null reference error:
The error is:
"Crashed in Positions.Opened with NullReferenceException: Object reference not set to an instance of an object."
It occurs when i try to open another position from within the onPosition Open event:
protected override void OnStart()
{
Positions.Opened += Positions_Opened;
Positions.Closed += PositionsClosed;
}
private void Positions_Opened(PositionOpenedEventArgs args)
{
//Code to open new positions
}
private void PositionsClosed(PositionClosedEventArgs args)
{
//code to close all positions
}
What could be the cause?
Replies
cloesd
09 Dec 2016, 14:20
RE:
cloesd said:
After some testing I'm starting to believe the Positions.Opened method doesn't work during backtest.
Positions opened during a backtest simply don't trigger the postions.Opened event, can anyone confirm?
Solved!
The probem turns out to be me using
if (position.comment.contains("something") =! true)
{
}
inside the code. Deleting this makes it work 100%.
Positons.Opened works perfectly.
@cloesd

cloesd
09 Dec 2016, 12:50
After some testing I'm starting to believe the Positions.Opened method doesn't work during backtest.
Positions opened during a backtest simply don't trigger the postions.Opened event, can anyone confirm?
@cloesd