Introduction

This bot can be used to turn alerts from TradingView into executable signals. Once activated, the bot monitors incoming messages from your TradingView account and executes the desired action in real-time (buy, sell, close position, stop bot etc).

What is TradingView?

TradingView is a popular charting platform for traders and investors of all experience levels. It features 100s of built-in technical indicators and allows users to create and share custom indicators. Alerts can be defined based on these indicators as well as price levels, which in turn can be sent to third parties such as Quadency for automating actions based on certain events.

How does it work?

The TradingView Bot monitors alerts from your TradingView account and executes the desired action in real-time. Alerts can be triggered based on one or multiple indicators as well as price levels.

As you can see in the graphic above:

  1. The TradingView bot receive alerts from TradingView

  2. The TradingView bot reads the message included in the Alert

  3. The Bot places an order according to the message

How to Get Started

Whether you are using a simple alert or a combination of indicators using TradingView Strategies, the first steps to get your bot started are the same.

Start the TradingView Bot

1. Select TradingView bot from the Available Bots list

2. Select the Exchange, Account and Market to trade

3. Specify a Starting Capital

  • Note: Starting Capital is used as the "cash" available to the bot to buy when an amount is not specified. This value must be specified in quote currency, in this example, we're trading XRP/BTC, and thus the quote currency is BTC. The value here represents the "capital" to measure your performance against, and balances will not be validated to give users the flexibility to trade with any amounts. This means you are responsible for ensuring sufficient balances are available in your account. Insufficient balance will result in errors shown in the logs.

4. Click Start Live to start the bot

5. Once started, look for this message in the logs:

The bot is now ready to receive messages from your TradingView account.

Configure the Alert Messages in Trading View

The tradingView bot monitors incoming messages from your TradingView account via Alert messages. There are two ways to set up alerts, please follow the two guides below accordingly:

  • TradingView Alerts via a single Indicator.

  • TradingView Strategies using Pine Scripts in combination with the AlertCondition function.

In this article we are going to use Alerts, if you wish to use Strategies, please go through this article.

6. Go back to the Parameters tab and copy your personal Webhook URL

7. Go to your TradingView account and open the chart for the symbol you wish to trade. In this example, we're trading XRP/BTC.

8. Click Indicators and Strategies and search "Bollinger Bands" for this example, and click Bollinger Bands from the list (indicator, not Strategy).

7. Click Alerts in the right sidebar, and click "Create Alert"

9. Define your alert conditions as appropriate. In this case we look for XRP/BTC price crossing below the lower band of Bollinger Bands. In Options, select "Once Per Bar".

10. Paste in your Webhook URL (Note: this is a Pro features in TradingView - currently $15/mo)

11. Paste in the message to send to the bot once this alert is triggered. In this example, we are buying 10 XRP/BTC when the condition is met. Click Save.

12. That's all! You're ready to receive signals from TradingView. Each time a signal is received, the bot will output the raw message in logs so you can confirm what is being sent.

  • Note: You can find two more examples here.

Supported Actions

To place an order, the alert message must contain certain fields. As seen below, the TradingView Bot currently supports four fields

  • BotId: Define which bot will receive the alert (mandatory)

  • Action: Define the action taken by the bot (mandatory)

    • BUY: place a buy order

    • SELL: place a sell order

    • Close_Position: sell or buy back entire position depending on the side (long or short)

    • Stop_bot: stop the bot completely, it will ignore open orders and alerts

  • Amount: define the amount per order (optional)

  • Price: define the entry price of a limit order (optional)

Here are the possible actions supported at this time:

Market order

To place a market order using the entire "Starting Capital":

{
"action": "BUY",
"botId": "1234"
}

In the example above, if you are trading XRP/BTC, and your starting capital is 0.001, the bot will send a Market order to buy XRP with 0.001 BTC.

Note - if your first action is SELL, an amount must be specified.

To place a market order for a specific amount of XRP:

{
"action": "BUY",
"amount": 10,
"botId": "1234"
}

In the example above, if you are trading XRP/BTC, the bot will send a Market order to buy exactly 10 XRP, regardless of the Starting Capital set.

Limit Order

To place a limit order, include the price parameter:

{
"action": "BUY",
"price": 0.00002190,
"amount": 10,
"botId": "1234"
}

Similarly, if you omit (exclude) the amount field, but specify a price, the bot will send a Limit order to buy XRP using starting capital at the price defined.

Note: You can use dynamic price by using variables in the message as shown in this article.

Replace "BUY" with "SELL" to place a sell order. The bot will execute every order sent, so if it already bought 10, and another message comes in to BUY 10 again, it will send an order to the exchange to buy 10 more, making the total position 20.

Note: Position, in this case, is simply a tracking mechanism - it does not imply a margin/futures "position", but simply a way to track the total exposure in either direction (long, short).

Close Position

To close an open position:

{
"action": "CLOSE_POSITION",
"botId": "1234"
}

A long position is closed by selling the entire unsold quantity bought. In the example above, an order to sell 20 will be sent. In the case of a short position, where you initially sold a certain amount, an order to buy will be sent. This is useful if your strategy involves averaging in at certain levels but you are not able to keep track of the entire quantity.

  • Example 1:

  1. Buy 1 $BTC

  2. Close position = Sell 1 $BTC

  • Example 2:

  1. Buy 1 BTC

  2. Sell 0.8 BTC

  3. Buy 0.3 BTC

  4. Close position = Sell 0.5 BTC (1-0.8+0.3=0.5)

Stop Bot

And finally, you also have the ability to stop the bot by sending the following message:

{
"action": "STOP_BOT",
"botId": "1234"
}

Once the bot is stopped, it will no longer monitor messages from TradingView.

Note: You can create multiple copies of this bot and run them on different pairs, just be careful to use the correct botId. Additionally, if your strategy trades both sides (long and short), it's ideal to create two separate bots for each so there are no conflicts.

That's all! If you have any questions or want to provide feedback, reach us via Live Chat below.

Did this answer your question?