Untitled
import numpy as np import pandas as pd import matplotlib.pyplot as plt # Example data: Replace with your data data = { 'Date': pd.date_range(start='2023-12-01', periods=30), 'Close': [100, 102, 101, 103, 105, 106, 107, 105, 104, 103, 102, 101, 100, 99, 98, 100, 102, 101, 99, 97, 96, 95, 94, 95, 96, 97, 98, 99, 100, 101] } df = pd.DataFrame(data) # Calculate support and resistance levels def calculate_levels(prices): resistance = prices.max() support = prices.min() return support, resistance support, resistance = calculate_levels(df['Close']) # Plot the data plt.figure(figsize=(12, 6)) plt.plot(df['Date'], df['Close'], label='Close Prices', color='blue', marker='o') # Plot support and resistance lines plt.axhline(y=support, color='green', linestyle='--', label=f'Support: {support}') plt.axhline(y=resistance, color='red', linestyle='--', label=f'Resistance: {resistance}') # Add labels and title plt.title('Support and Resistance Levels') plt.xlabel('Date') plt.ylabel('Price') plt.legend() plt.grid() # Show the graph plt.show()
Leave a Comment