Testing and analysis
Open Positions at the End of a Forex Backtest
Published ForeXpert team日本語で読む

When a forex backtest ends with open positions, report the realized profit and loss from closed trades and the unrealized profit and loss on remaining positions separately. If you also want to know how the test would look if everything were closed at the cutoff, calculate that scenario alongside the original results.
For example, you might finish with $60 in realized gains and an $80 unrealized loss. Including the open position puts the account $20 below where it started. This guide compares three ways to report the same set of trades and shows what to log so you can apply the same cutoff to another test.
What counts as open positions at the end of a backtest?
An open position is one you entered before the test ended and still held at the cutoff. Suppose you replay a chart through the final bar on a Friday. If your exit rule has yet to trigger, the position is still open. If you closed half of it earlier, that half has realized P&L and the remaining half still has unrealized P&L.
Log any unfilled entry orders separately. An entry order can be waiting at a specified price without having acquired a position, so there is no position to value. At the cutoff, check which trades have closed, which positions still have exposure, and which entries were never filled.
Realized P&L here means gains or losses from a completed exit. Unrealized P&L estimates the gain or loss on the remaining position at a stated price and time. Adding unrealized P&L to the account balance gives a snapshot of account value that includes open exposure. As an example of this accounting convention, OANDA's account documentation defines net asset value as balance plus unrealized P&L.
Three ways to report open positions

1. Count closed trades only
Summarize the trades that actually reached an exit during the test. This gives you the results of completed trades under your original rules. If positions tend to stay open for a while, entries late in the test have less time to reach their normal exit. Keep a count of the positions still open alongside the completed-trade total so you can see how much of the test remained unresolved.
2. Report unrealized P&L separately
Keep the realized P&L and closed-trade count, then put the unrealized amount at the cutoff on its own line. You can see how completed trades performed and where the account stood after valuing the open exposure. We use this as the starting point for manual reviews because the record preserves both numbers and the open trade can still be followed in a separate replay.
3. Simulate a closing trade
Assume the remaining positions are closed at a specified time and apply the modeled fills and any extra costs. This can answer either of two questions. If closing all positions at a fixed time is part of the strategy, the cutoff is a regular exit condition. If you are only testing what closing at the end of the dataset would have changed, label those exits as simulated end-of-test closes in the report.
Tools can treat these trades differently. For example, the Backtesting.py documentation describes a setting that closes active trades on the last bar and counts them in the statistics. When comparing reports, check what each report counts as a closed trade and whether it includes simulated end-of-test exits.
Worked example with the same trades
These figures are made up for illustration. The account starts with $1,000 and has no deposits or withdrawals during the test. Four closed trades have produced a combined realized gain of $60. One long EUR/USD position remains. The entry price was $1.1000 per euro, the position is 10,000 euros, and the bid at the cutoff is $1.0920. Assume zero commission, financing and slippage for this example.
The estimated P&L on the long is ($1.0920 − $1.1000) × 10,000 = −$80. No currency conversion is needed because the quote currency and the account currency are both US dollars. To check the price difference and cash amount with the stop loss and pip calculator, select EUR/USD and a USD account and enter the valuation price as the stop price for the calculation.
| Reporting method | Closed trades counted | P&L and amount at the cutoff |
|---|---|---|
| Closed trades only | 4 | +$60 realized, $1,060 balance |
| Unrealized P&L shown separately | 4 | +$60 realized, −$80 unrealized, $980 account value |
| Simulated close at the same price | 5 | −$20 including the simulated close, $980 ending balance |
The account value and the balance after the simulated exit happen to match because the same bid is used for both and the example assumes no additional exit costs. A commission charged only on the simulated exit would reduce that scenario's ending balance. Counting the simulated exit also changes the set of trades used for statistics based on completed trades, even when the amount at the cutoff matches.
In this valuation model, the bid is the selling price used for a long position, and the ask is the buying price used to cover a short. OANDA's account statement documentation gives an example of this convention. If your historical feed only contains midpoints, record how you estimated the difference between bid and ask. The forex backtesting costs guide walks through which costs may already be reflected in the price.
How to document the cutoff in a manual test
- Write down the cutoff before replaying the chart. Include the date, time zone, and the last bar you will process. This matters when two sources label candles differently or a session crosses midnight.
- Follow your normal rules through the final included bar. If a position closes under the rules on that bar, record it as a regular exit. Value any remaining size at the stated cutoff.
- Save a snapshot. Record realized P&L, the number of closed trades, the remaining positions and quantities, the valuation prices, and unrealized P&L. Note any costs already reflected in the account balance so they are counted once.
- Keep the original snapshot alongside any simulated exit. Record the time, price and extra fees of each simulated closing trade. Apply the same convention to every run you intend to compare.
In ForeXpert, you can step through historical charts one bar at a time and use the history screen to review completed trades. Keep the end-of-test valuation assumptions in your notes so you can reproduce the comparison later.

When the two totals diverge sharply, check how many entries came late in the test, how long they had been open, and whether one position accounts for most of the gap. Set the end time before seeing the results and use the same cutoff convention when repeating the test on another period. If you change the strategy or the reporting assumptions between runs, our guide to keeping a backtest rule change log explains how to document the differences. Backtest results do not guarantee future performance, and live trading can result in losses.
FAQ
Can I use the final candle's close as the exit price?
You can use it as a stated assumption for a simulated exit. Check whether that close represents the bid, the ask, or a midpoint, and document any adjustments and costs. If a candle close is the only price you have, label the result as an estimate based on that price.
Can I extend the test until every position closes?
You can follow the remaining positions in a separate replay. Save the original snapshot first so that the fixed-period report stays comparable. If the extension will become part of your testing procedure, define how long it can run and whether new entries are permitted during that extra time.
What should I write if every position is already closed?
Record zero open positions and zero unrealized P&L. An explicit zero makes it easy to tell later that you checked for open exposure.
Summary
Before replaying the chart, choose the cutoff and the price convention you will use to value anything still open. At the cutoff, report the closed-trade results and unrealized P&L side by side, with the number of open positions. If you need to know what an exit would have changed, keep a separate simulated-close result with its assumptions.


