Creating a TA (technical analysis) crypto trading bot for Binance using Tradingview

Chances are you’ve heard of Technical Analysis (TA) before, and you have probably used it at one point in order to make an informed decision about your trades. Given how number-based most (if not all) TA indicators are, it’s quite easy to integrate technical analysis into a crypto trading bot, especially by using Tradingview and the Binance API.

But before we go any further, let’s cover the basics in case you’re not already familiar with TA.

What Is Technical Analysis?

Technical analysis (TA for short) is a trading concept that is used to determine opportunities in the market by analysing metrics collected from historical trading activity, such as the price, movement or volume of an asset. The formulas are usually known as indicators, because they indicate the market’s direction.

Technical analysis can also be performed by algorithms, or crypto trading bots in order to confirm a trend, and place an order automatically.

But of course, in order to perform technical analysis on an asset, be it crypto or otherwise, we need to have a dataset. By default, the Binance API does not offer much in the way of TA, so we’re going to use Tradingview TA.

TA crypto trading bot examples

In the previous article, we went over how to build a simple DCA bot from scratch. We will be using this codebase to add TA logic to our DCA strategy. This crypto trading bot works on Binance, so make sure you have an account open first.

Here is the code, before we any technical analysis was added onto this crypto trading bot:

The above is a very simple example of how a simple crypto trading bot in Python would work on Binance. This bot will buy 0.0014 worth of BTC every week. But what if you only wanted to Buy when the market is down? Or when TA indicators confirm you should? 

For that we need to import tradingview-ta library into Python and create some basic logic using the TA_Handler method:

Using this method, Tradingview TA will crunch a collection of 18 different indicators, and provide us with an easy-to-follow recommendation. Here is an output example for the above function:

This is just the tip of the iceberg with Tradingview TA. The API allows you to go much more granular if you need, and only focus on certain selected indicators, and use the raw values rather than the computed recommendation, however for the scope of this bot, we’ll stick with the computed recommendation.

Ok so let’s add this onto our DCA bot:

There you have it. If you run this script, the bot should check the TA computed results using Tradingview TA, and, based on that decided whether it should be buying BTC (or any other coin you have defined) this week.

It doesn’t have to be once a week, simply modify or remove the time.sleep entirely and the bot will constantly check for opportunities to buy. You will also need to adjust the TA interval if you’re considering shorter term trades, as checking multiple times a second over a 1 week interval won’t be of much help.

Did you enjoy this article? Here’s what to do next…

Become a subscriber by clicking the Button in the bottom right corner. You’ll receive more guides, articles and tools via e-mail. All free of course.

But if you value this blog and its educational resources, you can subscribe to become a paid member for only $3 a month. This will keep the website open and free.

If  you’re looking for a custom-built cryptocurrency trading algorithm, shoot me a message and let’s talk.

Leave a Reply

Your email address will not be published. Required fields are marked *