Trailing stop#
HookTrader's trail has three independent pieces:
- Activation — the
activate_trailaction arms the trail. Without this the trail is dormant. - Updates —
trailevents from TradingView carry a newtrail_slprice. - Enforcement — exchange-side STOP_MARKET + autonomous price monitor safety net.
Activation#
The trail is off by default. Add an activate_trail action at the TP level where you want it to arm (typically TP2):
Before activation:
trailevents are accepted and update the trail level.- HookTrader does not act on a trail cross yet.
After activation:
trailevents continue to ratchet the trail forward.- HookTrader checks the live price against the trail level on every price tick and emergency-closes if crossed.
This split lets you "pre-warm" the trail (your indicator can keep sending trail updates from the start) without committing to it as the actual stop until the trade has proven itself.
Ratchet rule#
Every trail event is checked against the current trail_sl:
| Direction | Update accepted if … |
|---|---|
long |
new sl > current trail_sl (move up) |
short |
new sl < current trail_sl (move down) |
Updates that would move the SL backward are silently rejected. This is the ratchet — trails only tighten.
On a successful update HookTrader:
- Updates the trail level (and arms the trail if not already active).
- Calls
exchange.move_sl()to physically modify the resting STOP_MARKET algo to the new trigger.
The actual trail level computation is not HookTrader's job — your TradingView indicator emits the trail price via the trail event payload. If you want a different trailing logic (e.g. ATR-based, Chandelier exit), implement it in Pine. HookTrader is agnostic.
Enforcement — two layers#
Once the trail is armed, it is enforced by two independent layers:
- Exchange-side stop order — sits on Binance and fires independently of HookTrader. This is the primary safety net.
- HookTrader price monitoring — on every price tick, HookTrader checks the live price against the trail level. If the trail is crossed and the exchange order somehow hasn't fired (rare), HookTrader closes the position automatically.
This redundancy means a trail can't go "unprotected" between updates.
SL safety guard#
When a trail (or any move_sl_* action) would push the SL through the current mark price — e.g. a long where the new trail is below the entry but mark has already dropped below the new trail — HookTrader does not blindly submit it. Submitting would cause an instant stop-out.
The exchange normalises this as MoveSLStatus:
| Status | Meaning |
|---|---|
placed |
New SL placed successfully. |
skipped_in_the_money |
New would trigger immediately. Prior SL restored; position still protected. |
breached_emergency_closed |
Both new and prior would trigger. Position emergency-closed. |
position_already_closed |
Nothing to move — position closed mid-call. |
failed |
Generic failure (logged at error). |
skipped_in_the_money is the safe path: the trade keeps running with its previous SL. Subsequent actions in the same TP level still execute.
What you see in the UI#
- Live Trades shows the current trail level once the trail has been set, regardless of whether it's active yet.
- The trail-active indicator turns on once the trail is armed.
- A successful trail update is recorded as an event, not a leg (no order fill produced).
- A trail exit (the position is closed because price crossed the trail) writes a leg with phase
trail.