关于rsi底背离内容导航:
1、rsi底背离
:param df:
:param n:
:return:
'''
df = df.sort_index(ascending=False)
i = 0
TREND_UP, TREND_DOWN = 1, 2
trend = TREND_UP
while i < df.shape[0]:
if trend == TREND_UP:
if df.iloc[i]['close'] < df.iloc[i]['rsi']:
if df.iloc[i-1]['close'] > df.iloc[i-1]['rsi']:
return True
else:
trend = TREND_DOWN
elif trend == TREND_DOWN:
if df.iloc[i]['close'] > df.iloc[i]['rsi']:
if df.iloc[i-1]['close'] < df.iloc[i-1]['rsi']:
return True
else:
trend = TREND_UP
i += 1
return False
def rsi_top_divergence(df, n):
'''
判断rsi顶背离
:param df:
:param n:
:return:
'''
df = df.sort_index(ascending=False)
i = 0
TREND_UP, TREND_DOWN = 1, 2
trend = TREND_DOWN
while i < df.shape[0]:
if trend == TREND_UP:
if df.iloc[i]['close'] < df.iloc[i]['rsi']:
if df.iloc[i-1]['close'] > df.iloc[i-1]['rsi']:
return True
else:
trend = TREND_DOWN
elif trend == TREND_DOWN:
if df.iloc[i]['close'] > df.iloc[i]['rsi']:
if df.iloc[i-1]['close'] < df.iloc[i-1]['rsi']:
return True
else:
trend = TREND_UP
i += 1
return False
def macd_bottom_divergence(df, n):
'''
判断macd底背离
:param df:
:param n:
:return:
'''
df = df.sort_index(ascending=False)
i = 0
TREND_UP, TREND_DOWN = 1, 2
trend = TREND_UP
while i < df.shape[0]:
if trend == TREND_UP:
if df.iloc[i]['close'] < df.iloc[i]['macd']:
if df.iloc[i-1]['close'] > df.iloc[i-1]['macd']:
return True
else:
trend = TREND_DOWN
elif trend == TREND_DOWN:
if df.iloc[i]['close'] > df.iloc[i]['macd']:
if df.iloc[i-1]['close'] < df.iloc[i-1]['macd']:
return True
else:
trend = TREND_UP
i += 1
return False
def macd_top_divergence(df, n):
'''
判断macd顶背离
:param df:
:param n:
:return:
'''
df = df.sort_index(ascending=False)
i = 0
TREND_UP, TREND_DOWN = 1, 2
trend = TREND_DOWN
while i < df.shape[0]:
if trend == TREND_UP:
if df.iloc[i]['close'] < df.iloc[i]['macd']:
if df.iloc[i-1]['close'] > df.iloc[i-1]['macd']:
return True
else:
trend = TREND_DOWN
elif trend == TREND_DOWN:
if df.iloc[i]['close'] > df.iloc[i]['macd']:
if df.iloc[i-1]['close'] < df.iloc[i-1]['macd']:
return True
else:
trend = TREND_UP
i += 1
return False
def kdj_bottom_divergence(df, n):
'''
判断kdj底背离
:param df:
:param n:
:return:
'''
df = df.sort_index(ascending=False)
i = 0
TREND_UP, TREND_DOWN = 1, 2
trend = TREND_UP
while i < df.shape[0]:
if trend == TREND_UP:
if df.iloc[i]['close'] < df.iloc[i]['kdj_k']:
if df.iloc[i-1]['close'] > df.iloc[i-1]['kdj_k']:
return True
else:
trend = TREND_DOWN
elif trend == TREND_DOWN:
if df.iloc[i]['close'] > df.iloc[i]['kdj_k']:
if df.iloc[i-1]['close'] < df.iloc[i-1]['kdj_k']:
return True
else:
trend = TREND_UP
i += 1
return False
def kdj_top_divergence(df, n):
'''
判断kdj顶背离
:param df:
:param n:
:return:
'''
df = df.sort_index(ascending=False)
i = 0
TREND_UP, TREND_DOWN = 1, 2
trend = TREND_DOWN
while i < df.shape[0]:
if trend == TREND_UP:
if df.iloc[i]['close'] < df.iloc[i]['kdj_k']:
if df.iloc[i-1]['close'] > df.iloc[i-1]['kdj_k']:
return True
else:
trend = TREND_DOWN
elif trend == TREND_DOWN:
if df.iloc[i]['close'] > df.iloc[i]['kdj_k']:
if df.iloc[i-1]['close'] < df.iloc[i-1]['kdj_k']:
return True
else:
trend = TREND_UP
i += 1
return False
def boll_bottom_divergence(df, n):
'''
判断boll底背离
:param df:
:param n:
:return:
'''
df = df.sort_index(ascending=False)
i = 0
TREND_UP, TREND_DOWN = 1, 2
trend = TREND_UP
while i < df.shape[0]:
if trend == TREND_UP:
if df.iloc[i]['close'] < df.iloc[i]['boll_mid']:
if df.iloc[i-1]['close'] > df.iloc[i-1]['boll_mid']:
return True
else:
trend = TREND_DOWN
elif trend == TREND_DOWN:
if df.iloc[i]['close'] > df.iloc[i]['boll_mid']:
if df.iloc[i-1]['close'] < df.iloc[i-1]['boll_mid']:
return True
else:
trend = TREND_UP
i += 1
return False
def boll_top_divergence(df, n):
'''
判断boll顶背离
:param df:
:param n:
:return:
'''
df =