import logging import plotly.graph_objects as go from bots import imps, load_candle from openbb_terminal.common.technical_analysis import volume_model from openbb_terminal.decorators import log_start_end # pylint: disable=R0913 logger = logging.getLogger(__name__) @log_start_end(log=logger) def adosc_command( ticker="", interval: int = 15, past_days: int = 0, is_open: bool = False, fast="3", slow="10", start="", end="", extended_hours: bool = False, heikin_candles: bool = False, trendline: bool = False, news: bool = False, ): """Displays chart with chaikin oscillator [Yahoo Finance]""" # Debug if imps.DEBUG: # pylint: disable=logging-too-many-args logger.debug( "ta adosc %s %s %s %s %s %s %s %s %s %s %s %s", ticker, interval, past_days, is_open, fast, slow, start, end, extended_hours, heikin_candles, trendline, news, ) # Check for argument if ticker == "": raise Exception("Stock ticker is required") if not fast.lstrip("-").isnumeric(): raise Exception("Number has to be an integer") fast = int(fast) if not slow.lstrip("-").isnumeric(): raise Exception("Number has to be an integer") slow = int(slow) # Retrieve Data df_stock, start, end, bar_start = load_candle.stock_data( ticker=ticker, interval=interval, past_days=past_days, extended_hours=extended_hours, start=start, end=end, heikin_candles=heikin_candles, ) if df_stock.empty: raise Exception("No Data Found") df_ta = df_stock.loc[(df_stock.index >= start) & (df_stock.index < end)] df_ta = df_ta.join(volume_model.adosc(df_stock, is_open, fast, slow)) # Output Data if interval != 1440: df_ta = df_ta.loc[(df_ta.index >= bar_start) & (df_ta.index < end)] df_ta = df_ta.fillna(0.0) plot = load_candle.candle_fig( df_ta, ticker, interval, extended_hours, news, bar=bar_start, int_bar=interval, trendline=trendline, rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.05, row_width=[0.4, 0.7], specs=[ [{"secondary_y": True}], [{"secondary_y": False}], ], ) title = f"{plot['plt_title']} AD Oscillator" fig = plot["fig"] fig.add_trace( go.Scatter( name="AD Osc [M]", mode="lines", x=df_ta.index, y=df_ta.iloc[:, 6].values if (not trendline) and (interval != 1440) else df_ta.iloc[:, 11].values, line=dict(width=2), opacity=1, ), row=2, col=1, ) fig.update_layout( margin=dict(l=0, r=0, t=50, b=20), template=imps.PLT_TA_STYLE_TEMPLATE, colorway=imps.PLT_TA_COLORWAY, title=title, title_x=0.1, title_font_size=14, dragmode="pan", ) imagefile = "ta_adosc.png" # Check if interactive settings are enabled plt_link = "" if imps.INTERACTIVE: plt_link = imps.inter_chart(fig, imagefile, callback=False) imagefile = imps.image_border(imagefile, fig=fig) return { "title": f"Stocks: Accumulation/Distribution Oscillator {ticker.upper()}", "description": plt_link, "imagefile": imagefile, }