TradingView doesn’t really need an introduction: it’s probably the most used platform for doing technical analysis, indicator and trading script development.

TradingView can do so many things, except actually place trades on the exchanges that matter for crypto traders.

This article is about how to use Gunbot with the Tradingview Add-on to execute trading alerts sent from TradingView.

Examples of cool stuff you can do with Gunbot, and learn in this article:

Make sure TradingView sell alerts only execute when they are profitable

Use alerts for buying and let Gunbot handle selling, using a trailing stop

Let Gunbot take care of averaging down your bags

The config parameters in this article use the syntax as needed in the Gunbot config.js file. These are sometimes slightly different than how they show up in the GUI.

How does Gunbot integrate with TradingView?

TradingView alert example

Picking up alerts from TradingView in Gunbot is easy:

Make sure the alert is sent by email

Send the order type, trading pair, exchange name and trading limit in the message contents

Connect Gunbot to the IMAP server of the email address the alert gets sent to. This works with Gmail or any other IMAP mail server.

This is how to configure Gunbot to listen to incoming alerts from TradingView (or any source: as long as the alert content follows the expected format, Gunbot can execute it).

Scenario 1: TradingView all the way. Just execute the alerts already

Let’s say your script at TradingView just rocks, all you want is have your alerts executed. This is how to do that.

Properly format the alert message contents

The required alert syntax is easy, let’s look at one and break down all the options it offers:

Working alert: BUY_BINANCE_BTC-ETH_0.1 Abstracted: ACTION_EXCHANGE_PAIR_AMOUNT

Options for ACTION :

BUY > places a buy order

> places a buy order SELL > places a sell order

> places a sell order LONG > opens a long position, on supported exchanges for margin trading

> opens a long position, on supported exchanges for margin trading SHORT > opens a short position, on supported exchanges for margin trading

> opens a short position, on supported exchanges for margin trading CLOSE > closes an open margin position

Input for EXCHANGE :

Contains the name of any supported exchange in Gunbot, in ALLCAPS.

Define the PAIR :

Gunbot expects pairs to be defined as BASE-QUOTE. Where the base currency is the one used to purchase quote. Say you want to buy BTC with USDT, the pair would be written as USDT-BTC.

Set the AMOUNT :

The amount in the alert is defined in base currency. Say the pair is USDT-BTC and the amount is set to 1000, an executed buy order would try to buy 1000 USDT worth of BTC.

Amounts in buy alerts are optional but convenient. When no amount is defined, Gunbot will use the general trading limit as set in the configuration options for the TradingView add-on.

2. Enable gain protection for sell orders (optional)

If you want, you can set Gunbot to never allow it to execute sell orders that would lead to a loss.

To do so, enable the TV_PROTECTION option in Gunbot.

3. Cap your investment per trading pair (optional)

Does your trading strategy place consecutive buy orders (“pyramiding”)? This can get out of hand quickly when you don’t limit it somehow.

Using the TV_TRADING_LIMIT_CAP setting you can limit the investment per trading pair to an absolute amount, expressed in base currency. Every incoming buy alert that would exceed this cap, gets ignored.

Scenario 2: Just buy with TradingView alerts, let Gunbot sell

There are pretty good bottom finder scripts out there on TradingView, together with Gunbot you can use this to buy bottoms, sell tops.

To do this, you need to setup the following:

Send buy alerts from TradingView

Besides enabling the IMAP listener in Gunbot, enable the TV_GB option too. This makes Gunbot run in mixed mode: receive alerts and process pairs set in Gunbot.

option too. This makes Gunbot run in mixed mode: receive alerts and process pairs set in Gunbot. A strategy that only sells, we’ll use an example that uses trailing

A trading pair in Gunbot that runs the sell strategy

Enable TV_GB mode

The TV_GB option makes it possible to run pairs (with each their own strategy) in Gunbot itself, and simultaneously receive and execute incoming TradingView alerts. Enable it on the TradingView preferences page in Gunbot.

2. Create a sell only strategy

Let’s create a strategy that only sells the assets bought using TradingView alerts:

