the code below, when I set "entries per direction" to more than 1 (say 5) during a backtest results in an error "Error on running backtest: Object reference not set to an instance of an object." and some of the positions close by a wrong exit: say, "IQ Entry" may be closed by a "PQ exit".
------------------ begin -----------------
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(SMA(Fast), SMA(Slow), 1))
{
EnterLong(DefaultQuantity, "IQ");
}
// Condition set 2
if (CrossBelow(SMA(Fast), SMA(Slow), 1))
{
ExitLong("IQ Exit", "IQ");
}
// Condition set 3
if (DonchianChannel(Channel).Upper[0] > DonchianChannel(Channel).Upper[1])
{
EnterLong(DefaultQuantity, "PQ");
}
// Condition set 4
if (Low[0] < Low[1])
{
ExitLong("PQ Exit", "PQ");
}
}
------------------ end -----------------
What is the problem and how to solve it?
Thank you.
Comment