Hawk Backtester › Simulation Model

Simulation Model

This document describes the technical specifications of the simulation engine for research purposes.

This service does not execute actual financial transactions or trades. It is intended solely for researching and validating algorithms on time-series data.

The following defines the preconditions, constraints, and specifications of the simulation engine. This information is necessary for interpreting backtest results.

Historical Data Format»

The engine operates on OHLC bar units. Tick data is not supported.

Column IndexFieldUsage
0TimeTimestamp (ms)
1OpenNext-bar-open entries; fills when a bar gaps through TP/SL or an order price
2CloseMarket fills at the signal-bar close, strategy closes, unrealized PnL
3HighBuy-side TP hit check / Sell-side SL hit check / Trailing Stop updateBuy-side TP hit detection, Sell-side SL hit detection, Trailing Stop update
4LowBuy-side SL hit check / Sell-side TP hit check / Trailing Stop updateBuy-side SL hit detection, Sell-side TP hit detection, Trailing Stop update

Order Fill Model»

At step k a strategy sees candles[:k]; the last one is the current bar. Market orders fill at the current bar's close, or at the next bar's open if configured. TP/SL, limit and stop orders fill at their price level (or at the open when the bar gapped through it). Every fill pays half the spread plus slippage on the adverse side, and fees are deducted.

OperationFill PriceNotes
Market order Close ± cost / NextOpen ± cost Chosen by the fill-timing setting. cost = spread/2 + slippage (+ for buys, − for sells)
Limit / stop order OrderPrice ± cost Triggered by High/Low; if the open already crossed the price, filled at the open (better for limits, worse for stops)
TP / SL exit Level ∓ cost Filled at the level; at the open if the bar gapped through it. If both are touched in one bar, the stop is assumed first
Strategy / forced close Close ∓ cost At the current bar's close

Intra-Bar Processing Order»

Processing is executed in the following order for each bar. All operations are atomic at the bar level.

  1. Load OHLC data for the new bar
  2. Update Trailing Stop (raise SL level based on High/Low)
  3. Recalculate unrealized P&L (Close-based)
  4. Pending Order (Limit/Stop) trigger evaluation and fill
  5. TP/SL hit check and position closing
  6. Margin ratio check and ticket acceptance availability update
  7. Force-close all positions if margin ratio exceeds threshold

Position Management»

In this system, each order is managed as an independent Ticket (trade ticket). A Ticket corresponds to a deal ticket in securities/FX trading, and one Ticket is issued per order. Even when placing multiple orders in the same direction, no netting is performed — each is tracked separately as an individual Ticket with its own P&L, holding period, etc.

Order Type»

Order TypeDescription
Market Order Market order. Fills at the current bar's close, or at the next bar's open if configured
Limit Order Limit order. Fills at the limit price when reached, or at the open if the bar gapped through it (Buy: at or below the current price, Sell: at or above)
Stop Order Stop order. Fills at the stop price when crossed, or at the open if the bar gapped through it (Buy: at or above the current price, Sell: at or below)
Trailing Stop Trailing Stop. Automatically raises the SL level as price moves favorably (Buy: follows High, Sell: follows Low). The SL level is only updated in the favorable direction and maintained during reversals

Take Profit, Stop Loss, and Trailing Stop can be optionally attached to all order types.

Ticket Management»

SpecificationDescription
Per-Ticket Management Each order is created and managed as an independent Ticket. Multiple orders in the same direction are not netted — P&L, TP/SL, and holding period are tracked individually
Close Method Close individually by specifying Ticket ID. Supports TP/SL auto-close, strategy manual close, and forced close
Partial Close Supported. Partially close a ticket by specifying reduce_ratio (0.0–1.0)Supported. Partially close a Ticket by specifying reduce_ratio (0.0-1.0)
Hedging Long and Short Tickets can be held simultaneously. However, margin calculation does not net — it simply sums the margin of all Tickets (see below)

Margin & Leverage»

ItemFormula / Specification
Required Margin Σ (units × entryPrice / leverage) for all open tickets
Equity Assets + Σ unrealizedPnL
Buy: (Close − entryPrice) × units
Sell: (entryPrice − Close) × units
Margin Ratio RequiredMargin / Equity

Cost Model»

ItemSpecification
SpreadPrice units. Half is applied adversely on every fill, so a round trip costs one spread.
Fee rateFraction of notional (price × units), charged on entry and on exit.
Fixed feeFixed amount per fill, on entry and on exit.
SlippageAdverse price offset applied to every fill: market, TP/SL, limit, stop and closes.

Constraints & Assumptions»

ItemDescription
Deterministic Execution The engine contains no random number generation and returns fully reproducible results for identical inputs
Numerical Precision The WASM engine (C++) uses float32 arithmetic. Frontend Exit Analysis evaluation uses Math.fround() to match precision
Tick Data Not supported. All processing is completed at the OHLC bar level
Multi-Asset Not supported. Each simulation runs on a single asset