关于一根均线指标的问题,我们总结了以下几点,给你解答:
一根均线炒股
均线是大家一段时间内持股的平均成本,对股价起到支撑与压制的作用,常用5日,10日,30日,60日等
一根均线指标
def get_ma(self, df, n):
"""
:param df:
:param n:
:return:
"""
ma_name = 'MA_' + str(n)
df[ma_name] = df['close'].rolling(n).mean()
return df
# 计算指定区间内的最大值
def get_max(self, df, n):
"""
:param df:
:param n:
:return:
"""
max_name = 'MAX_' + str(n)
df[max_name] = df['close'].rolling(n).max()
return df
# 计算指定区间内的最小值
def get_min(self, df, n):
"""
:param df:
:param n:
:return:
"""
min_name = 'MIN_' + str(n)
df[min_name] = df['close'].rolling(n).min()
return df
# 计算指定区间内的均值
def get_mean(self, df, n):
"""
:param df:
:param n:
:return:
"""
mean_name = 'MEAN_' + str(n)
df[mean_name] = df['close'].rolling(n).mean()
return df
# 计算指定区间内的标准差
def get_std(self, df, n):
"""
:param df:
:param n:
:return:
"""
std_name = 'STD_' + str(n)
df[std_name] = df['close'].rolling(n).std()
return df
# 计算指定区间内的变异系数
def get_var(self, df, n):
"""
:param df:
:param n:
:return:
"""
var_name = 'VAR_' + str(n)
df[var_name] = df['close'].rolling(n).var()
return df
# 计算指定区间内的偏度
def get_skew(self, df, n):
"""
:param df:
:param n:
:return:
"""
skew_name = 'SKEW_' + str(n)
df[skew_name] = df['close'].rolling(n).skew()
return df
# 计算指定区间内的峰度
def get_kurt(self, df, n):
"""
:param df:
:param n:
:return:
"""
kurt_name = 'KURT_' + str(n)
df[kurt_name] = df['close'].rolling(n).kurt()
return df
# 计算指定区间内的RSI
def get_rsi(self, df, n):
"""
:param df:
:param n:
:return:
"""
rsi_name = 'RSI_' + str(n)
df[rsi_name] = talib.RSI(df['close'].values, n)
return df
# 计算指定区间内的MACD
def get_macd(self, df, n_fast, n_slow):
"""
:param df:
:param n_fast:
:param n_slow:
:return:
"""
macd_name = 'MACD_' + str(n_fast) + '_' + str(n_slow)
df[macd_name] = talib.MACD(df['close'].values, n_fast, n_slow)[0]
return df
# 计算指定区间内的KDJ
def get_kdj(self, df, n):
"""
:param df:
:param n:
:return:
"""
kdj_name = 'KDJ_' + str(n)
df[kdj_name + '_K'], df[kdj_name + '_D'], df[kdj_name + '_J'] = talib.STOCH(df['high'].values,
df['low'].values,
df['close'].values,
fastk_period=n,
slowk_period=3,
slowd_period=3)
return df
# 计算指定区间内的CCI
def get_cci(self, df, n):
"""
:param df:
:param n:
:return:
"""
cci_name = 'CCI_' + str(n)
df[cci_name] = talib.CCI(df['high'].values, df['low'].values, df['close'].values, timeperiod=n)
return df
# 计算指定区间内的ATR
def get_atr(self, df, n):
"""
:param df:
:param n:
:return:
"""
atr_name = 'ATR_' + str(n)
df[atr_name] = talib.ATR(df['high'].values, df['low'].values, df['close'].values, timeperiod=n)
return df
# 计算指定区间内的BOLL
def get_boll(self, df, n):
"""
:param df:
:param n:
:return:
"""
boll_name = 'BOLL_' + str(n)
df[boll_name + '_UP'], df[boll_name + '_MB'], df[boll_name + '_DN'] = talib.BBANDS(df['close'].values,
timeperiod=n,
nbdevup=2,
nbdevdn=2,
matype=0)
return df
# 计算指定区间内的DMI
def get_dmi(self, df, n):
"""
:param df:
:param n:
:return:
"""
dmi_name = 'DMI_' + str(n)
df[dmi_name + '_PDI'], df[dmi_name + '_MDI'], df[dmi_name + '_ADX'], df[dmi_name + '_ADXR'] = talib.ADX(
df['high'].values,
df['low'].values,
df['close'].values,
timeperiod=n)
return df
# 计算指定区间内的WR
def get_wr(self, df, n):
"""
:param df:
:param n:
:return:
"""
wr_name = 'WR_' + str(n)
df[wr_name] = talib.WILLR(df['high'].values, df['low'].values, df['close'].values, timeperiod=n)
return df
# 计算指定区间内的SAR
def get_sar(self, df, n):
"""
:param df:
:param n:
:return:
"""
sar_name = 'SAR_'
一根均线指标公式
MACD>0 并且K>D时,续让损坏均线显示MA5+2;
MACD<=0 并且K>D时,均线显示MA5;
MACD>0 义资并且K<=D时,均线显示MA5;
MACD<=0 并且K<=D时,均线显示MA5-2;
要想画出这么一根指标线,该怎么写程序语句?请哪位高手给予指