diff options
Diffstat (limited to 'openbb_terminal/core/plots/plotly_ta/plugins/custom_indicators_plugin.py')
-rw-r--r-- | openbb_terminal/core/plots/plotly_ta/plugins/custom_indicators_plugin.py | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/openbb_terminal/core/plots/plotly_ta/plugins/custom_indicators_plugin.py b/openbb_terminal/core/plots/plotly_ta/plugins/custom_indicators_plugin.py index c32fb7921c1..5b01ac0ecbf 100644 --- a/openbb_terminal/core/plots/plotly_ta/plugins/custom_indicators_plugin.py +++ b/openbb_terminal/core/plots/plotly_ta/plugins/custom_indicators_plugin.py @@ -41,10 +41,12 @@ class Custom(PltTA): cond4 = df["High"][i - 1] > df["High"][i - 2] return cond1 and cond2 and cond3 and cond4 - df_ta2 = df_ta.copy().loc[ - (df_ta.index >= datetime.now() - timedelta(days=window)) - & (df_ta.index < datetime.now()) - ] + df_ta2 = df_ta.copy() + today = pd.to_datetime(datetime.now(), unit="ns") + start_date = pd.to_datetime(datetime.now() - timedelta(days=window), unit="ns") + + df_ta2 = df_ta2.loc[(df_ta2.index >= start_date) & (df_ta2.index < today)] + if df_ta2.index[-2].date() != df_ta2.index[-1].date(): interval = 1440 else: @@ -54,78 +56,69 @@ class Custom(PltTA): cut_days = 1 if interval < 15 else 2 dt_unique_days = df_ta2.index.normalize().unique() df_ta2 = df_ta2.loc[ - (df_ta.index >= dt_unique_days[-cut_days]) - & (df_ta.index < datetime.now()) + (df_ta2.index >= pd.to_datetime(dt_unique_days[-cut_days], unit="ns")) + & (df_ta2.index < today) ].copy() levels: list = [] - x_range = ( - df_ta2.index[-1].replace(hour=17, minute=45) - if interval < 15 - else df_ta2.index[-1].replace(hour=15, minute=45) - ) + x_range = df_ta2.index[-1].replace(hour=15, minute=59) if interval > 15: x_range = df_ta2.index[-1] + timedelta(days=15) if x_range.weekday() > 4: x_range = x_range + timedelta(days=7 - x_range.weekday()) + elif df_ta2.index[-1] >= today.replace(hour=15, minute=0): + x_range = (df_ta2.index[-1] + timedelta(days=1)).replace(hour=11, minute=0) + if x_range.weekday() > 4: + x_range = x_range + timedelta(days=7 - x_range.weekday()) + for i in range(2, len(df_ta2) - 2): if is_support(df_ta2, i): lv = df_ta2["Low"][i] if is_far_from_level(lv, levels, df_ta2): levels.append((i, lv)) fig.add_scatter( - x=[x_range], - y=[lv], + x=[df_ta.index[0], x_range], + y=[lv, lv], opacity=1, - mode="text", - text=f"{lv:{self.get_float_precision()}}", - textposition="top left", + mode="lines+text", + text=["", f"{lv:{self.get_float_precision()}}"], + textposition="top center", textfont=dict( - family="Arial Black", color="rgb(120, 70, 200)", size=12 + family="Arial Black", color="rgb(120, 70, 200)", size=10 + ), + line=dict( + width=2, dash="dash", color="rgba(120, 70, 200, 0.70)" ), + connectgaps=True, showlegend=False, row=1, col=1, secondary_y=self.show_volume, ) - fig.add_hline( - y=lv, - line_width=2, - line_dash="dash", - line_color="rgba(120, 70, 200, 0.70)", - row=1, - col=1, - secondary_y=self.show_volume, - ) elif is_resistance(df_ta2, i): lv = df_ta2["High"][i] if is_far_from_level(lv, levels, df_ta2): levels.append((i, lv)) fig.add_scatter( - x=[x_range], - y=[lv], + x=[df_ta.index[0], x_range], + y=[lv, lv], opacity=1, - mode="text", - text=f"{lv:{self.get_float_precision()}}", - textposition="top left", + mode="lines+text", + text=["", f"{lv:{self.get_float_precision()}}"], + textposition="top center", textfont=dict( - family="Arial Black", color="rgb(120, 70, 200)", size=12 + family="Arial Black", color="rgb(120, 70, 200)", size=10 + ), + line=dict( + width=2, dash="dash", color="rgba(120, 70, 200, 0.70)" ), + connectgaps=True, showlegend=False, row=1, col=1, secondary_y=self.show_volume, ) - fig.add_hline( - y=lv, - line_width=2, - line_dash="dash", - line_color="rgba(120, 70, 200, 0.70)", - row=1, - col=1, - secondary_y=self.show_volume, - ) return fig |