Trailing Stop Trigger
The trailing_stop trigger fires when the price drops a specified percentage from the highest price reached since the position was opened. It locks in profits during uptrends by selling when momentum reverses.
Unlike a fixed stop-loss (pos_price_change with a negative value), a trailing stop moves up as the price rises. It only looks down from the peak — never up.
TOML Syntax
[[actions.triggers]]
type = "trailing_stop"
value = "-3%" # Required: always negative (drop from peak)
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | Yes | — | Must be "trailing_stop" |
value | string | Yes | — | Percentage drop from peak in "-N%" format (always negative) |
max_count | integer | No | unlimited | Maximum times this trigger can fire per position |
trailing_stop does not support the timeframe field. It tracks the peak price across all candles since position entry.
How It Works
- When a position opens, the engine starts tracking the highest close price since entry
- On every candle, if the new close is higher than the tracked peak, the peak is updated
- The engine calculates:
drop_pct = (current_close - peak_price) / peak_price * 100 - When
drop_pct <= threshold(e.g., -3%), the trigger fires
graph TD
A["Track peak price<br/>since position entry"] --> B["New candle close"]
B --> C{"New close ><br/>peak?"}
C -->|Yes| D["Update peak"]
C -->|No| E{"Drop from peak<br/>meets threshold?"}
D --> F["Continue"]
E -->|Yes| G["Trigger fires"]
E -->|No| F
Visual Example
Imagine you enter at $100, the price rises to $110 (new peak), then drops:
| Price | Peak | Drop from Peak | -3% trigger |
|---|---|---|---|
| $100 | $100 | 0% | — |
| $105 | $105 | 0% | — |
| $110 | $110 | 0% | — |
| $108 | $110 | -1.8% | — |
| $107 | $110 | -2.7% | — |
| $106.70 | $110 | -3.0% | Fires |
The trailing stop at -3% would NOT have fired at $106.70 with a fixed stop-loss from entry ($100). The trailing mechanism locks in the gains from the $100 → $110 run.
The value Format
The value must be negative (it represents a drop):
| Value | Meaning |
|---|---|
"-2%" | Sell when price drops 2% from peak |
"-3%" | Sell when price drops 3% from peak |
"-5%" | Sell when price drops 5% from peak |
"-0.5%" | Very tight trailing stop (0.5% from peak) |
Examples
Basic Trailing Stop
[[actions]]
type = "sell"
amount = "100%"
[[actions.triggers]]
type = "trailing_stop"
value = "-4%"
Trailing Stop + DCA Strategy
Combine a trailing stop with DCA levels for a complete loss-prevention system:
[meta]
name = "Trend-Safe Trailing Stop"
description = "BB+RSI entry, DCA on dips, trailing stop locks profits"
max_open_positions = 1
# Entry: Bollinger Band + RSI filter
[[actions]]
type = "open_long"
amount = "100 USDC"
[[actions.triggers]]
indicator = "bb_lower"
operator = ">"
target = "price"
timeframe = "1h"
[[actions.triggers]]
indicator = "rsi_14"
operator = "<"
target = "40"
timeframe = "1d"
# DCA at -5%
[[actions]]
type = "buy"
amount = "100 USDC"
average_price = true
[[actions.triggers]]
type = "pos_price_change"
value = "-5%"
[[actions.triggers]]
indicator = "rsi_14"
operator = "<"
target = "35"
timeframe = "1h"
# Take profit at +3%
[[actions]]
type = "sell"
amount = "100%"
[[actions.triggers]]
type = "pos_price_change"
value = "3%"
# Trailing stop: sell when price drops 4% from peak
[[actions]]
type = "sell"
amount = "100%"
[[actions.triggers]]
type = "trailing_stop"
value = "-4%"
# Time exit: free stuck capital after 7 days
[[actions]]
type = "sell"
amount = "100%"
[[actions.triggers]]
type = "time_in_position"
value = "7d"
Tips
Choose your trailing stop percentage based on the asset's typical volatility. A -2% trailing stop on BTC during a volatile week will trigger constantly. A -5% trailing stop gives more room for normal price swings.
Trailing stops and fixed take-profits (pos_price_change) work well together. The take-profit catches quick gains, while the trailing stop captures extended runs. Whichever fires first wins.
Trailing stops can fire during flash wicks (sudden price drops that recover quickly). In highly volatile markets, consider a wider percentage to avoid premature exits.
Related Triggers
| Trigger | What It Measures |
|---|---|
| Position Price Change | Fixed % from entry price (stop-loss/take-profit) |
| Trailing Take-Profit | More flexible trailing with activation threshold + tolerance |
| Time in Position | Duration-based exit (pairs well with trailing stop) |