python
import pandas as pd
import numpy as np
import yfinance as yf
import matplotlib.pyplot as plt

# Получаем исторические данные о цене актива
ticker = 'AAPL' # здесь указываем тикер актива
data = yf.download(ticker, start='2021-01-01', end='2021-12-31')

# Рассчитываем скользящие средние
data = data.rolling(window=50).mean()
data = data.rolling(window=200).mean()

# Определяем точки входа
data = 0
data[data > data] = 1 # долгосрочное пересечение
data[data < data] = -1 # короткосрочное пересечение

# Визуализируем точки входа
plt.figure(figsize=(12, 6))
plt.plot(data, label='Цена закрытия', alpha=0.7)
plt.plot(data, label='SMA 50', linestyle='--', alpha=0.7)
plt.plot(data, label='SMA 200', linestyle='--', alpha=0.7)
plt.plot(data[data == 1].index, data[data == 1], '^', markersize=10, color='g', label='Покупка')
plt.plot(data[data == -1].index, data[data == -1], 'v', markersize=10, color='r', label='Продажа')
plt.title(f'Точки входа на {ticker}')
plt.legend()
plt.show()
Disclaimer

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.