macd展示period;柱子的值保留两位小数

This commit is contained in:
2025-10-19 10:28:44 +08:00
parent 9f8c51600e
commit dad77f139e

View File

@@ -91,7 +91,8 @@ def add_macd(
) )
df["DIF"] = macd df["DIF"] = macd
df["DEA"] = signal df["DEA"] = signal
df["MACD"] = hist * 2 macd_name = f"MACD_{fastperiod}_{slowperiod}_{signalperiod}"
df[macd_name] = np.round(hist * 2, 2)
macd_chart = chart.create_subchart( macd_chart = chart.create_subchart(
position=position, width=1, height=height, sync=True position=position, width=1, height=height, sync=True
) )
@@ -100,9 +101,9 @@ def add_macd(
) )
macd_chart.time_scale(visible=False) macd_chart.time_scale(visible=False)
histogram = macd_chart.create_histogram(name="MACD") histogram = macd_chart.create_histogram(name=macd_name)
hist_data = df[["time", "MACD"]].copy() hist_data = df[["time", macd_name]].copy()
hist_data["color"] = hist_data["MACD"].apply( hist_data["color"] = hist_data[macd_name].apply(
lambda x: "#00FF00" if x < 0 else "#ff0000" # 绿色 : 红色 lambda x: "#00FF00" if x < 0 else "#ff0000" # 绿色 : 红色
) )
histogram.set(hist_data) histogram.set(hist_data)