TradingView webhooks

How to use webhooks with TradingView to automate alerts, trades and more.

TradingView is a popular charting platform and social network for traders and investors that provides tools for technical analysis of financial markets. It offers customizable charts, over 100 technical indicators, drawing tools, and a community forum to share and discuss trading ideas. Users can also connect their brokerage accounts to trade directly on the platform

Webhook Relay allows to receive, transform and forward webhooks to multiple destinations. In this tutorial we will show how to use it to receive webhooks from TradingView and send them to Discord.

Setup Discord to receive webhooks

We will be sending webhooks to Discord. Get your Discord webhook URL from here:

Create discord webhook

Copy it, we will use it in Webhook Relay.

Setup Webhook Relay

  1. Open https://my.webhookrelay.com/new-public-destination and add the URL we copied from Discord.
  2. Then, on the input click this "Transform":

Transform input

Now, we will need to create a new function:

  1. Open Functions page and click "Create function".
  2. Select from scratch
  3. Copy paste this:
local json = require("json")

local new_body = {
    content = r.RequestBody,
}

local encoded_payload, err = json.encode(new_body)
if err then error(err) end

r:SetRequestHeader("content-type","application/json")
r:SetRequestMethod("POST")
r:SetRequestBody(encoded_payload)

This function will receive the webhook from TradingView and send it to Discord in a special format. You can add any logic here!

Let's create an alert

Let's head to TradingView and create a new alert. I will monitor BTC price and create an alert. This is merely an example, you can use it with NVIDIA, S&P or anything else where you want to get notified about market events:

Creating an alert

Now, configure it to the Input URL we copied from Webhook Relay. In the message field you can write any message you want, it will be sent to your webhook endpoint.

Send a test payload and we will see the alert:

Discord message

Other use cases could involve:

  • Sending you an email
  • Triggering a Slack message
  • Performing a trade on your behalf as you can call another API from within a function