TradeLayer receives your TradingView alerts through a webhook and turns them into trades on your connected brokers. This page has the webhook URL, the exact alert message to paste, and a ready-made Pine strategy example. You can also generate all of this inside the app (Connections → Alert maken).
In TradingView, open your alert, tick Webhook URL under Notifications, and paste your server's webhook endpoint:
https://mytradelayer.com/api/v1/webhooks/tradingviewThe app shows your exact URL under Connections → Alert maken. Self-hosting on your own domain instead? Swap mytradelayer.com for yours — the path stays the same.
Every alert must carry your webhook secret so no one else can post trades to your server. TradingView can't send custom headers, so the secret travels inside the JSON as the secret field.
Set it once in the app under Connections → Webhook; the same value goes into every alert message below. Keep it private — treat it like a password.
Using an indicator or study alert? Paste this JSON into the alert's Message box. TradingView fills {{ticker}} and {{close}} automatically, so one alert works on whatever chart you place it on. Set direction to match this alert (a long alert vs a short alert):
{
"secret": "YOUR_SECRET",
"event": "ALERT",
"strategy": "My Strategy",
"asset": "{{ticker}}",
"direction": "LONG",
"price": {{close}},
"sl": {{plot_0}}
}sl is optional — point {{plot_0}} at your stop-loss plot, or drop the line. Add "tp": {{plot_1}} the same way for a take-profit. TradeLayer sizes the trade from your risk % and the stop.
LONG/SHORT, long/short and buy/sell all work — so a strategy can send {{strategy.order.action}} directly (see below).Using a Pine strategy? Build the JSON inside the script with alert_message, and in the TradingView alert box use only {{strategy.order.alert_message}}. Then you need just one alert per ticker and the script decides long/short every time.
//@version=5
strategy("TradeLayer example", overlay=true)
// your entry logic
fast = ta.sma(close, 9), slow = ta.sma(close, 21)
longCond = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)
// Build the TradeLayer alert JSON. Pine fills in the values.
msg(dir) =>
'{"secret":"YOUR_SECRET","event":"ALERT","strategy":"My Strategy",' +
'"asset":"' + syminfo.ticker + '","direction":"' + dir + '",' +
'"price":' + str.tostring(close) + '}'
if longCond
strategy.entry("L", strategy.long, alert_message = msg("LONG"))
if shortCond
strategy.entry("S", strategy.short, alert_message = msg("SHORT"))Create the alert on "Any alert() function call" / the strategy, set the condition to your strategy, and put {{strategy.order.alert_message}} in the Message box. To also close on the opposite signal, add a "CLOSE" message with the same trade_ref, or turn on side-swap (flip) for the strategy in the app.
| secretreq | Your webhook secret (from the app). Authenticates the alert. |
| eventreq | ALERT (new setup), CLOSE or INVALIDATE (follow-ups on the same trade_ref). |
| strategyreq | The strategy name — must already exist in the app. Routes the trade and applies that strategy's config. |
| assetreq | The instrument, e.g. {{ticker}}, EURUSD, BTCUSDT. Resolved tolerantly. |
| directionreq | LONG/SHORT — also accepts buy/sell and {{strategy.order.action}}. |
| price | Entry/reference price, e.g. {{close}}. |
| sl / tp | Stop-loss / take-profit. Needed for risk-based sizing; a strategy may require both. |
| trade_ref | Your own id shared by all events of one trade (so a CLOSE finds the right ENTRY). e.g. {{timenow}}. |