简单移动平均线交叉

时间:2021-01-08 13:34:43

标签: python moving-average algorithmic-trading trading

我想找出简单移动平均线的价值等于股票价格的日子。这是我的尝试:

from yahoo_fin.stock_info import *
import matplotlib.pyplot as plt

ticker = 'NFLX'

price = get_data(ticker, start_date='2019-01-01', end_date=None, index_as_date=bool, interval ='1d')
price.to_csv(r'D:\Python Stuff\pythonProject\NFLX.csv')

price_list = price['adjclose']

days = 14

simple_moving_average = price_list.rolling(window=days).mean()

combined = pd.DataFrame()
combined['adjclose'] = price['adjclose']
combined['SMA'] = simple_moving_average

#print(price_list[-days:]) #Shows last n days of the list

if simple_moving_average[-1] == price_list[-1] and simple_moving_average[-5] >price_list[-5]:
    print('time to buy')

如何改进我的代码以完成必要的工作

0 个答案:

没有答案