diff --git a/stock_market_cli.py b/stock_market_cli.py index fc4f1ebef0c..9f5ad7a5161 100644 --- a/stock_market_cli.py +++ b/stock_market_cli.py @@ -65,11 +65,12 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open): print(" sma simple moving average") print(" ema exponential moving average") print(" macd moving average convergence/divergence") - if s_interval != "1440min": - print(" vwap volume weighted average price") print(" stoch stochastic oscillator") print(" rsi relative strength index") print(" adx average directional movement index") + print(" cci commodity channel index") + if s_interval != "1440min": + print(" vwap volume weighted average price") print("\nPrediction:") print(" ma") @@ -114,7 +115,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', 'adx', - 'ratings']) + 'cci', 'ratings']) # Print first welcome message and help print("\nWelcome to Didier's Stock Market Bot\n") @@ -217,6 +218,11 @@ def main(): smta.adx(l_args, s_ticker, s_interval, df_stock) continue + # ---------------------------------------------------- CCI ---------------------------------------------------- + elif ns_known_args.cmd == 'cci': + smta.cci(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 c3c57c29ae9..1e13df3f3f6 100644 --- a/stock_market_technical_analysis.py +++ b/stock_market_technical_analysis.py @@ -265,3 +265,38 @@ def adx(l_args, s_ticker, s_interval, df_stock): return +# ----------------------------------------------------- CCI ----------------------------------------------------- +def cci(l_args, s_ticker, s_interval, df_stock): + parser = argparse.ArgumentParser(prog='cci', + description=""" The CCI is designed to detect beginning and ending market trends. + The range of 100 to -100 is the normal trading range. CCI values outside of this + range indicate overbought or oversold conditions. You can also look for price + divergence in the CCI. If the price is making new highs, and the CCI is not, + then a price correction is likely. """) + + 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.cci(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.cci(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} CCI") + except: + print("") + return \ No newline at end of file