Python中的Gator振荡器

时间:2018-07-03 17:51:56

标签: python-3.x algorithmic-trading indicator

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

#read file
df = pd.read_csv(r'C:\Users\user\Desktop\FCPO.csv')
oprice = df['Open']
hprice = df['High']
lprice = df['Low']
cprice = df['Close']

date = df['Date']
df = df.iloc[::-1] 
df = df.reset_index()

#Calculation
def SMMA(cprice, n, m=3):
    result = np.array([np.nan]*len(cprice))
    result[n-2] = cprice[:n-1].mean()
    for i in range(n-1, len(cprice)):
        result[i] = (result[i-1]*(n-2)+2*cprice[i])/n
    return result

medianprice = (hprice/2) + (lprice/2)
jaw   = SMMA(medianprice,13,8)
teeth = SMMA(medianprice,8 ,5)
lips  = SMMA(medianprice,5 ,3) 

#plot graph
date = df['Date']
fig = plt.figure(figsize=(7,5))

ax = fig.add_subplot(2, 1, 1)
ax.set_xticklabels([])
plt.plot(cprice,lw=1)
plt.title('FCPO Close Price')
plt.ylabel('Stock price')
plt.xlabel('Date')
plt.grid(True)

bx = fig.add_subplot(2, 1, 2)
plt.plot(jaw,'b',lw=0.75,linestyle='-',label='GATOR JAW')
plt.plot(teeth,'r',lw=0.75,linestyle='-',label='GATOR TEETH')
plt.plot(lips,'g',lw=0.75,linestyle='-',label='GATOR LIPS')
plt.legend(loc=2,prop={'size':9.5})
plt.grid(True)
plt.show()

有人可以向我展示如何在python中运行Gator振荡器吗?我是python的新手,有点卡在这里。我认为我的计算部分不足以运行gator振荡器,但我不知道从哪里开始。计算完下巴,牙齿和嘴唇后,应该有一些方程式来显示直方图,例如

topbar = abs(颚-牙齿)

bottombar = -abs(牙齿-嘴唇)

请告知。

0 个答案:

没有答案