def drawDMI(ax, data, periods=[6, 14], hlines=[10, 12, 16, 20, 22]): if data.__contains__('pdi') & data.__contains__('mdi') & data.__contains__( 'adx') & data.__contains__('adxr'): pdi = data['pdi'] mdi = data['mdi'] adx = data['adx'] adxr = data['adxr'] else: close, high, low = data['close'], data['high'], data['low'] pdi, mdi = ind.DI(high, low, close, time_period=periods[0]) adx = ind.ADX(high, low, close, time_period=periods[1]) adxr = ind.ADXR(high, low, close, time_period=periods[1]) ax.plot(pdi, label='pdi%d' % periods[0]) # ax.plot(mdi, label='mdi%d' % periods[0]) # ax.plot(adx, label='adx%d' % periods[1]) # ax.plot(adxr, label='adxr%d' % periods[1]) drawHline(ax, hlines) ax.set_ylabel('DMI')
# AMZN # GOOG # .HK .SZ .HZ # 300059.sz # pdi 10~20 13~16 # mdi data = web.DataReader('300059.sz', data_source='yahoo', start='1/1/2018', end='1/30/2019') data = pd.DataFrame(data) high, low, close, volume = data['High'], data['Low'], data['Close'], data[ 'Volume'] pdi, mdi = ind.DI(high, low, close, time_period=14) adx = ind.ADX(high, low, close, time_period=6) upper_band, middle_band, lower_band = ind.BBANDS(close, time_period=20) m, s, macd_histogram = ind.MACD(close, fast_period=12, slow_period=26, signal_period=9) rsi = ind.RSI(close, time_period=14) min = ind.MIN(close, 20) max = ind.MAX(close, 50) df = pd.DataFrame() df['close'] = close df['fast'] = m df['slow'] = s df['ref'] = df['fast'].shift(1) < df['slow'].shift(1) df['now'] = df['fast'] > df['slow']