diff --git a/chart.py b/chart.py index 70e4392..150b74d 100644 --- a/chart.py +++ b/chart.py @@ -313,13 +313,20 @@ class QuantChart: return total_bars = len(df) - # TODO: k线拉到最早会报错 - if bars_after < 0: - start_idx = max(0, int(bars_before)) - end_idx = total_bars - else: - start_idx = int(bars_before) - end_idx = max(0, int(total_bars - bars_after)) + # 计算可见范围的起始和结束索引 + # if bars_after < 0: + # start_idx = max(0, int(bars_before)) + # end_idx = total_bars + # elif bars_before < 0: + # start_idx = 0 + # end_idx = max(0, int(total_bars - bars_after)) + # else: + # start_idx = int(bars_before) + # end_idx = max(0, int(total_bars - bars_after)) + + start_idx = max(0, int(bars_before)) + end_idx = max(0, int(total_bars - max(0, int(bars_after)))) + df_range = df.iloc[start_idx:end_idx] # logger.info( # f"Calculating POC for bars {start_idx} to {end_idx}, total_bars={total_bars}, bars_before={bars_before}, bars_after={bars_after}" @@ -335,10 +342,6 @@ class QuantChart: poc_line = chart.horizontal_line( price=poc, color="#FF0000", width=4, style="solid", text=f"{poc:.2f}" ) - # chart.legend( - # visible=True, - # text=f"POC: {poc:.2f}, poc_range_profit%: {profit:.1f}%, visible_tf_cnt: {len(df_range)}", - # ) legend_text = f"POC: {poc:.2f}, poc_range_profit%: {profit:.1f}%, visible_tf_cnt: {len(df_range)}" self.update_legend(chart=chart, key=poc_line_name, text=legend_text)