Technical Articles

Pine Script Part 5: Alerts, Webhooks, and Full Automation Integration

Dec 01, 202520
#Pine Script#webhook#alert#automation#algo trading

Pine Script Part 5: Alerts, Webhooks, and Full Automatic Trading

This chapter covers the most powerful part of the TradingView ecosystem: full automation.

By the end of this chapter, your strategy will:

  • Generate signals
  • Trigger alerts
  • Send JSON via webhook
  • And a bot will execute orders on an exchange

1. TradingView Alert System

Alerts are the backbone of automation. Once a strategy generates a signal, an alert sends it to your bot.

Alarm screen:
https://sancoqhub.com/go/tradingview


2. Alert Types

  • Once per bar
  • Once per bar close (recommended)
  • Crossing
  • Greater / Less than

3. Sending Alerts from Pine Script

if longSignal
    alert("LONG", alert.freq_once_per_bar_close)

4. Webhooks Explained

A webhook allows TradingView to send real-time JSON messages to a bot.


5. Webhook JSON Example

{
  "signal": "LONG",
  "symbol": "BTCUSDT",
  "price": "{{close}}",
  "time": "{{timenow}}"
}

6. alert() with JSON

msg = '{"signal": "LONG", "price": ' + str.tostring(close) + '}'
alert(msg, alert.freq_once_per_bar_close)

7. Full Automation Workflow

  1. Strategy → signal
  2. Alert → trigger
  3. Webhook → JSON
  4. Bot → executes API order
  5. Exchange → fills trade

8. Full Example Strategy with Webhook

//@version=5
strategy("Automatic EMA Bot", overlay=true)

fast = ta.ema(close, 20)
slow = ta.ema(close, 50)

longSignal = ta.crossover(fast, slow)
shortSignal = ta.crossunder(fast, slow)

if longSignal
    strategy.entry("Long", strategy.long)
    alert('{"type":"LONG","price":' + str.tostring(close) + '}', alert.freq_once_per_bar_close)

if shortSignal
    strategy.entry("Short", strategy.short)
    alert('{"type":"SHORT","price":' + str.tostring(close) + '}', alert.freq_once_per_bar_close)

plot(fast)
plot(slow)

9. Creating Alerts

  1. Add strategy
  2. Click “Alert”
  3. Choose condition
  4. Enter webhook URL
  5. Add JSON message
  6. Click Create

10. API Security

  • Enable only "trade"
  • Disable withdrawals
  • Use IP restrictions
  • Run bot on secure server

11. Premium Benefits

https://sancoqhub.com/go/tradingview


12. Conclusion

You now understand real automation.
Next chapter: Advanced Techniques & Multi-Timeframe Trading.