What an alert actually is
A Pine alert is a condition attached to a script. When the condition becomes true on the latest bar, TradingView sends a notification — email, SMS, push notification, or webhook. For a strategy, the built-in alert types are "Order fills only" and "Order fills and ...", which fire on every simulated order.
The custom alert pattern
longSignal = ta.crossover(fast, slow)
alertcondition(longSignal, title="Long signal", message="SMA cross long on {{ticker}} at {{close}}")
alertcondition takes a condition (series bool), a title, and a message template. Placeholders like {{ticker}} and {{close}} are substituted at firing time.
Strategy alerts
For strategies, use the built-in alert type "Order fills only" — Pine emits a JSON payload describing each fill. Most automation platforms (3Commas, Pineconnector, custom brokers) consume this JSON.
Webhook destinations
TradingView paid plans let you route alerts to a webhook URL. You post the alert payload to your own server, which translates it into a broker API call. This is how a Pine strategy fires a live order through a broker that does not have native TradingView integration.
JSON message template
strategy.entry("Long", strategy.long, when=longSignal)
strategy.exit("X", "Long", stop=close - stopDist, limit=close + stopDist * 2)
if strategy.position_size > 0 and strategy.position_size[1] == 0
alert('{"action":"buy","ticker":"' + syminfo.ticker + '","qty":' + str.tostring(contracts) + ',"sl":' + str.tostring(close - stopDist) + ',"tp":' + str.tostring(close + stopDist * 2) + '}', alert.freq_once_per_bar_close)
The alert() function lets you fire a custom JSON message on a specific bar event. Use alert.freq_once_per_bar_close for "fire only when the bar closes and the condition is still true" — this avoids intra-bar whipsaw.
From signal to fill
Pine does not place live orders. The chain is: Pine fires alert → webhook → your server → broker API → live fill. Each hop is a place where something can break, so test on paper first.
What to take from this
The strategy is the easy part. The hard part is the wiring. Start with paper trading the alert messages, validate the chain, then go live with the smallest size your broker allows.