From f47dc5d647f18dc98ee8a51cd13e143baff8fff4 Mon Sep 17 00:00:00 2001 From: aszerW Date: Sat, 18 Oct 2025 22:57:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E4=BD=93=E5=92=8C?= =?UTF-8?q?=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/chart.py b/chart.py index 4a2f86b..44cf892 100644 --- a/chart.py +++ b/chart.py @@ -40,13 +40,15 @@ def add_cci(df, chart, period: int = 14, height: float = 0.1, position: str = "b cci_chart = chart.create_subchart( position=position, width=1, height=height, sync=True ) - cci_chart.legend(visible=True) + cci_chart.legend( + visible=True, font_size=14, color="#FFFFFF", font_family="Times New Roman" + ) cci_chart.time_scale(visible=False) - cci_line = cci_chart.create_line(name="cci", color="#FF5722", width=2) + cci_line = cci_chart.create_line(name="cci", color="#FF0000", width=2) cci_line.set(df[["time", "cci"]]) -def add_macd(df, chart, height: float = 0.2, position: str = "bottom"): +def add_macd(df, chart, height: float = 0.1, position: str = "bottom"): macd, signal, hist = ta.MACD( df["close"], fastperiod=12, slowperiod=26, signalperiod=9 ) @@ -56,19 +58,21 @@ def add_macd(df, chart, height: float = 0.2, position: str = "bottom"): macd_chart = chart.create_subchart( position=position, width=1, height=height, sync=True ) - macd_chart.legend(visible=True) + macd_chart.legend( + visible=True, font_size=14, color="#FFFFFF", font_family="Times New Roman" + ) macd_chart.time_scale(visible=False) histogram = macd_chart.create_histogram(name="histogram") hist_data = df[["time", "histogram"]].copy() hist_data["color"] = hist_data["histogram"].apply( - lambda x: "#26a69a" if x < 0 else "#ef5350" # 绿色 : 红色 + lambda x: "#00FF00" if x < 0 else "#ff0000" # 绿色 : 红色 ) histogram.set(hist_data) macd_line = macd_chart.create_line(name="macd", color="#2962FF", width=2) macd_line.set(df[["time", "macd"]]) - signal_line = macd_chart.create_line(name="signal", color="#FF6D00", width=2) + signal_line = macd_chart.create_line(name="signal", color="#FF0000", width=2) signal_line.set(df[["time", "signal"]]) @@ -108,9 +112,9 @@ def add_TD(df, chart): markers.append( { "time": item["time"].strftime("%Y-%m-%d"), - "position": "below", - "shape": "arrow_up", - "color": "#4CAF50", + "position": "above", + "shape": "arrow_down", + "color": "#00FF00", "text": f"{item['TD']}", } ) @@ -118,9 +122,9 @@ def add_TD(df, chart): markers.append( { "time": item["time"].strftime("%Y-%m-%d"), - "position": "above", - "shape": "arrow_down", - "color": "#F44336", + "position": "below", + "shape": "arrow_up", + "color": "#FF0000", "text": f"{item['TD']}", } ) @@ -142,7 +146,7 @@ def add_buy_sell_signal_markers(df, chart): "time": item["time"].strftime("%Y-%m-%d"), "position": "below", "shape": "arrow_up", - "color": "#4CAF50", + "color": "#00FF00", "text": f"B", } ) @@ -152,7 +156,7 @@ def add_buy_sell_signal_markers(df, chart): "time": item["time"].strftime("%Y-%m-%d"), "position": "above", "shape": "arrow_down", - "color": "#F44336", + "color": "#FF0000", "text": f"S", } ) @@ -231,13 +235,15 @@ def plot_chart(df, symbol: str, name: str, timeframe: str): time, open, high, low, close, volume, [buy, sell]可选 buy=1 买入信号, sell=1 卖出信号 """ - chart = Chart(toolbox=True, inner_height=0.7, maximize=True) + chart = Chart(toolbox=True, inner_height=0.6, maximize=True) chart.topbar.textbox("symbol", symbol) chart.topbar.textbox("name", name) chart.topbar.textbox("timeframe", timeframe) - chart.legend(visible=True) + chart.legend( + visible=True, font_size=14, color="#FFFFFF", font_family="Times New Roman" + ) chart.set(df) add_ema(df, chart, period=10) @@ -253,7 +259,7 @@ def plot_chart(df, symbol: str, name: str, timeframe: str): if __name__ == "__main__": - symbol = "931357" + symbol = "399986" timeframe = "1W" df = pd.read_csv(