HomePine Script Snippets › TradersPost Webhook JSON

Pine Script Webhook JSON for TradersPost

Fires the exact JSON payload TradersPost expects from a TradingView alert — buy, sell, and exit actions built at runtime with alert().

//@version=6
strategy("TradersPost Webhook JSON", overlay=true, calc_on_every_tick=false)

// ── Inputs ──────────────────────────────────────────────
qty = input.int(1, "Contracts", minval=1)

// ── Entry logic (replace with your own conditions) ───────
longCondition  = ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
shortCondition = ta.crossunder(ta.ema(close, 9), ta.ema(close, 21))

// ── TradersPost JSON payloads (built at runtime) ─────────
// {{...}} dialog placeholders are NOT processed inside alert(),
// so the ticker and quantity are concatenated with str.tostring.
buyMsg  = '{"ticker": "' + syminfo.ticker + '", "action": "buy", "quantity": ' + str.tostring(qty) + '}'
sellMsg = '{"ticker": "' + syminfo.ticker + '", "action": "sell", "quantity": ' + str.tostring(qty) + '}'
exitMsg = '{"ticker": "' + syminfo.ticker + '", "action": "exit"}'

if longCondition
    strategy.entry("Long", strategy.long, qty=qty)
    alert(buyMsg, alert.freq_once_per_bar_close)

if shortCondition
    strategy.entry("Short", strategy.short, qty=qty)
    alert(sellMsg, alert.freq_once_per_bar_close)

// Call from your own exit logic when you flatten:
// alert(exitMsg, alert.freq_once_per_bar_close)

Settings

How to use

Frequently Asked Questions

What JSON does TradersPost expect from TradingView?

A minimal payload has ticker, action, and quantity: {"ticker": "MNQ1!", "action": "buy", "quantity": 1}. Supported actions include buy, sell, and exit. TradersPost reads the JSON from the alert message body and routes the order to your connected broker.

How do I send a webhook alert from Pine Script?

Call alert() with your JSON string inside the entry block, using alert.freq_once_per_bar_close so it fires once per signal. Then create a single alert on the strategy in TradingView, choose "Order fills and alert() function calls", and paste your TradersPost webhook URL in the notifications tab.

Should I use alert() or alertcondition()?

For strategies, alert(). It builds the message at runtime with str.tostring, fires from inside your order logic, and needs only one alert in TradingView. alertcondition() only works in indicators, cannot see strategy fills, and needs a separate alert per condition.

Related

Want a complete eval-ready strategy wired for TradersPost?

This snippet is a building block. Our paid scripts are complete strategies — entries, safety rules, and webhook alerts pre-wired for TradersPost, tested on 3 years of MES/NQ data. Instant delivery from $50.

View Plans — From $50