Build your own technical analysis stock screener using Python

Yong Hong Tan
Analytics Vidhya
Published in
6 min readJan 31, 2021

--

An example based on the Malaysian stock market.

There are dozens of amazing stock screener apps and sites out there like TradingView. However, most sites do not offer as much customization as you want, if you don’t pay for it.

For example, in TradingView you can easily find stocks with the last price above certain moving averages (MAs) but you are limited to the pre-defined 5, 10, 20, 30, 50, 100, and 200-day MA.

The good news is, with a few lines of Python code, you can make your own customized simple stock screener, and I am here to show you how.

If you haven’t set up Python on your computer yet, click here for the setup tutorial. If you’re totally new to Python I strongly recommend using Jupyter Notebook or Google Colab to get you started.

Step 1: Get stock prices

First things first, we need stock prices. There are, again, many great free APIs out there that allow you to access the stock prices using literally two lines of code.

import yfinance as yf
yf.Ticker("AAPL").history(start="2021-01-11", end="2021-01-15")

However, for those who have tried to do the same to the stocks listed in Bursa Malaysia (stock exchange of Malaysia), you might have come across something like this.

Fortunately, it’s not the end of the world. We can always try to scrape the stock data from some other stock websites. I am using i3investor in this example.

--

--

Yong Hong Tan
Analytics Vidhya

A developer by day, and night. Constantly learning and evolving. Contact me at linkedin.com/in/yonghong-tan