Your indicator on TradingView already shows the signals — but you’re not going to stare at the chart 24/7. That’s where alertcondition and webhooks come in: Pine fires the alert, and TradingView sends a message (JSON) to an address of yours, which can trigger a bot. This guide shows the correct syntax in Pine Script v5, how to build the webhook payload, and the real considerations of anyone automating. Important: trading is extremely high-risk and webhooks don’t guarantee profit — test the whole flow in a demo account.

Got the signal but missing the execution? See how a Python bot receives the webhook and trades with risk management — testing in a demo account.

See the Python bot →

alertcondition vs alert(): which to use?

In Pine v5 there are two paths. alertcondition() creates a “condition” that you select manually when creating the alert in TradingView. The alert() function, on the other hand, fires dynamically during execution and lets you build the message in real time. For webhooks with a dynamic payload (price, asset), alert() tends to be more flexible; alertcondition() is great for fixed, simple signals.

alertcondition syntax

alertcondition(condition, title, message)

condition — the boolean expression (e.g. a crossover).
title — the name that appears in the alerts list.
message — the text sent (it can be the webhook JSON).

Example: crossover signal

//@version=5 indicator(“Alertas EMA – IA Trader Pro”, overlay=true) emaFast = ta.ema(close, 9) emaSlow = ta.ema(close, 21) buy = ta.crossover(emaFast, emaSlow) sell = ta.crossunder(emaFast, emaSlow) plot(emaFast, color=color.green) plot(emaSlow, color=color.red) alertcondition(buy, “Compra”, ‘{“acao”:”BUY”,”ativo”:”{{ticker}}”}’) alertcondition(sell, “Venda”, ‘{“acao”:”SELL”,”ativo”:”{{ticker}}”}’)
TradingView placeholders: inside the message you can use variables like {{ticker}}, {{close}}, {{time}}, and {{interval}} — TradingView replaces them with the real values at the moment the alert fires.

Dynamic message with alert()

If you want to build the JSON in real time (e.g. include the calculated price), use alert() inside the condition:

if buy msg = ‘{“acao”:”BUY”,”preco”:’ + str.tostring(close) + ‘}’ alert(msg, alert.freq_once_per_bar_close)

The second argument controls the frequency: alert.freq_once_per_bar_close fires only at the bar close — recommended to avoid signals that “repaint” during the candle.

Configuring the webhook

In TradingView, when creating the alert: check the Webhook URL option and paste your server’s address (e.g. an endpoint that receives POST). The alert message becomes the body of the request. Your server reads the JSON, validates it, and then executes the order via the broker’s API.

Security considerations: anyone who discovers your URL can send requests. Include a secret token in the JSON and validate it on the server; use HTTPS; and never expose broker keys in Pine. The webhook should only carry the intent (BUY/SELL), never credentials.

Honest limitations

Webhooks are powerful, but they have pitfalls: the feature depends on your TradingView plan; alerts can be delayed by seconds (bad for very fast scalping); not every binary options broker accepts external execution; and “automating” doesn’t fix a bad strategy — it just executes a losing one faster. A good webhook + a strategy with no edge = losing money faster.

FAQ

Do I have to pay to use webhooks?
Yes, sending alerts via webhook depends on paid TradingView plans. Check your current plan.

alertcondition or alert()?
Use alertcondition for simple fixed signals; use alert() when you need to build the message dynamically.

How do I avoid repainted signals?
Fire at the bar close (alert.freq_once_per_bar_close) and avoid conditions that change during the candle.

Does TradingView execute the order itself?
No. It only sends the message. The one that executes is your server/bot that receives the webhook.

Disclaimer: trading is a high-risk activity and most retail traders lose money. This content is educational and technical; it does not constitute an investment recommendation, an offer, or financial advice. Automation does not predict the future nor guarantee results; past results do not guarantee future results. Always test in a demo account before risking real capital, and never invest more than you can afford to lose.