Predicting Lows and Highs in Stock Prices

Finding suitable entry and exit points

Buy low, sell high — this is the major axiom of investing. Being able to predict entries and exits for trades will enable traders to outperform the market, even if the model is not perfect. It just needs to be greater than a coin flip, or 50–50. Extrapolated over multiple trades over a long time frame, it will be profitable.

However, a simple 50%+ accuracy may not be profitable enough to beat buying and holding. Therefore it is important to get as close to 100% accuracy as possible to outperform the market, or even profit in a bear market.

Technical Indicators

Technical indicators are the most commonly used measurements traders use to guide their investments. They track movements in price history and the supply and demand dynamics of the particular security.

This is different than fundamental investing which takes into account macroeconomic factors, financial statements, and other sentiments in the market, ultimately, what is the value of the stock compared to it’s price?

Hundreds of technical indicators exist, but the most commonly used indicators fall into three types:

  1. Momentum: Identify when the price is moving up or down and to what degree
  2. Volume: Number of executed trades
  3. Trend: Measurement of the direction of trend using averaged price data


The model used was a logistic regression model using weight-of-evidence encoder and KBinsDiscretizer binner. The metric used for accuracy was a cross validation ROC-AUC score mean. The GitHub repository is here.


It is important to use avoid using indicators which convey similar information as they will likely not add any meaningful information to the model that one of those indicators already contains.

The indicators on this chart of HPQ show similar information

Instead, indicators which convey different or dissimilar information should be used as they will contribute more meaningful information to the model.

These indicators for HPQ show different information

Technical indicators used were MACD, RSI, volume spikes, 9-day moving average, and 20-day moving average.


The data for this model was obtained via the Yahoo Finance Library for Marathon Oil Corp. (MRO) stock. Below, the buy low points are denoted by green ticks, the sell high, red.

Buy Predictions

X-axis is price, Y-axis is days from 5 years ago

The model predicted buy points with 68% accuracy while backtesting along with many false positives. Predictions are denoted by green spikes, actual by orange.

Sell Predictions

X-axis is price, Y-axis is days from 5 years ago

The model predicted sell points with a much greater accuracy of 85% while backtesting with fewer false positives. Predictions are denoted by green spikes, actual by orange.


This model seems to be better at picking short positions than long positions. It may be more suited for short traders or for options trading strategies which take advantage of short positions. More features should be added and more stocks should be examined to improve this model.

I am a data scientist having recently graduated from the Flatiron School Immersive Data Science Bootcamp