简化当前可视k线范围计算
This commit is contained in:
25
chart.py
25
chart.py
@@ -313,13 +313,20 @@ class QuantChart:
|
|||||||
return
|
return
|
||||||
|
|
||||||
total_bars = len(df)
|
total_bars = len(df)
|
||||||
# TODO: k线拉到最早会报错
|
# 计算可见范围的起始和结束索引
|
||||||
if bars_after < 0:
|
# if bars_after < 0:
|
||||||
start_idx = max(0, int(bars_before))
|
# start_idx = max(0, int(bars_before))
|
||||||
end_idx = total_bars
|
# end_idx = total_bars
|
||||||
else:
|
# elif bars_before < 0:
|
||||||
start_idx = int(bars_before)
|
# start_idx = 0
|
||||||
end_idx = max(0, int(total_bars - bars_after))
|
# 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]
|
df_range = df.iloc[start_idx:end_idx]
|
||||||
# logger.info(
|
# logger.info(
|
||||||
# f"Calculating POC for bars {start_idx} to {end_idx}, total_bars={total_bars}, bars_before={bars_before}, bars_after={bars_after}"
|
# 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(
|
poc_line = chart.horizontal_line(
|
||||||
price=poc, color="#FF0000", width=4, style="solid", text=f"{poc:.2f}"
|
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)}"
|
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)
|
self.update_legend(chart=chart, key=poc_line_name, text=legend_text)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user