How the Simulation Works
The candle-by-candle execution loop, how positions open and close, and how the equity curve is built.
How the Simulation Works
A backtest replays your strategy against historical data. But what actually happens inside the engine? This article walks through the candle-by-candle process that turns your entry and exit rules into an equity curve and a set of performance metrics.
The engine processes one candle at a time, from the first candle in your date range to the last. At each candle it reads the price data, decides whether to enter or exit based on your rules and the current position state, then records the portfolio value. The engine never looks ahead -- it only knows what has happened up to the current candle.
The Candle-by-Candle Loop
Every backtest follows the same loop. The engine runs this sequence once per candle, from the start of your date range to the end:
After the last candle, the engine has a complete equity curve and trade log. These are passed to the metrics calculator, which produces the full set of performance metrics you see in your results.
One loop, one candle interval
Notice that the loop steps through one candle interval. A strategy where every condition uses the same timeframe is the simple case -- the engine reads that timeframe's candle at step 1 and checks every condition against it. That is what most backtests are.
A multi-timeframe strategy runs the exact same loop. The engine still steps one candle at a time at the fastest timeframe any condition uses, and at each step a condition that references a higher timeframe is checked against that higher timeframe's value, rebuilt from only the candles that have closed so far. Single-timeframe is just the special case where every condition happens to share the loop's interval -- nothing about the candle-by-candle mechanism changes.
The Equity Curve
The equity curve is a line that tracks your portfolio value over time. It is the most fundamental output of a backtest -- every other metric is derived from it.
Simula normalizes the starting capital to 1.0, so the equity curve shows relative growth rather than a dollar amount. A final value of 1.15 means the strategy returned 15%. A value of 0.90 means it lost 10%.
The shaded regions above represent candles where a position was open. Between positions, the equity curve stays level because the strategy is not exposed to price changes. The peak is the highest point the equity curve reaches, and the trough is the lowest point after a peak. Max drawdown is the largest peak-to-trough decline across the entire curve.
Leverage and the equity curve
When you run a backtest with multiple leverage levels, the engine tracks a separate equity curve for each one. The loop runs once, but at step 4 it updates multiple equity values -- one per leverage factor. Each leverage level amplifies both gains and losses proportionally.
Position Lifecycle
A position is the period between an entry and an exit. The engine tracks one position at a time -- it does not stack multiple positions on the same asset.
Opening a position
When entry conditions pass and the strategy has no open position, the engine opens a trade at the next candle's open price by default -- you can switch a backtest to fill at the triggering candle's close instead (see Execution timing below). The full spread is applied on the round trip -- you always buy at the ask (the higher price) and sell at the bid (the lower price). For a long trade, this means the entry price is the ask and the exit price is the bid. For a short trade, the directions are reversed. Slippage further worsens the execution price by a percentage on each side. Commission is calculated on the trade value at each end.
While a position is open
On each candle where a position is open, the engine calculates the unrealized profit or loss. For a long position, this is based on how far the close price has moved above the entry price. For a short position, it is how far the close has moved below the entry price. This unrealized value is what gets recorded in the equity curve at step 4.
Closing a position
A position closes when one of these happens:
When a position closes, the engine calculates the realized profit or loss (including spread, slippage, and commission costs), updates the portfolio value, and logs the completed trade with its entry time, exit time, and return. The cumulative impact of these costs is shown in the Transaction Cost Analysis card in your results.
Once the position is closed, the strategy is free to enter again. By default a new trade can open as early as the next candle if the entry conditions are still true; you can instead make it wait for the entry conditions to turn false and then true again. See Re-entering After an Exit.
What the Engine Does Not Do
Understanding the engine's limitations helps you interpret results accurately:
One Day at a Time: Intraday Stock Backtests
Stock markets close. A US regular session runs from 9:30 AM to 4:00 PM Eastern, and between the closing bell and the next morning's open there is a gap where no trading happens on your chart but a great deal can happen to the price. Earnings are released after the close. News breaks overnight. A stock can open the next morning several percent away from where it closed, and you had no opportunity to react.
Because of that gap, most intraday stock strategies are traded flat: the trader closes every position before the bell and starts the next morning with nothing open. So Simula backtests intraday stock strategies one day at a time by default. Each trading day is independent. This applies to stocks on the 1-minute through 4-hour timeframes only -- there is nothing to isolate on a daily chart, and forex and crypto trade continuously with no daily close.
What happens at the close
Three rules, all of which apply only while the setting is on:
Where the engine thinks the day ends
The engine uses the last candle it actually has for that day, not a fixed 4:00 PM clock time. That distinction matters on the two or three half days a year -- the day after Thanksgiving, and Christmas Eve or July 3rd when they fall on a weekday -- when US markets close early, at 1:00 PM. On those days the data simply contains fewer candles, and the engine closes your position on the last one it has. You do not need to know the exchange holiday calendar, and neither does the engine.
The same rule applies at the very end of your backtest. If your date range stops partway through a session, that final candle is treated as a day end, so a run never finishes with a position left hanging open.
Holding positions overnight
Set Day Isolation to Hold overnight in the configuration bar above the strategy builder. Positions then carry across the gap until one of your exit conditions, a stop-loss, or a take-profit closes them, exactly as they do on a forex or crypto backtest. All three rules above switch off together, including the skipped entry on the final candle -- if you have chosen to hold overnight, an entry late in the day is a perfectly ordinary trade.
Be honest with yourself about what that result then represents. Holding overnight means holding through the gap, and a backtest cannot show you the moment you would have wanted to get out and could not. It also means your stop-loss did not protect you overnight: if the price gapped straight through your stop level while the market was closed, the simulation fills you at that stop level, which is a fill you would not have received in practice.
From Loop to Results
After the loop finishes, the engine passes two outputs to the metrics calculator: the equity curve (portfolio value at every candle) and the trade log (every entry and exit with prices, times, and returns). From these two datasets, Simula calculates every metric you see in your results -- returns, drawdown, Sharpe ratio, win rate, and everything else.
Where to Go Next
Limitations & Pitfalls -- biases beyond the engine itself, like survivorship bias, overfitting, and regime change.
Entry & Exit Conditions -- how crossovers, thresholds, and logic operators define the rules the engine evaluates at step 2.
Multi-Timeframe Analysis -- how the same loop checks conditions that reference a higher timeframe than the chart.
Spreads, Commissions & Slippage -- how transaction costs are applied during position entry and exit.
Metrics -- deep dives into every metric calculated from the equity curve and trade log.