import pandas as pd import matplotlib.pyplot as plt
# Load data # For this example, we'll use a CSV file with 'Date' and 'Close' columns. # Adjust the file path as needed. data = pd.read_csv('path/to/your/data.csv')
# Convert 'Date' column to datetime data['Date'] = pd.to_datetime(data['Date'])
# Set 'Date' column as the index data.set_index('Date', inplace=True)
# Define the short-term and long-term moving averages short_window = 50 long_window = 200
# Calculate the short-term and long-term moving averages data['Short_MA'] = data['Close'].rolling(window=short_window, min_periods=1).mean() data['Long_MA'] = data['Close'].rolling(window=long_window, min_periods=1).mean()
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.