Papers
Topics
Authors
Recent
Search
2000 character limit reached

Formal Candle-Based Backtesting Models

Updated 25 February 2026
  • Formal candle-based backtesting models are rigorous frameworks that convert continuous price evolution into discrete 4-tuple candlestick data for evaluating trading strategies.
  • They incorporate deterministic order-signal mapping, precise execution semantics, and systematic ambiguity resolution to model trade entries and exits.
  • The approach reduces the infinite intra-period price space to a finite set of model candles, enabling robust, reproducible verification of trading systems.

Formal candle-based backtesting models constitute a rigorous framework for evaluating trading systems using only discretely sampled candlestick data. These models specify not only the mathematical structure of candle data and its relation to the underlying continuous-time price evolution but also algorithmic strategies for ambiguity resolution, correctness proofs, and finite, constructive verification procedures. The paradigm enables robust, reproducible comparisons of trading strategy performance on historical data streams by making order execution, position sizing, and outcomes mathematically explicit and formally verifiable.

1. Mathematical Definition of Candle Data and Order-Signal Mapping

A candle, or bar, for a time interval [a,b][a,b] is defined as the 4-tuple C=(open,close,high,low)(R+)4C = (\mathrm{open},\mathrm{close},\mathrm{high},\mathrm{low}) \in (\mathbb{R}^+)^4 such that

lowmin{open,close}max{open,close}high\mathrm{low} \leq \min\{\mathrm{open}, \mathrm{close}\} \leq \max\{\mathrm{open}, \mathrm{close}\} \leq \mathrm{high}

(Löw et al., 2015, Maier-Paape et al., 2014). Every continuous intra-period price function fC([a,b],R+)f \in C([a,b], \mathbb{R}^+) induces a candle

C(f)=(f(a),f(b),maxt[a,b]f(t),mint[a,b]f(t))C(f) = (f(a), f(b), \max_{t \in [a,b]} f(t), \min_{t \in [a,b]} f(t))

This formalism posits continuity of intra-period price paths and absence of jumps, an assumption adopted for the unambiguous generation of candles from price trajectories.

Order signals are generated from past information sets ItI_t by deterministic or indicator-driven functions:

  • Entry-signal: Et=E(It1)E_t = E(I_{t-1}), representing market, limit, stop, or composite orders.
  • Exit-signal: Xt=X(It1)X_t = X(I_{t-1}), encoding market exits, stop-loss, or take-profit conditions.

The backtest result for a path ff is a tuple R(f)=(entryf,exitf)(R+{1})2R(f) = (\text{entry}_f, \text{exit}_f) \in (\mathbb{R}^+ \cup \{ -1 \})^2 representing realized execution prices or indicating no trade, and the full candle-result pair is CR(f)=(C(f),R(f))CR(f) = (C(f), R(f)) (Löw et al., 2015).

2. Intra-Period Price Models and Execution Semantics

Within the resolution interval, the intra-period price is modeled as a continuous function f:[a,b]R+f: [a, b] \to \mathbb{R}^+, precluding intra-period gaps, with liquidity being perfect (i.e., orders are always filled when touched, with no partial or missed executions) (Maier-Paape et al., 2014). The execution semantics for standard order types are as follows:

  • Market order: executed at open price OtO_t of candle tt.
  • Limit buy at \ell^*: filled if LtHtL_t \leq \ell^* \leq H_t, at price \ell^*.
  • Stop buy at bb^*: activated if LtbHtL_t \leq b^* \leq H_t, with fill at bb^*.
  • Stop-limit buy (b,)(b^*, \ell^*): order activates at first Pt(u)=bP_t(u) = b^*, then fills limit at first Pt(u)=P_t(u) = \ell^*.

Positions, P&L, and position sizing are handled as follows:

Π=Q(pexitpentry),Q=RCcurrentpentrys\Pi = Q \cdot (p_{\rm exit} - p_{\rm entry}), \quad Q = \frac{R\,C_{\rm current}}{p_{\rm entry} - s^*}

where QQ is the size determined by risk RR, current equity CcurrentC_{\rm current}, and stop-loss ss^* (Maier-Paape et al., 2014).

3. Model Candles, IPMS, and the Reduction to Finite Verification

