OPEN-SOURCE SCRIPT
ที่อัปเดต:

Hyperliquid-Ready Webhook Strategy Template

1 109
Most webhook templates get you 80% of the way there — then your bot double-fills an order at 3am and you learn about the missing 20%. This template IS the missing 20%.

What this is

An open-source strategy template whose real value is the alert payload: a production-grade JSON webhook message with the fields most templates skip. The included strategy (EMA 21/55 cross + RSI filter, ATR-based SL/TP) is a simple demo — swap in your own logic. It happens to test reasonably on BTC 4H, but the point of this script is the plumbing, not the entry logic. Bring your own edge.

The payload — and why each field exists

→ id — unique per event (ticker + timeframe + action + bar time). Your backend treats this as an idempotency key: TradingView sometimes retries the same alert when your server responds slowly. Dedupe by id (one Redis SET NX) and you'll never double-fill. The action is part of the id so an entry and its exit on the same bar can never collide — a bug I caught in live testing of this exact script.

→ ts — fire-time timestamp via {{timenow}}. Reject alerts older than N seconds so a delayed or replayed webhook can't trade a stale price.

→ secret — replace with a long random token and verify it server-side (or better, HMAC the body). Anyone who finds your webhook URL can POST to it. This field is your lock.

→ reduce_only — true on exits, so a close can never accidentally flip you into a new position if state desyncs.

Also included: leverage and qty fields for your backend (cap leverage server-side too — never trust the client alone), and an on-chart payload preview table so you can eyeball your exact JSON before wiring real money.

Setup (2 minutes)

Add to chart (crypto perps: BTC/ETH/SOL, 15m–4H)
Create alert → condition: this strategy → "Order fills events" → message box: {{strategy.order.alert_message}}
Point the alert's webhook URL at your execution backend or bridge

Works with any TradingView→exchange webhook bridge. Important: alerts snapshot the script when created — if you edit the code, delete and re-create your alerts.

Who I am

I build custom TradingView→Hyperliquid execution pipelines (Pine Script v6, non-custodial agent wallets). If you want this wired to live execution or adapted to your strategy, links are in my signature.
Release Note
v1.1 — Pine v6 · executor-contract upgrade

- NEW: ATR trailing stop with ratchet → fires modify_sl webhook events so your backend can amend the exchange-side stop as the trade moves. Min-improvement threshold (× ATR) respects your alert budget. Backtest stop ratchets identically — what you test is what executes.
- Payload aligned to a real production executor contract: signal_id (idempotency — collision-proof across same-bar events), token (auth), strategy (ownership tag for multi-strategy backends: one strategy owns each coin), side_intent (route on intent, not action names), qty / leverage (server-side clamped), price_ref, sl_price / tp_price.
- FIXED: the on-chart payload preview table now actually renders. Two bugs: the whole JSON drew as one cell wider than the pane, and barstate.islast never fires for a strategy under a Strategy Tester deep-backtest range — so v1.0's table never displayed. Now chunked across short rows and drawn on barstate.isconfirmed. Works everywhere.
- DOCUMENTED: the stale-exit trap. TradingView composes strategy.exit alert messages at order placement, but stop fills happen intrabar — exit alerts arrive with an old ts BY DESIGN. Exempt reduce_only / modify_sl from strict freshness checks; a replayed exit is harmless by construction. This bug cost me a manual recovery on my own testnet — documented so it doesn't cost you.
- Alert setup is now: "Order fills and alert() function calls" (order fills carry entries/exits, alert() calls carry trail updates).
- Rename map in comments for wiring to any TradingView→exchange bridge.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน