MACD柱状图颜色逻辑:零轴上方用红色(上涨实心、下跌空心),零轴下方用绿色(下跌实心、上涨空心)。
This commit is contained in:
15
chart.py
15
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(
|
||||
|
||||
Reference in New Issue
Block a user