Using Python in Build Alpha [Creating Custom Signals]

Build Alpha and Python

As 2017 comes to an end, I want to introduce one more upgrade to BuildAlpha in its first year. As you know Build Alpha allows users to create, stress test, and even generate tradable code without ANY programming at all.
It also allows traders to use a custom drag and drop signal builder to create unique rules and signals to test alongside the pre-built Build Alpha signal library of nearly 5,000 signals – and growing (below is a picture of the drag and drop custom signal builder).
Build Alpha Custom Indicator Editor 2

However, I have now added a python environment to give traders even more freedom. Traders now have the ability to code their own signals in python and optimize these signals in the Build Alpha strategy creation engine.

Again, you do NOT need ANY programming skills to use Build Alpha but if you WANT to you can now use python to create signals, but you do NOT have to as Build Alpha will work without. This is just an upgrade for the more sophisticated traders out there.

Python Example in Build Alpha

Below is a simple, step-by-step walkthrough of how to create a signal using python and test it with other pre-built signals in Build Alpha. 

Step One: File >> Custom Indicator Editor

This step opens the custom indicator editor pictured above. 

File Custom Indicator Editor Menu Option

Step Two: Add new indicator and select Python

In the lower left of the new window that opens, please select Add and then near the top of the interface please click on Python. Both of these are circled in red below.

Add Python Indicator to Custom BA Editor

Step Three: Create and save the file

Hit the Create button which will open your File Explorer. Name the file that will contain your custom python script and select an appropriate file location to save the file. 

You can also give your indicator a name in the top Name input box. Please note that this is the name that will appear in the main Build Alpha signal selection window.

In the example below I’ve named my custom python indicator “MyCustomIndicatorName” (green box) and named the file “CustomExample.py” (lower red box) while saving to my File Explorer. 

Custom Indicator Name

Step Four: Add your code and save

Build Alpha then produces a simple to use template and we just need to add our custom code in the GetCustomSignal function. I have added a small moving average example below.

The only requirement is that we return a Signal list with the same length as data rows in our input data. That is, we must have a true or false signal for every bar. Do not drop NaNs. 

Step Five: Custom Parameters

Build Alpha also supports custom parametric python signals. We can add variables between these comment sections like this

Custom Indicator Python Parameter Variable

Then edit your code in the GetCustomSignal function to utilize your new parameter variable. Here is mine edited below. Notice I have removed the magic number 8 and replaced it with the sma_length variable which stores the value 8 at the moment.

Custom Indicator Python Parameter Replaced

Now save your custom python script and hit Save on the Build Alpha Custom Indicator Editor window. The indicator is now saved and will appear in your Custom Signals list of the main Strategy Builder interface.

If you click on your custom signal in the Strategy Builder you will now see the ability to edit the parameter range for any custom parameters you have added to your python script. Below I have set to optimize mine as 8, 16, 24, 32, 40, 48, 56, 64. 

Running a simulation will then show all possible parameter variations for your custom python indicator. I set two max rules and required the second rule to be Not Sunday (always true) so each row has one variation of my custom python signal.

Custom Parametric Python Signals Results Window Build Alpha

This new feature opens the door for what is possible in Build Alpha. Traders can leverage the power of python as well as BuildAlpha in extremely easy to use ways.

Installing Python Libraries for Build Alpha

Build Alpha’s python environment is a full python environment which means we can import any external python libraries. The above example imported the famous technical analysis library, talib, to create a moving average trading strategy with python.

You can add any external python library. The Build Alpha python installer includes talib, sci-kit learn, scipy, matplotlib and many other essentials.

Install Python Library for Technical Analysis Indicators

If you do not have talib installed or want to add a new python library, then open a command terminal and navigate to your python directory.

You can type ‘cmd’ into the start menu of most Windows devices. If you used the Build Alpha installer then talib is included. However, you can navigate to your python directory like this below:

Please note you can always check the folder inside Build Alpha for the most recent version of Python. At the time of writing we are using Python 3.11 so the folder name is TTPython311.

Then install talib using the following prompt below. Notice the hyphen in ta-lib.

Hit <ENTER> and you have now added a new library for use in python for Build Alpha. You can import the new library to the top of any new python script and Build Alpha will recognize it.

Algorithmic Trading Python

Python is the fastest growing and most versatile programming language making it extremely attractive for quantitative traders and developers. Many algo traders prefer python due to its easy-to-read code and simple syntax. Python does not require code block brackets or semi-colons to end statements, but still is object oriented providing a great mix of ease and flexibility.
Python for algorithmic trading is growing every day with new libraries and popular libraries being updated. TALIB is the most popular library, but many more advanced libraries continue to pop up. Algo trading with python has never been easier.

However, connecting to exchanges, handling live price data, and coming up with trading ideas can be a daunting task. The best part about coding is coming up with new signals. Build Alpha takes care of the heavy lifting enabling python traders to simply do the fun part: signal creation.

Summary

Build Alpha now supports the ability to import custom signals via python. This is additional functionality for programmers that want to leverage the speed and ease of Build Alpha. Reminder that this is extra and NO programming is needed to use Build Alpha’s built-in signals or drag and drop custom signal builder.

It has been one heck of a year for Build Alpha’s development and there is still so much to do in 2018! Thanks for all those that support the software; I am looking forward to next year.

Author

David Bergstrom – the guy behind Build Alpha. I have spent a decade-plus in the professional trading world working as a market maker and quantitative strategy developer at a high frequency trading firm with a Chicago Mercantile Exchange (CME) seat, consulting for Hedge Funds, Commodity Trading Advisors (CTAs), Family Offices and Registered Investment Advisors (RIAs). I am a self-taught programmer utilizing C++, C# and python with a statistics background specializing in data science, machine learning and trading strategy development. I have been featured on Chatwithtraders.com, Bettersystemtrader.com, Desiretotrade.com, Quantocracy, Traderlife.com, Seeitmarket.com, Benzinga, TradeStation, NinjaTrader and more. Most of my experience has led me to a series of repeatable processes to find, create, test and implement algorithmic trading ideas in a robust manner. Build Alpha is the culmination of this process from start to finish. Please reach out to me directly at any time.
No coding needed

Stop Wasting Time
Coding, Testing, Coding, Testing…

Build Alpha’s Genetic Algorithm uses your inputs to create 1000s of trading strategies in seconds
Recent Posts

Get updates & ideas

Learn more about BA & get exclusive insights