Trigger evaluation
Every call to tick_position reads the latest price from the configured feed, advances the trailing extreme, then evaluates three triggers in a fixed order. The first condition that hits settles the position in the same instruction.
Evaluation order
Triggers are checked in this order. The first hit wins. Set a value to 0 to disable that trigger.
- Stop loss
stop_price - Take profit
take_profit_price - Trailing
trailing_offset+trailing_extreme
Long side conditions
stop: price <= stop_price
tp: price >= take_profit_price
trail: price <= trailing_extreme - trailing_offset
where trailing_extreme = max(trailing_extreme, price)On open and on every tick, the program updates trailing_extreme = the highest price seen so far. The trailing trigger fires when the price retraces from that extreme by exactly trailing_offset.
Short side conditions
stop: price >= stop_price
tp: price <= take_profit_price
trail: price >= trailing_extreme + trailing_offset
where trailing_extreme = min(trailing_extreme, price)open_position, the program sets trailing_extreme = entry_price. If price never moves favorably, the trailing condition does not fire spuriously. The extreme only advances on actual favorable movement.Validation at open
The program rejects positions whose triggers are on the wrong side of entry. This prevents a position from auto-triggering on the next tick.
long & stop_price > 0 requires stop_price < entry_price
long & take_profit > 0 requires take_profit > entry_price
short & stop_price > 0 requires stop_price > entry_price
short & take_profit > 0 requires take_profit < entry_price
any & trailing_offset > 0 requires trailing_offset < entry_priceSettlement split
When a trigger fires, the position's collateral is split inline:
fee= collateral ×fee_bps÷ 10_000 → fee receiverkeeper_reward= collateral ×keeper_reward_bps÷ 10_000 → tick callernet_to_owner= collateral − fee − keeper_reward → position owner
Status flips to TRIGGERED, trigger_reason records which of the three fired, and settled_at is the slot clock.
Edge cases
- Stale feed If
last_updatedis older than 120 seconds, ticks revert withPriceFeedStale. - Zero price Ticks revert with
PriceFeedZero. - Multiple triggers met same tick Stop wins over TP, TP wins over trailing.
- No trigger met The instruction succeeds, only
tick_countand possiblytrailing_extremechange. - Trigger update mid-flight
update_triggersresetstrailing_extremeto entry if the offset changes.