Skip to content

TP levels#

A HookTrader strategy can have up to 10 take-profit levels (tp1 through tp10), each with its own ordered list of actions. The same lists run from two places:

  1. When TradingView fires a tp_hit alert for that level (tp_source: webhook or auto on live keys).
  2. Autonomously by HookTrader, when the platform detects the TP price has been crossed intra-bar (tp_source: platform or auto on paper keys).

This dual mechanism means TP behaviour is identical regardless of which side detects the cross first.

Stored shape#

The webhook stores the strategy as a JSON object keyed by TP level:

{
  "tp1": [{ "type": "move_sl_be" }, { "type": "reduce_position", "percent": 30 }],
  "tp2": [{ "type": "activate_trail" }, { "type": "reduce_position", "percent": 30 }],
  "tp3": [{ "type": "close_position" }]
}

Order matters — actions within a level execute sequentially. Empty or missing levels are no-ops.

Pre-staged exchange-side TPs#

Intermediate TP levels whose actions include reduce_position or close_position are pre-staged as exchange-side TAKE_PROFIT_MARKET algos at entry. The reduction fires the moment the trigger hits, instead of waiting on the platform's tick-to-market round-trip.

  • Up to 8 intermediate algos are pre-staged per trade. Deeper levels fall back to autonomous detection.
  • The final TP (tp_max) keeps using a full-close bracket.

This is a latency optimisation, not a behavioural change — the same action list still runs once the level triggers.

Custom events#

Beyond fixed TPs, a strategy can also define custom events: named action lists that fire when a custom alert arrives with that name. Up to 10 custom events per strategy. Useful for momentum-based exits or external signal-based scale-ins.

Names must match ^[a-z][a-z0-9_]{1,49}$ (lowercase, starts with a letter, alphanumeric + underscore).

Frozen at entry#

The action list for each TP level is frozen onto the trade at entry time. If you edit the strategy mid-trade:

  • In-flight trades keep running the old action list.
  • The next entry signal picks up the new config.

This prevents an in-flight trade from suddenly behaving differently because you tweaked the strategy in the dashboard.

Recording#

Every action that places an order is recorded in the trade history with:

  • phase — e.g. tp1, tp1_reduce, tp1_add, tp2_reduce, trail, sl, emergency_close.
  • qty, exit_price (qty-weighted average fill price), realized_pnl, commission, commission_asset.
  • The underlying exchange order references for audit.

Opening and scale-in entries have no realised PnL. All close-side entries have a real value.

See SL / TP / Trailing → How brackets work for the order-level mechanics, and Examples for ready-to-paste TP recipes.