To rigorously verify backtest engines, the infinite space of possible intra-period price paths is discretized via model candles and Intra-Period Model Price Series (IPMS) constructions (Löw et al., 2015):

  • Order levels: Given mm user-defined price levels L1<<LmL_1 < \cdots < L_m, construct an extended grid {l0,...,l2m}\{l_0, ..., l_{2m}\} by inserting intermediate points between order levels.
  • Model candles: All 4-tuples (o,c,h,l)(o, c, h, l) where each component is a grid point and the tuple respects candle ordering.
  • IPMS: Finite sequences s=(li1,...,lik)s = (l_{i_1}, ..., l_{i_k}) with adjacent indices differing by ±1\pm1, interpreted as piecewise-linear interpolations.

The main correctness theorem (Theorem 3.8 in (Löw et al., 2015)) asserts that if a backtest engine EE is stable under strictly increasing bijections T:R+R+T: \mathbb{R}^+ \to \mathbb{R}^+ (i.e., transformation of price scale), then if EE yields correct results on all model candles, EE is correct for all continuous intra-period price functions and underlying candles for a given order setup. The proof leverages the transform-invariant reduction to a finite test set.

4. Ambiguities and Systematic Resolution Strategies

Ambiguous situations, termed SNUs (Situations Not Uniquely decidable), arise due to the loss of intra-candle sequencing information:

  • E.g., Limit buy and target violated in same candle: was the target reached after fill or before order activation?
  • Situations where stop-loss and target are both touched within the bar.

Resolution strategies, selectable per backtest execution, include (Maier-Paape et al., 2014):

  • Worst-case (wc): Assign the least favorable execution or sequence.
  • Best-case (bc): Assign the most favorable outcome.
  • Ignore (ig): Discard the ambiguous trade.
  • Exact (ex): Consult tick-level data for unique disambiguation (when available).

Resolution is codified:

1
2
3
4
5
6
7
8
9
10
11
function resolve_SNU(situation, mode):
    if mode == "ex":
        load_tick_data()
        return determine_exactly()
    if mode == "ig":
        return SKIP_TRADE
    outcomes = enumerate_possible_fill_sequences(situation)
    if mode == "wc":
        return worst_outcome(outcomes)
    else:  # bc
        return best_outcome(outcomes)
This parametrization enables both conservative and aggressive backtest statistics.

5. Algorithmic Implementation and Complexity Considerations

A formal algorithmic implementation iteratively processes candles, evaluating signals, resolving ambiguities, and updating capital per trade (Maier-Paape et al., 2014). For engines seeking proof of correctness, the process is as follows (Löw et al., 2015):

  • Initialize a mapping from candle-result pairs to IPMS.
  • For each IPMS sequence of increasing length, simulate the reference engine and store novel CR pairs.
  • Stopping criterion: When Mn=Mn+1\mathcal{M}_n = \mathcal{M}_{n+1}, all additional sequences yield only previously observed candle-results.

This algorithm reduces an infinite verification problem to a finite suite, with worst-case complexity O((2m)4)O((2m)^4) for combinatorial model candles, but practical runtime is reduced by equivalence pruning (Remark 4.11 in (Löw et al., 2015)).

6. Representative Examples and Edge Cases

The framework captures and systematically resolves challenging cases:

  • Limit Buy + Stop-Loss + Target: When both exit levels are touched in the same candle, the realized outcome is determined by the user-selected ambiguity resolution mode.
  • Stop-Limit Entry + Target: For concurrent activation and limit fill conditions overlapping with exit criteria, possible outcomes are enumerated and the most or least favorable selected as required.
  • Market Order at Open: When stop condition lies below open, fill is immediate at open, with no ambiguity.

All such cases demonstrate the formal approach's capacity to manage the full range of ambiguous candlestick scenarios, providing explicit formulas for profit/loss and position management (Maier-Paape et al., 2014).

7. Significance, Applications, and Extensions

The formal models developed in (Löw et al., 2015) and (Maier-Paape et al., 2014) provide a theoretically closed method to validate backtest engines operating on candlestick data. By proving that correct operation on all model candles ensures correctness on all real data, they establish a finite, constructive route to engine verification under the assumptions of continuity, local decision-making, and transformation-stability.

Applications include trading platform engine validation, systematic trading system prototyping, and regulatory audits. Although current results address the one-entry, one-exit scenario per period, the underlying methodology (grid discretization, IPMS, transformation-stability, finite termination) directly suggests plausible extensions to more complex order configurations and multi-instrument setups.

Key insights include the reduction of an analytically intractable infinite path space to a demonstrably finite and algorithmically accessible problem, transforming platform validation from an empirical to a rigorously provable process (Löw et al., 2015).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Formal Candle-Based Backtesting Models.