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:
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.
#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.
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.
#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.