Execution Engine

How the backtest engine evaluates strategies — entry logic, the fixed risk model, position management, and determinism rules.

Overview

The backtest engine evaluates your strategy against historical OHLCV data candle by candle, in chronological order. For each candle, it runs the full evaluation pipeline: compute inputs, evaluate conditions, sum scores, check the decision rule, and open a trade if the rule is met.

The engine is deterministic. Given the same strategy, asset pair, and date range, it always produces the same result.

Evaluation Pipeline

For each candle, the engine runs in this order:

1
Compute inputsAll input expressions are evaluated using current and past candle data. Indicators are computed with the full lookback required.
2
Evaluate conditionsEach condition is evaluated as a boolean using the computed inputs and comparison operators.
3
Sum scoreThe scores of all true conditions are summed to produce the candle's total score.
4
Check decisionThe entry expression is evaluated. If it resolves to true, a new trade is opened.
5
Update open positionsAll currently open trades are checked against the high and low of the candle to see if SL or TP was hit.

Entry Execution

Entries are executed at the close of the candle where the decision rule evaluates to true. There is no look-ahead — the signal is generated using data up to and including the current close, and the entry price is that close.

Entry on close means the strategy cannot react faster than one candle interval. On a 1H strategy, the minimum response time to a market event is one hour.

#Risk Model (R-Units)

Every trade uses a fixed risk model:

  • Stop-loss1% from entry price.
  • Take-profit3% from entry price (1:3 risk-reward ratio).
  • Win (in R)+3.0R per winning trade.
  • Loss (in R)-1.0R per losing trade.

Results are measured in R, not in currency amounts. This makes strategy results comparable regardless of account size, asset price, or position sizing method.

Why R-units?

R-units remove the illusion of dollar profits. A strategy withpnlR: +50 returned 50 units of risk across the backtest period. Whether each unit was $10 or $1,000 is a position sizing decision made separately. This is the correct way to evaluate statistical edge.

#Multiple Positions

The engine supports multiple open positions simultaneously. Every candle where the decision rule evaluates to true opens a new, independent trade — even if other trades are already open.

There is no position sizing or capital allocation simulation. Each trade is fully independent. If 5 trades are open simultaneously and all hit SL, the result is -5R. The engine does not simulate compounding or account depletion.

This is intentional: the goal is to evaluate the statistical edge of the strategy signal itself, not the portfolio behavior under any particular position sizing scheme.

Same-Candle Ambiguity

When both the stop-loss and take-profit levels are reached within the same candle (i.e., the candle's low is below SL and its high is above TP), the engine conservatively assumes the stop-loss triggered first.

The count of these ambiguous trades is reported in the bothHitfield of the results. A high bothHit count relative to total trades may indicate the strategy is being used on a timeframe that is too coarse for the intended entry precision.

Warmup Period

Indicators require a minimum number of candles to compute (the lookback period). For example, ema(close, 21) requires at least 21 candles of history before it can produce a value.

The engine automatically handles this by consuming the first N candles as warmup before evaluation begins. These candles are not traded. The warmup period is derived automatically from the indicators used in the strategy.

Strategy Diagnostics

Beyond performance metrics, the engine tracks two diagnostic datasets that are critical for strategy quality analysis:

conditionsDistributionPct

For each condition in the strategy, the fraction of all evaluated candles where it was true. A condition that is true on 95% of candles adds almost no discriminating power and may be wasting score weight.

scoreDistributionPct

For each possible score value, the fraction of candles that reached that score. This shows how often your strategy is "close to triggering" vs. fully aligned, and helps tune your entry threshold.

💡
Use these diagnostics to identify overfitting risk. If your entry threshold is barely above the most common score, you may be triggering too frequently on marginal signals.

#Limitations

  • No slippage simulation. Entries and exits are at exact close/SL/TP prices.
  • No trading fees or commissions are deducted from results.
  • No capital compounding. Each trade is sized independently at 1R.
  • Only long (buy) positions are supported in the current version. Short selling is not yet available.
  • Data is limited to supported asset pairs and their available historical range.
  • The engine processes candles sequentially — there is no intra-candle execution simulation.
These limitations are by design. The engine is built to evaluate statistical edge, not to simulate live trading. Live execution infrastructure (including slippage and fees) is part of the upcoming Live Execution API.