img

5 Easy Steps to Add TA-Lib to Your Python Trading Bot on Windows

img
valuezone 18 February 2023

5 Easy Steps to Add TA-Lib to Your Python Trading Bot on Windows

Adding TA-Lib to your Algo Trading Bot turbocharge quantitative analysis. With over 150 indicators, blazingly fast, and used by many of the world’s top quant gurus and platforms, it’s a one-stop quant analysis tool. Most importantly, it’s free and open-source!

If you’re using Python for your trading bot, installing TA-Lib and its Python wrapper can be somewhat challenging.

I know that it took me a couple of hours to figure it out, with many of the online guides out of date, containing incorrect backlinks, or just plain wrong.

If that’s you, I’ve got you covered. I’ll show you exactly how to install it and get it up and running.

Download TA-Lib

TA-Lib is built in C++. This highly efficient, low-level programming language implementation explains TA-Lib’s blazing-fast speed — however, it also means that installation is not as simple as heading to pip and running a ‘pip install …’

To download TA-Lib, you’ll need to head to a list of unofficial packages for Windows, located here. The link should take you directly to the TA-Lib section, if not, scroll down till you find it.

Make sure that you select the version with msvc.zip bit if you’re running Windows 64 bit!

Unzip and Move TA-Lib

Next, you need to set up TA-Lib to be used. This can be done in the simple Powershell command:

Expand-Archive -Path <Path to where you downloaded> -DestinationPath C:\

This command will unzip the archive (no 7zip required!) and move it to C:\ta-lib

Get Windows Build Tools

Unfortunately, Windows doesn’t include a native C++ compiling tool. If your trading bot is stuck on Windows (i.e. if you’re building a trading bot with MetaTrader 5), then this means you need to download and install the Visual Studio Build Tools.

Download whatever edition you need (the community one is free) from the link above, and make sure you include the C++ tools. It’s a large and cumbersome download, so this may take a while.

Compile the File

Once the Build Tools are installed, it’s time make (compile) TA-Lib. I’ve split the commands below into two, however, they can easily be compiled into 1 line if you’d prefer.

Run the following commands in your Powershell terminal:

# Move prompt to directory
cd C:\TA-Lib\c\make\cdr\win32\msvc
# Compile
nmake

Add to Your Project

The final step is one you should be familiar with — adding it to your project. I won’t cover all the various options for venv, adding it to a Python interpreter in an IDE.

Instead, here is the base command, drop a note in the comments if you’re stuck.

pip install TA-Lib

Quick Recap

That’s all you need to do. To recap:

  1. Download TA-Lib using the msvc file
  2. Unzip the file and move to C:\
  3. Download Visual Studio Build Tools
  4. nmake TA-Lib
  5. Perform the standard install pip install TA-Lib