Step by Step: How to Set Up Automated Trading for our TradingView Scripts

Cryptonerds
8 min readJul 31, 2022

--

Automated trading in a Nutshell

In automated trading, pre-established rules are used to execute trading tasks on behalf of the user. These rules are defined in a trading algorithm. Once set up, no further actions are required!

In our case, the trading algorithm is developed and hosted on TradingView. Once an entry or exit signal is detected by the algorithm, it is then immediately sent to 3Commas.

3Commas hosts the trading bot settings. The signal received by 3Commas will be translated into a trading command. Through API access, 3Commas sends the command to the exchange, which executes it automatically. This all takes place instantaneously.

Requirements:

  • TradingView account: TradingView is a charting platform that collects financial data and allows for developers to create custom trading scripts. Alerts can be generated, these are required for automated trading.

TradingView Alerts are limited for each account type:

  • 1 active Alert for a FREE account.
  • 10 active Alerts for a PRO account.
  • 30 active Alerts for a PRO+ account.
  • 400 active Alerts for a PREMIUM account.

With each active Alert, a single cryptocurrency pair can be automatically traded. Click here to create your TradingView account and receive a 30$ discount for the paid plan.

  • Our TradingView script: Our trading script generates Alert signals. We offer a 7-Day Free Trial.
  • 3Commas account: 3Commas receives the Alert signals from TradingView and sends them to the exchange. To create your 3Commas account click here.

The FREE 3Commas plan gets you one FREE SinglePair trading bot. Each bot can only trade in either the long or short direction. If you want to trade in both directions or multiple trading pairs, multiple trading bots are required, requiring a paid plan.

  • Exchange account: On the exchange, the trading will be executed.

As a user, you need to consider the exchange you use. 3Commas will work with most major exchanges. For a complete list click here. In this guide, we will use Binance and FTX as an example. To create your FTX account click here and for Binance click here, and receive a discount on trading fees.

We do recommend FTX because the API key (required to connect 3Commas to the exchange) won’t expire after 90 days.

Step 1: Connect 3Commas to your exchange

This assumes you have already created your 3Commas and exchange accounts. For 3Commas to be connected to the exchange an API key needs to be created and linked to 3Commas. This is how it’s done:

Binance

Go to the Binance website and hover the mouse over the profile icon in the top right corner, then click on “API Management”.

Now press the “Create API” button and give it a name. This will generate the API key. Next, enable the required permissions by pressing “Edit Restrictions” on the top right.

Enable the required permissions and click on “save”.

IP access restrictions: Do not select Restrict access to trusted IPs only. 3Commas leverages various IP addresses and changing the setting to Restrict access will result in connection issues.

Every 90 days Binance will automatically uncheck your API key permissions, so you can re-enable these by editing your API key on Binance and just re-check all the permissions in the previous step. You do not need to create a new API key.

FTX

Go to https://ftx.com/external-program-api-keys

In the “External Program” drop-down list, select “3Commas”.

Click on the button “Create API Key”.

This will generate the API key.

If you want to be able to trade in the short direction on FTX you must enable spot margin. Go to https://ftx.com/profile and in the margin menu select “Enable spot margin trading”. Select your leverage.

Input the API key in 3Commas

Now that the API key has been generated it can be copied into 3Commas. First, select “My Exchanges”.

Select the exchange in the dropdown menu. Be aware that Binance (Futures), Binance US, Binance (Margin), etc. all have their dedicated selection. So make sure you select the one applicable to you.

The regular Binance spot trading will only allow for trading in the long direction (long and long exit). While Binance Margin and Binance Futures allow for leveraged trading in both the long and short direction (bet against the market). FTX allows for both leveraged long and short trading after spot margin has been enabled.

Now select “API Connect”. Fill in the API Key and the API Secret and press “Connect”.

Your exchange is now connected to 3Commas!

Step 2: Create and configure your trading bot in 3Commas.

The exchange has now been connected to 3Commas. In 3Commas select “DCA bot” and press “Create DCA bot”.

On the next screen select “Advanced”.

A new screen will now open that allows for many settings in your trading bot. First select a name for your bot, select your exchange and select “Single-pair”. Multi-Pair trading bots are not compatible with TradingView, simply create a new bot for each additional trading pair required.

Next: Select the pair you want to trade, “Strategy” (Long or Short), “Profit currency” (Select Quote), “Base order size”, and “Start order type” (Select Market).

Select “Trading View custom signal”.

In the Take Profit and Stop Loss settings set the “Target profit (%)” to 1000 and change the Take profit type to “Percentage from base order”. Leave the “Stop Loss (%)” turned off. The TradingView script has these settings built in already and will manage these.

In the Safety orders settings put the “Max safety order count” both to 0. These settings won’t be used in our bot.

In the Advanced settings, no changes are to be made and it should look like this:

Now press the “Create Bot” button.

It will ask you to start the bot. Click “Start”.

These settings can be easily changed at any time in the DCA Bot Menu by clicking on the paper icon. You can also turn your bot on and off here.

You have now created and configured your trading bot in 3Commas! If you want to trade multiple trading pairs and trade in both the long and short directions you simply have to repeat this process.

Step 3: Connect your 3Commas trading bot to the TradingView strategy.

The last step is to have the TradingView strategy send a signal to your 3Commas bot. This is how you do it:

In 3Commas go to the DCA Bot menu and select the eye icon next to your bot.

In The next screen, scroll down until you see “Message for deal start signal” and “Message to close order at Market Price”. These are the entry and exit command lines in your bot.

Copy the “Message for deal start signal” by clicking on it, a box will appear once it is copied:

Now go to TradingView and load the script, select the correct timeframe and trading pair. Now go to the indicator settings.

In the “inputs” tab, scroll down until you see “Enable Automated Trading”. Select this box.

Now put in the copied “Message for deal start signal” from earlier in the “Auto Trading Long Entry Code”. Now copy the “Message to close order at Market Price” and put it in the “Auto Trading Long Exit Code”.

If you made a long bot then only fill in the upper two fields and for a short bot only the lower two fields. Make sure to fill the entry and exit codes in the correct fields!

Now press the blue “Ok” button. Wait for about 20 seconds to ensure these changes are loaded properly. Now press ALT + A and the following pop-up will appear:

In the Condition dropdown select the strategy:

Select the expiration date. Free users are advised to select the maximum of 60 days (be sure to refresh the Alert after 60 days). If you are not a free user, select open-ended:

Select the Alert actions you prefer (if you want to be alerted when a trade is made). Select the Webhook URL box and copy the following text into the field:

https://3commas.io/trade_signal/trading_view

Give your Alert a name and copy the following text into the comment field:

{{strategy.order.comment}}

If you want to trade multiple trading pairs and trade in both the long and short directions you simply have to repeat this process.

Contact

If you learned something new today and found value, please give us a like to show your support! We’d appreciate it. Message us on TradingView or Twitter if you have any questions.

We currently offer a 7-Day Free Trial for our swing trading strategy ELLIPSE. To request access click here.

For more information and the full backtest results, you can click here.

--

--

Cryptonerds
Cryptonerds

Written by Cryptonerds

We apply advanced data analysis to deliver the most responsible and sustainable crypto trading indicators available.

No responses yet