k线dmi指标-k线图dmi

2023-03-06 21:09:17 技术指标 0次阅读 投稿:admin

关于k线dmi指标内容导航:

1、k线dmi指标


:param df:
:return:
'''
df['MTR'] = df['high'] - df['low']
df['PDM'] = df['high'] - df['high'].shift(1)
df['MDM'] = df['low'].shift(1) - df['low']
df['PDM'][df['PDM'] < 0] = 0
df['MDM'][df['MDM'] < 0] = 0
df['TR'] = df[['MTR', 'PDM', 'MDM']].max(axis=1)
df['PDI'] = df['PDM'].rolling(n).sum() / df['TR'].rolling(n).sum() * 100
df['MDI'] = df['MDM'].rolling(n).sum() / df['TR'].rolling(n).sum() * 100
df['DMI'] = abs(df['PDI'] - df['MDI']) / (df['PDI'] + df['MDI']) * 100
df['ADX'] = df['DMI'].rolling(m).mean()
df['ADXR'] = df['ADX'].rolling(m).mean()
return df


def macd(df, n_fast=12, n_slow=26):
'''
macd指标
:param df:
:param n_fast:
:param n_slow:
:return:
'''
EMAfast = pd.Series(df['close'].ewm(span=n_fast, min_periods=n_slow).mean())
EMAslow = pd.Series(df['close'].ewm(span=n_slow, min_periods=n_slow).mean())
df['diff'] = EMAfast - EMAslow
df['dea'] = pd.Series(df['diff'].ewm(span=9, min_periods=9).mean())
df['macd'] = 2 * (df['diff'] - df['dea'])
return df


def kdj(df, n=9, m1=3, m2=3):
'''
kdj指标
:param df:
:param n:
:param m1:
:param m2:
:return:
'''
low_list = df['low'].rolling(n).min()
low_list.fillna(value=df['low'].expanding().min(), inplace=True)
high_list = df['high'].rolling(n).max()
high_list.fillna(value=df['high'].expanding().max(), inplace=True)
rsv = (df['close'] - low_list) / (high_list - low_list) * 100
df['K'] = pd.Series(rsv).ewm(com=m1).mean()
df['D'] = pd.Series(df['K']).ewm(com=m2).mean()
df['J'] = 3 * df['K'] - 2 * df['D']
return df


def boll(df, n=20, m=2):
'''
boll指标
:param df:
:param n:
:param m:
:return:
'''
df['MA'] = df['close'].rolling(n).mean()
df['MD'] = df['close'].rolling(n).std()
df['UP'] = df['MA'] + m * df['MD']
df['DN'] = df['MA'] - m * df['MD']
return df


def rsi(df, n=14):
'''
rsi指标
:param df:
:param n:
:return:
'''
df['diff'] = df['close'].diff()
df['up'] = df['diff'][df['diff'] > 0].fillna(0)
df['down'] = -df['diff'][df['diff'] < 0].fillna(0)
df['AU'] = df['up'].rolling(n).mean()
df['AD'] = df['down'].rolling(n).mean()
df['RSI'] = df['AU'] / (df['AU'] + df['AD']) * 100
return df


def obv(df):
'''
obv指标
:param df:
:return:
'''
df['diff'] = df['close'].diff()
df['obv'] = df['diff'].apply(lambda x: -x if x < 0 else x)
df['obv'] = df['obv'].cumsum()
return df


def cci(df, n=14):
'''
cci指标
:param df:
:param n:
:return:
'''
df['TP'] = (df['high'] + df['low'] + df['close']) / 3
df['MA'] = df['TP'].rolling(n).mean()
df['MD'] = df['TP'].rolling(n).std()
df['CCI'] = (df['TP'] - df['MA']) / (0.015 * df['MD'])
return df


def wr(df, n=14):
'''
wr指标
:param df:
:param n:
:return:
'''
df['HH'] = df['high'].rolling(n).max()
df['LL'] = df['low'].rolling(n).min()
df['WR'] = (df['HH'] - df['close']) / (df['HH'] - df['LL']) * 100
return df


def sar(df, n=4, step=0.02, max_step=0.2):
'''
sar指标
:param df:
:param n:
:param step:
:param max_step:
:return:
'''
df['sar'] = df['low'].shift(1)
df['up'] = 0
df['down'] = 0
df['ep'] = 0
df['af'] = 0
df['up'][:n] = df['high'][:n]
df['down'][:n] = df['low'][:n]
df['ep'][:n] = df['high'][:n]
df['af'][:n] = 0.02
for i in range(n, len(df)):
if df['sar'][i - 1] < df['high'][i - 1]:
df['up'][i] = max(df['high'][i], df['up'][i - 1])
df['ep'][i] = df['high'][i]
df['af'][i] = min(df['af'][i - 1] + step, max_step)
df['sar'][i] = df['sar'][i - 1] + df['af'][i] * (df['ep'][i] - df['sar'][i - 1])
elif df['sar'][i - 1] > df['low'][i - 1]:
df['down'][i] = min(df['low'][i], df['down'][i - 1])
df['ep'][i] = df['low'][i]
df['af'][i] = min(df['af'][i - 1] + step, max_step)
df['sar'][i] = df['sar'][i - 1] + df['af'][i] * (df['ep'][i] - df['sar'][i - 1])
else:
df['sar'][i] = df['sar'][i - 1]
df['ep'][i] = df['ep'][i - 1]
df['af'][i] = min(df['af'][i - 1] + step, max_step)
if df['sar'][i - 1] < df['up'][i - 1]:
df['sar'][i] = df['sar'][i - 1] + df['af'][i] * (df['

2、股票k线dmi什么意思

你可以买本日本蜡烛图看下,也可以在手机上下个炒股行情软件去学习,像我用的牛股宝模拟软件,里面对各项技术指标都有详细法控损石房机乎还说明如何运用,免费使用的,可以来自试试。
股票k线dmi什么意思

3、k线图dmi

声明:稳得一批是理财投资基础知识平台! 并不指导专业性投资! 投资有风险,入市需谨慎!