# How to compute the support and resistance in Python

1 min

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.