Pine Script — Alert → Webhook

TradingView Pine v5 example and recommended webhook payload for automation pipelines (include a secret in the alert).

Pine Script — Alert → Webhook

Pine Script

Category: Code Library  •  Tags: pine, tradingview, webhook  •  Published: PUBLISH_DATE

Pine v5 example

      Copy// @version=5
indicator("Simple Alert Example", overlay=true)
sma = ta.sma(close, 20)
plot(sma, color=color.orange)
if ta.crossover(close, sma)
    alert('{"action":"BUY","symbol":"' + syminfo.ticker + '","price":' + str.tostring(close) + ',"secret":"YOUR_SECRET"}', alert.freq_once_per_bar)

Suggested webhook JSON

{
  "action": "BUY",
  "symbol": "BTCUSD",
  "price": 62400.5,
  "time": "2025-01-10T12:00:00Z",
  "secret": "your-obfuscated-secret"
}
  • Include a secret in the alert payload and verify server-side using HMAC or token compare.
  • Respond 200 quickly and enqueue heavy work (orders, DB writes) in background workers.

License: MIT

Back to Code Library

Don’t miss our blog post!

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *