Loading...

Plus+ Python

How to Add Technical Analysis to OHLCV DataFrame in Python

How to Add Technical Analysis to OHLCV DataFrame in Python

Combining Historical Data with Technical Analysis
Technical analysis primarily focuses on price and volume data. This simplification allows analysts to filter out what they consider 'noise' – factors such as economic reports, news events, or company fundamentals – to concentrate solely on how prices have moved in the past, under the assumption that this will give insight into how prices will move in the future. Many believe that historical price movements and patterns tend to repeat themselves over time. We will write a Python script to demonstrate how to load the historical data available on our site into a Pandas DataFrame, and then add columns of Technical Analysis. We will be using the TA-LIB library, which was originally written in C++ but has since been converted to Python. This python package has over 200+ technical analysis indicators.

The Code
The code will work on any exchange on our site and available cryptocurrency pairs. The symbol relies on it being in this format: "BTC/USDT" (includes the slash). We will create columns for a SMA 20 (simple period moving average with 20 day window), an relative strength index (RSI) indicator with 14 day window, Bollinger bands (upper, middle and lower), and MACD, MACDSignal, and MACDHistogram. The script will then write a CSV file with the technical analysis indicators added to it. We also added comments to every line of code and are available for you to reach out to if you have any questions via email. Please modify as you wish or fit your purpose.

Plus+ membership required

Create a Plus+ account to view the live codebase.

This article has a fully working, notebook-ready code block. Sign up for Plus+ to access it and the rest of the 20+ premium articles.

Subscribe to Plus+ Browse Plus+ articles