Technical analysis is a method of forecasting the direction of price through the study of past market data, volume and price being the market data we are interested in. Quantitative analysis and behavioral economics use many of the tools covered under technical analysis, showing that it has applications which are appreciated by a variety of market practitioners. If you are interested in the history of technical analysis along with comprehensive coverage regarding the concept behind this topic, I recommend you go through A Brief Overview of Technical Analysis, an article which is available on this blog.

## Implementation of Technical Analysis

Having already discussed the history of technical analysis in the article mentioned above, we will be discussing some of the use cases of technical analysis in this one, the use case being: plotting some of the well known indicators in order to see how they can aid us in our analysis of a particular security, and making use of technical analysis indicators in a trading strategy. Having discussed the agenda, lets get to it!

### Plotting Technical Indicators

Simple Moving Average

A simple moving average(SMA) calculates the average of a selected range of closing prices, by the number of periods in that range. The code and plot of the SMA indicator applied to Apple’s stock is shown below.

Exponential Moving Average

An exponential moving average places greater weight and significance on the most recent data points, thus making it more biased to the most recent prices of the relevant data. The code and plot are shown below.

Bollinger Bands

Bollinger Bands are a type of statistical chart characterizing the prices and volatility of a financial instrument over a particular time period, using a formula proposed by John Bollinger, a CFA charter holder. The code and plot are shown below.

Relative Strength Index

The relative strength index is a technical indicator that is intended to chart the current and historical strength of weakness of a security based on the closing prices of a recent trading period. The code and plot are shown below.

The fact that we only discussed 4 technical indicators should not deter you as a reader from experimenting with some of the more exotic technical indicators, especially considering how simple the TA-lib makes it apply technical indicators to a security. For our purposes though, four are enough. Now, we move on to applying technical analysis to a trading strategy.

## A Trading Strategy and Technical Analysis

Having coded and visualized a few technical indicators, it now time to apply that knowledge to and create a trading strategy, as we’ve done in posts like Exploring Quantamental Investing with Python and Quantopian, among others. An important point to mention about this strategy will not be as thorough because it was not done on Quantopian, the reason being that Quantopian no longer offers that functionality. This is a tragic loss for all quants(aspiring and flourishing) worldwide. In spite of this, we will make best of what is available.

The proposed strategy makes use of two technical indicators ,Bollinger Bands and RSI, as a voting system to decide whether to buy or sell a security when the correct parameters have been satisfied. When written out in code, this is what the voting system looks like.

The above code shows why python is superb for algorithmic trading purposes: its concise and understandable! Also, its pretty easy to change the voting system by making use of more or less technical indicators than the ones mentioned, depending on what you would like achieve. The code used in this strategy will be uploaded to my GitHub soon after this post.

When applying the voting system to Coca-Cola stock from 2015-02-24 to 2021-02-23 , we get the following results, presented through a matplotlib plot. The plot shows the trades made, superimposed on the stock price via green and red dots. Thereafter the plots for RSI and Bollinger Bands are given.

When applying the voting system to IBM stock from 1990-02-26 to 2021-01-25, we get the following results, presented through a matplotlib plot. The plot shows the trades made, superimposed on the stock price via green and red dots. Thereafter the plots for RSI and Bollinger Bands are given.

## Conclusion

Its safe to say that technical analysis can be used to create profitable trading strategies. Its unfortunate to not be able to backtest this strategy through Quantopian, but all in all, this blog post has achieved its intended purpose. Complement this article with the following video.

## References

Trading Strategy: Technical Analysis with Python TA-Lib, __towardsdatascience.com__

Technical Analysis of Stocks using TA-Lib, __towardsdatascience.com__

Technical Analysis, __wikipedia.com__