Pine Script Webhook JSON for TradersPost
Fires the exact JSON payload TradersPost expects from a TradingView alert — buy, sell, and exit actions, all built at runtime with alert().
Pine Script
//@version=6
strategy("Target Filled - TradersPost Webhook Example", overlay=true, calc_on_every_tick=false)
// --- Inputs ---------------------------------------------------
orderQty = input.int(1, "Contracts", minval=1)
// --- Sample signal — replace with your own entry logic ---------
fastMA = ta.ema(close, 9)
slowMA = ta.ema(close, 21)
goLong = ta.crossover(fastMA, slowMA)
goShort = ta.crossunder(fastMA, slowMA)
// --- TradersPost JSON payloads (assembled at runtime) -----------
// Dialog {{placeholders}} are not substituted inside alert() — build
// the string yourself with str.tostring.
buyPayload = '{"ticker": "' + syminfo.ticker + '", "action": "buy", "quantity": ' + str.tostring(orderQty) + '}'
sellPayload = '{"ticker": "' + syminfo.ticker + '", "action": "sell", "quantity": ' + str.tostring(orderQty) + '}'
flatPayload = '{"ticker": "' + syminfo.ticker + '", "action": "exit"}'
if goLong
strategy.entry("Long", strategy.long, qty=orderQty)
alert(buyPayload, alert.freq_once_per_bar_close)
if goShort
strategy.entry("Short", strategy.short, qty=orderQty)
alert(sellPayload, alert.freq_once_per_bar_close)
// Call from your own flatten logic when closing out:
// alert(flatPayload, alert.freq_once_per_bar_close) Settings
| Input | Default | Purpose |
|---|---|---|
| orderQty | 1 | Contract quantity sent in the payload and used for the entry. |
How to use
- Paste into the Pine Editor, add to chart, and swap the EMA-crossover placeholder for your own entry conditions.
- Create one alert on the strategy: condition "Order fills and alert() function calls," and paste your TradersPost webhook URL into the Notifications tab.
- Leave the alert dialog's message box untouched — the JSON comes from
alert()at runtime, not from the dialog template. - Test against a TradersPost paper account before pointing the alert at anything funded.
Which firms allow this
Automation policy varies by firm. Current stance for two firms commonly paired with TradersPost:
| Firm | Automation Policy |
|---|---|
| Apex Trader Funding | Allowed during the evaluation. Not allowed for commercial/resold automation on live Performance Accounts — a script may still drive manual-confirm execution. |
| Topstep | Full automation permitted on the Combine (evaluation). Funded-account automation policy has changed multiple times; semi-automation (script alerts, manual confirmation) is the stated safer default rather than an outright ban. |
Frequently Asked Questions
What JSON does TradersPost expect from TradingView?
A minimal payload needs three fields: ticker, action, and quantity — for example
{"ticker": "MNQ1!", "action": "buy", "quantity": 1}. Supported actions include buy, sell, and exit. TradersPost reads this straight out of the alert message body and routes the order to whichever broker you've connected.How do I send a webhook alert from Pine Script?
Call
alert() with the JSON string from inside your order logic, using alert.freq_once_per_bar_close so it only 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 into the notifications tab.Should I use alert() or alertcondition()?
For a strategy,
alert(). It builds the message at runtime with str.tostring, fires directly from order logic, and needs only one alert set up in TradingView. alertcondition() only works in indicators, can't see strategy fills, and needs a separate alert per condition.