From 6e026282d24f89447f01cb8ac8e09e4af5eb015c Mon Sep 17 00:00:00 2001 From: zengbin93 Date: Thu, 8 Feb 2024 21:32:16 +0800 Subject: [PATCH] =?UTF-8?q?0.9.42=20add=5Fmacd=20=E4=BC=98=E5=85=88?= =?UTF-8?q?=E6=8C=89=E8=AE=A1=E7=AE=97=E5=A5=BD=E7=9A=84=E5=80=BC=E7=BB=98?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- czsc/utils/plotly_plot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/czsc/utils/plotly_plot.py b/czsc/utils/plotly_plot.py index c46bf93cc..39d33ee1d 100644 --- a/czsc/utils/plotly_plot.py +++ b/czsc/utils/plotly_plot.py @@ -182,7 +182,12 @@ def add_macd(self, kline: pd.DataFrame, row=3, **kwargs): slowperiod = kwargs.get('slowperiod', 26) signalperiod = kwargs.get('signalperiod', 9) line_width = kwargs.get('line_width', 0.6) - diff, dea, macd = MACD(df["close"], fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod) + + if 'DIFF' in df.columns and 'DEA' in df.columns and 'MACD' in df.columns: + diff, dea, macd = df['DIFF'], df['DEA'], df['MACD'] + else: + diff, dea, macd = MACD(df["close"], fastperiod=fastperiod, slowperiod=slowperiod, signalperiod=signalperiod) + macd_colors = np.where(macd > 0, self.color_red, self.color_green) self.add_scatter_indicator(df['dt'], diff, name="DIFF", row=row, line_color='white', show_legend=False, line_width=line_width)