How to compute the support and resistance in Python

1 min readFinanceAlgorithmic TradingAdvanced
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

There are several ways to compute support and resistance prices in Python, depending on the data you have and the method you want to use. Here are a few examples:

  1. Using the ta-lib library: This library provides a wide range of technical indicators, including support and resistance levels. You can install it using pip install TA-Lib. Once installed, you can use the TA_Lib class to compute support and resistance levels for a given stock or other financial asset.
  2. Using the pandas and numpy libraries: You can use these libraries to perform data manipulation and calculations on your stock data, respectively, and then use those calculations to identify support and resistance levels.
  3. Using Machine Learning: You could use a machine learning algorithm like a Random Forest or Decision Tree to predict the support and resistance levels.

Here is an example with pandas

import pandas as pd

# Compute the high, low, and closing prices for the stock
high = prices["High"]
low = prices["Low"]
close = prices["Close"]

# Find the rolling maximum and minimum for the high and low prices
rolling_max = high.rolling(20).max().mean()
rolling_min = low.rolling(20).min().mean()

# Identify the support levels as the rolling minimum
support = rolling_min

# Identify the resistance levels as the rolling maximum
resistance = rolling_max

# Print the support and resistance levels
print("Support levels:", support)
print("Resistance levels:", resistance)

It's important to note that the accuracy of the support and resistance level predictions can vary greatly depending on the method used and the quality of data.

It's also important to note that support and resistance level predictions are not always accurate, so it's important to use them as part of a broader trading strategy, not as standalone predictions.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.