diff --git a/stock_market_cli.py b/stock_market_cli.py index 55cc6e166a2..fc4f1ebef0c 100644 --- a/stock_market_cli.py +++ b/stock_market_cli.py @@ -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 -------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- diff --git a/stock_market_technical_analysis.py b/stock_market_technical_analysis.py index 5097089b510..c3c57c29ae9 100644 --- a/stock_market_technical_analysis.py +++ b/stock_market_technical_analysis.py @@ -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 \ No newline at end of file + 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 + +