Trailing stop path backtest · Calculation guide

Replay a trailing stop against observed trade prices.

Calculation guide

Start at the first observation. Update the running high for longs or low for shorts. A crossing fills at the observed trade price, including any gap. No intraperiod prices assumed.

Long trigger = running high × (1 − trail). Short trigger = running low × (1 + trail).

Inputs

Trailing distance

Example entry 5 %. Allowed range 0 to 100.

Order side

Select one of the listed cases (Buy / Sell).

Price per unit

Example entry 100 (in the selected currency). Minimum 1e-08.

Worked example

InputValue
Trailing distance5%
Order sideBuy

Observed trade prices in time order

Price per unit
100
110
103
98
ResultValue
Last trigger level104.5
Simulated exit price103
Exit observation number3

How each input affects this example

Each row starts from the worked example and changes one input.

InputOriginal inputNew inputAffected resultOriginal resultNew result
Trailing distance5%6%Last trigger level104.5103.4
Order sideBuySellLast trigger level104.5105
Price per unit (row 2)110121Last trigger level104.5114.95
Trailing stop path backtest →

Sources