- ago
Sometimes my strategy will still have open positions when the backtest is finished. Is there a way to "delete" these open positions (and the stop orders in place for them), as if they never existed in the first place? I don't want these to count in my backtest results (since these trades could not complete within the backtest window). In other words, I want there to be only trades that completed on the chart (and BT results) when the BT completed.

This is motivated by the pending stop orders that these positions have in place when the backtest finishes. They confuse me and I would like them gone :)
0
331
Solved
2 Replies

Reply

Bookmark

Sort
- ago
#1
You cannot hide existing positions as if they never existed but you can close them out at the last bar in your strategy.
0
Cone8
 ( 24.57% )
- ago
#2
QUOTE:
This is motivated by the pending stop orders that these positions have in place when the backtest finishes. They confuse me and I would like them gone :)
You can remove this motivation by removing all the signals like this -

Caution! You will not get Signals for ANY new trades if you add this.
CODE:
public override void BacktestComplete() {          Backtester.Orders.Clear(); }


Or if you want to just remove the Stop orders -
CODE:
public override void BacktestComplete() {          for (int n = Backtester.Orders.Count - 1; n >= 0; n--)          {             Transaction t = Backtester.Orders[n];             if (t.OrderType == OrderType.Stop)                Backtester.Orders.RemoveAt(n);          } }
1
Best Answer

Reply

Bookmark

Sort