From c6a1da244900bcb6c1bd93c3a74bfde4740d6efb Mon Sep 17 00:00:00 2001 From: aszerW Date: Sun, 19 Oct 2025 13:14:30 +0800 Subject: [PATCH] =?UTF-8?q?MACD=E6=9F=B1=E7=8A=B6=E5=9B=BE=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E9=80=BB=E8=BE=91=EF=BC=9A=E9=9B=B6=E8=BD=B4=E4=B8=8A?= =?UTF-8?q?=E6=96=B9=E7=94=A8=E7=BA=A2=E8=89=B2=EF=BC=88=E4=B8=8A=E6=B6=A8?= =?UTF-8?q?=E5=AE=9E=E5=BF=83=E3=80=81=E4=B8=8B=E8=B7=8C=E7=A9=BA=E5=BF=83?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E9=9B=B6=E8=BD=B4=E4=B8=8B=E6=96=B9=E7=94=A8?= =?UTF-8?q?=E7=BB=BF=E8=89=B2=EF=BC=88=E4=B8=8B=E8=B7=8C=E5=AE=9E=E5=BF=83?= =?UTF-8?q?=E3=80=81=E4=B8=8A=E6=B6=A8=E7=A9=BA=E5=BF=83=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/chart.py b/chart.py index 150b74d..4e6ab58 100644 --- a/chart.py +++ b/chart.py @@ -224,9 +224,18 @@ class QuantChart: histogram = macd_chart.create_histogram(name=macd_name) hist_data = df[["time", macd_name]].copy() - hist_data["color"] = hist_data[macd_name].apply( - lambda x: "#00FF00" if x < 0 else "#ff0000" # 绿色 : 红色 - ) + hist_data['prev_value'] = hist_data[macd_name].shift(1) + # 设置颜色逻辑 + def get_histogram_color(row): + current, prev = row[macd_name], row['prev_value'] + is_hollow = (current >= 0 and current < prev) or (current < 0 and current > prev) + if current >= 0: + return "rgba(255, 0, 0, 0.3)" if is_hollow else "#ff0000" + else: + return "rgba(0, 255, 0, 0.3)" if is_hollow else "#00FF00" + hist_data["color"] = hist_data.apply(get_histogram_color, axis=1) + hist_data = hist_data.drop('prev_value', axis=1) + histogram.set(hist_data) macd_line = macd_chart.create_line(