Add adx to technical analysis

This commit is contained in:
didier
2020-12-26 18:35:00 +00:00
parent d1f5d28a98
commit 5c6676a707
2 changed files with 46 additions and 2 deletions

View File

@@ -69,6 +69,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open):
print(" vwap volume weighted average price")
print(" stoch stochastic oscillator")
print(" rsi relative strength index")
print(" adx average directional movement index")
print("\nPrediction:")
print(" ma")
@@ -112,7 +113,7 @@ def main():
# Add list of arguments that the main parser accepts
main_parser.add_argument('cmd', choices=['quit', 'help', 'gainers' ,'view', 'load', 'clear',
'sma', 'ema', 'macd', 'vwap', 'stoch', 'rsi',
'sma', 'ema', 'macd', 'vwap', 'stoch', 'rsi', 'adx',
'ratings'])
# Print first welcome message and help
@@ -211,6 +212,11 @@ def main():
smta.rsi(l_args, s_ticker, s_interval, df_stock)
continue
# ---------------------------------------------------- ADX ----------------------------------------------------
elif ns_known_args.cmd == 'adx':
smta.adx(l_args, s_ticker, s_interval, df_stock)
continue
# --------------------------------------------------------------------------------------------------------------
# ------------------------------------------------ PREDICTION --------------------------------------------------
# --------------------------------------------------------------------------------------------------------------

View File

@@ -226,4 +226,42 @@ def rsi(l_args, s_ticker, s_interval, df_stock):
plot_ta(s_ticker, df_ta, f"{ns_parser.n_timeperiod} RSI")
except:
print("")
return
return
# ----------------------------------------------------- ADX -----------------------------------------------------
def adx(l_args, s_ticker, s_interval, df_stock):
parser = argparse.ArgumentParser(prog='adx',
description=""" The ADX is a Welles Wilder style moving average of the Directional
Movement Index (DX). The values range from 0 to 100, but rarely get above 60.
To interpret the ADX, consider a high number to be a strong trend, and a low number,
a weak trend. """)
parser.add_argument('-p', "--timeperiod", action="store", dest="n_timeperiod", type=check_positive, default=60,
help='Number of data points used to calculate each ADX value')
try:
(ns_parser, l_unknown_args) = parser.parse_known_args(l_args)
except SystemExit:
print("")
return
if l_unknown_args:
print(f"The following args couldn't be interpreted: {l_unknown_args}")
try:
# Daily
if s_interval == "1440min":
df_ta = ta.adx(high=df_stock['2. high'], low=df_stock['3. low'],
close=df_stock['5. adjusted close'], time_period=ns_parser.n_timeperiod).dropna()
# Intraday
else:
df_ta = ta.adx(high=df_stock['2. high'], low=df_stock['3. low'],
close=df_stock['4. close'], time_period=ns_parser.n_timeperiod).dropna()
plot_ta(s_ticker, df_ta, f"{ns_parser.n_timeperiod} ADX")
except:
print("")
return