Building an AI-Driven Technical Analysis Trading Strategy

Let’s build TA into an AI-driven strategy and try to find out.

Luke PoseyBlockedUnblockFollowFollowingMay 23Technical AnalysisTechnical analysis (TA) is a form of analysis used by analysts who believe they can predict future stock performance based on past trends and patterns.

TA is a hugely popular and controversial topic.

Many retail traders swear by it, others sneer at it.

Here is an example of a well-known technical indicator known as Moving Average Convergence Divergence (MACD).

I built the indicator in Python and plotted it with markers for crossovers.

A bullish crossover is a buy signal (in green), and a bearish crossover is a sell signal (in red).

MACD Example…Source: LINKThere are many different TA methods.

Some traders swear by the quality and predictive capabilities of some indicators, some traders swear by the quality of single indicators, and some traders do not believe in any form of TA whatsoever.

I sought out to build a system that predicts performance based on over 50 Technical Indicators.

Such an AI system can take into account the current technical patterns for a stock and perform a prediction accordingly.

Here’s how I did it.

Collecting the DataThe first thing I did was collect price data.

I gathered a few years of price data for my favorite stock to perform analysis on: AMD.

I then kept the closing prices from each day of that stock.

I built the technical indicators into the analysis and saved over 50 indicators from every day of trading.

You can either use some library for the indicators or build your own tools.

Sample of the CSV File Containing the Indicators…Training the ModelsI tested a number of different methods to apply regression for my predictions.

Primary methods tested included: Random Forest, Support Vector Machine, Neural Networks (various architectures).

I first trained the models using each day’s TA as samples with price data as labels.

Unsurprisingly, this performed extraordinarily well, approaching 99.


This should be wholly unsurprising.

The features are directly derived from the label itself, so this is a fairly useless analysis that should most definitely approach 100% accuracy.

This is a fun observation in theory, and it might even be worth mentioning in a paper or study.

This article is about realistic applications and this is completely useless analysis for a real-world prediction.

What would be more useful is actual predictive analytics.

Sure, if we give the trained model a set of indicators it should be able to give you the current price.

But that’s not predictive power; that’s just a neat application of curve fitting.

It’s the type of thing people have bragged about in terms of performance.

It is a neat application but not very practical.

It requires using already available indicators which are derived from the day’s stock price to predict the day’s stock price.

What use is that other than being kinda neat?.Instead, we want to provide indicators with future prices as labels.

At least this day by day analysis is a good sign our model is working as it should.

Daily Price EstimationPredicting Stock Prices and BacktestingSo I ventured on to trying to predict out to some number of days instead of performing same-day price predictions.

I began to wonder if trying to predict 5 days into the future is a worthy pursuit.

What about 10 days?.What about a short time-frame like 2 days?.So I retrained my models and gave the problem another attempt.

I used the technical indicators as features and the results from 2 days, 5 days and 10 days in the future as labels.

The results were surprisingly good, though mileage may very.

2 Day Rolling PredictionUnsurprisingly, the 2 day prediction performed the best.

The prediction suffered the further out you go.

2 day Mean Absolute Error: 2.

28 dollars, Accuracy: 91.

58%5 day Mean Absolute Error: 3.

68 dollars, Accuracy: 86.

3%10 day Mean Absolute Error: 4.

36 dollars, Accuracy: 83.

62%5 Day Rolling PredictionThe predictions were certainly lagging the actual price, but they seemed to get a mind of their own about a month in to analysis.

10 Day Rolling PredictionFurther ResearchMy next goal will be to frame this as a classification problem.

It was neat as a regression problem, but I think viewing this from a buy, sell, or hold perspective is more useful.

Try to build your own models and test to find out if more data would help the prediction.

You can also try tuning hyperparameters or exploring different models to improve accuracy.


. More details

Leave a Reply