The buy method is irrelevant here, as it will get disabled. “tssl” is short for “trailing stop / stop loss”.

Disable buying for this strategy:

Set the relevant sell parameters:

In this example GAIN is set to 2. That means it aims for a minimum sell of 2% above the break-even point. In case multiple buy orders happened since the last sell order, the break-even point is automatically calculated using a weighted average price per unit.

The SELL_RANGE defines the trailing range, as a percentage below the highest bid price.

These settings will do this:

When prices increase 2.5% above the break-even price of your buy order(s), Gunbot will effectively start sell trailing (minimum target of 2%, plus the range of 0.5%).

As long as prices keep increasing, the trailing stop is set 0.5% below the highest bid price.

When the price direction changes, the trailing stop is frozen.

When the highest bid price crosses the trailing stop, all available quote assets are sold. If prices do go up again, trailing continues.

This sell order was realized using the exact sell settings described above.

3. Add the trading pair you are sending alerts for

Now add the trading pair you are sending alerts for, and assign the strategy you just created:

Scenario 3: Buy and sell using TradingView alerts, use Gunbot to automatically average down when prices drop

You can use the mixed mode of Gunbot to simultaneously execute buy and sell alerts from TradingView and use the dollar cost averaging (DCA) feature available for Gunbot strategies. This allows you to lower the average price per unit, in case prices drop a lot after a buy order happened.

Averaging down looks like this. The first arrow shows the initial buy order, the second and third arrows are Gunbot processing DCA. The result would be that the average price per unit is about as high as the rates around the second buy order. That’s a lot more realistic to profitably sell soon than without using DCA.

This is what you need to set that up:

Send buy and sell alerts from TradingView

Besides enabling the IMAP listener in Gunbot, enable the TV_GB option too. This makes Gunbot run in mixed mode: receive alerts and process pairs set in Gunbot.

option too. This makes Gunbot run in mixed mode: receive alerts and process pairs set in Gunbot. A strategy that only does DCA

A trading pair in Gunbot that runs the DCA strategy

Enable TV_GB mode

The TV_GB option makes it possible to run pairs (with each their own strategy) in Gunbot itself, and simultaneously receive and execute incoming TradingView alerts. Enable it on the TradingView preferences page in Gunbot.

2. Create a DCA only strategy

To create a strategy that places no regular buy or sell orders, and only averages down, we have to get a bit creative:

The buy and sell methods don’t matter a lot here, as only DCA will be used.

Make sure no regular buy orders are placed:

To prevent the gain buy method from placing regular buy orders, set BUY_LEVEL to 99. This means that the strategy would only ever place a buy order when the current lowest ask price is 99% below the current EMA (which should never happen, with normal settings for EMA).

Buying needs to be enabled for DCA orders to be placed.

Disable selling:

This leaves selling to your script at TradingView.

Enable DCA:

DCA is called “Double up” in Gunbot, shortened: “DU”.

Let’s go over the settings used in the example above:

DOUBLE_UP : true

This allows Gunbot to average down

DOUBLE_UP_CAP : 1

Defines how much extra quote units are bought for each DU buy, 1 means a ratio of 1:1. Say you own 1 BTC at the moment Gunbot is about to average down, then it will purchase another 1 BTC (consequently, the second round of averaging down will lead to a buy order of 2 BTC).

DU_CAP_COUNT : 2

Sets the allowed maximum frequency of averaging down. When set to 2, Gunbot is allowed to average down two times.

DU_METHOD : RSI

This sets the method used for averaging down. RSI means that Gunbot will only place DCA orders when RSI is below a set threshold.

RSI_DU_BUY : 30

Sets the RSI threshold. Gunbot will only place DCA orders when RSI is 30 or lower.

DU_BUYDOWN : 2

Defines a minimum price drop between two buy orders. This means that the first DCA order may only be placed when prices are at least 2% below the last buy price (and RSI is below 30).

3. Add the trading pair to Gunbot and assign the DCA strategy

Now add the trading pair you are sending alerts for, and assign the strategy you just created:

You’re all set after adding this pair.

If you liked this story, please feel free to waste 15–20 seconds to give it 50 claps.