TradingView

Connect TradingView alerts

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).

You decide execution, never the alert. TradeLayer strips any control fields from an incoming alert — placing, sizing and the kill switch live in the app. An alert only tells it what the setup is, never whether to fire.

1Webhook URL

In TradingView, open your alert, tick Webhook URL under Notifications, and paste your server's webhook endpoint:

https://mytradelayer.com/api/v1/webhooks/tradingview

The 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.

TradingView needs a public HTTPS address. If your backend only listens on a private Tailscale IP, expose just the webhook path through a small HTTPS proxy (or use the public domain your install already serves).

2Your secret

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.

3Alert message (indicator / study)

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.

Direction values are flexible. LONG/SHORT, long/short and buy/sell all work — so a strategy can send {{strategy.order.action}} directly (see below).

4Pine strategy (one alert per ticker)

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.

Reference

Alert fields

secretreqYour webhook secret (from the app). Authenticates the alert.
eventreqALERT (new setup), CLOSE or INVALIDATE (follow-ups on the same trade_ref).
strategyreqThe strategy name — must already exist in the app. Routes the trade and applies that strategy's config.
assetreqThe instrument, e.g. {{ticker}}, EURUSD, BTCUSDT. Resolved tolerantly.
directionreqLONG/SHORT — also accepts buy/sell and {{strategy.order.action}}.
priceEntry/reference price, e.g. {{close}}.
sl / tpStop-loss / take-profit. Needed for risk-based sizing; a strategy may require both.
trade_refYour own id shared by all events of one trade (so a CLOSE finds the right ENTRY). e.g. {{timenow}}.
Tip: open the app and go to Connections → Alert maken to generate this message with your URL and secret already filled in — then just paste it into TradingView.