日志展示优化
This commit is contained in:
@@ -42,7 +42,7 @@ class BitmartFuturesTransaction:
|
||||
# 反手频率控制
|
||||
self.reverse_cooldown_seconds = 60 # 反手冷却时间(秒)
|
||||
self.last_reverse_time = None # 上次反手时间
|
||||
self.max_reverse_times_per_kline = 2 # 同一根 K 线最多反手次数
|
||||
self.max_reverse_times_per_kline = 1 # 同一根 K 线最多反手次数
|
||||
self.reverse_count_kline_id = None # 反手计数对应的 K 线 id
|
||||
self.reverse_count_in_kline = 0 # 当前 K 线已反手次数
|
||||
|
||||
@@ -72,7 +72,7 @@ class BitmartFuturesTransaction:
|
||||
# 自动止盈:基于当前K线振幅四等分(多仓用 open~high,空仓用 open~low)
|
||||
self.take_profit_close_quartile = 3 # 达到极值后,回到 3/4 位置平仓
|
||||
self.take_profit_reentry_quartile = 2 # 止盈后,继续回到 2/4 位置同向再开仓
|
||||
self.take_profit_min_gain_pct_from_entry = 0.4 # 相对开仓均价的最小盈利阈值(%),超过才允许止盈
|
||||
self.take_profit_min_gain_pct_from_entry = 0.4 # 相对当前K线开盘价的最小涨跌幅阈值(%),超过才允许止盈
|
||||
self.take_profit_triggered_kline_id = None # 多仓:本K线内是否出现过 open~high 的极值触发
|
||||
self.take_profit_reentry_threshold = None # 多仓止盈平仓后,价格 <= 此值则开多(同向)
|
||||
self.take_profit_triggered_kline_id_short = None # 空仓:本K线内是否出现过 open~low 的极值触发
|
||||
@@ -764,10 +764,8 @@ class BitmartFuturesTransaction:
|
||||
long_levels = self.calc_long_take_profit_levels(current_kline)
|
||||
if long_levels is not None:
|
||||
retrace_close_threshold = long_levels["close_threshold"]
|
||||
min_gain_price_long = self.open_avg_price * (1 + self.take_profit_min_gain_pct_from_entry / 100) if self.open_avg_price is not None else None
|
||||
min_gain_ok_long = (
|
||||
min_gain_price_long is not None and long_levels["extreme"] > min_gain_price_long
|
||||
)
|
||||
min_gain_price_long = long_levels["open"] * (1 + self.take_profit_min_gain_pct_from_entry / 100)
|
||||
min_gain_ok_long = long_levels["extreme"] > min_gain_price_long
|
||||
# 使用当前K线 high 判定是否已触发到 4/4 极值,避免依赖分钟收盘价漏判
|
||||
if long_levels["extreme"] > long_levels["open"]:
|
||||
self.take_profit_triggered_kline_id = current_kline_time
|
||||
@@ -778,7 +776,7 @@ class BitmartFuturesTransaction:
|
||||
):
|
||||
reason = (
|
||||
f"当前K线开盘价={long_levels['open']:.2f},最高价={long_levels['extreme']:.2f}(4/4);"
|
||||
f"现价{current_price:.2f}已回调至≤{retrace_close_threshold:.2f}(3/4),且当根最高价相对开仓均价{self.open_avg_price:.2f}盈利>{self.take_profit_min_gain_pct_from_entry:.2f}%,按规则止盈平多"
|
||||
f"现价{current_price:.2f}已回调至≤{retrace_close_threshold:.2f}(3/4),且当根最高价相对当前K线开盘价{long_levels['open']:.2f}涨幅>{self.take_profit_min_gain_pct_from_entry:.2f}%,按规则止盈平多"
|
||||
)
|
||||
self._log_take_profit_action("止盈平多仓", reason)
|
||||
self.平仓()
|
||||
@@ -820,10 +818,8 @@ class BitmartFuturesTransaction:
|
||||
short_levels = self.calc_short_take_profit_levels(current_kline)
|
||||
if short_levels is not None:
|
||||
retrace_close_threshold_short = short_levels["close_threshold"]
|
||||
min_gain_price_short = self.open_avg_price * (1 - self.take_profit_min_gain_pct_from_entry / 100) if self.open_avg_price is not None else None
|
||||
min_gain_ok_short = (
|
||||
min_gain_price_short is not None and short_levels["extreme"] < min_gain_price_short
|
||||
)
|
||||
min_gain_price_short = short_levels["open"] * (1 - self.take_profit_min_gain_pct_from_entry / 100)
|
||||
min_gain_ok_short = short_levels["extreme"] < min_gain_price_short
|
||||
# 使用当前K线 low 判定是否已触发到 4/4 极值,避免依赖分钟收盘价漏判
|
||||
if short_levels["extreme"] < short_levels["open"]:
|
||||
self.take_profit_triggered_kline_id_short = current_kline_time
|
||||
@@ -834,7 +830,7 @@ class BitmartFuturesTransaction:
|
||||
):
|
||||
reason = (
|
||||
f"当前K线开盘价={short_levels['open']:.2f},最低价={short_levels['extreme']:.2f}(4/4);"
|
||||
f"现价{current_price:.2f}已反弹至≥{retrace_close_threshold_short:.2f}(3/4),且当根最低价相对开仓均价{self.open_avg_price:.2f}盈利>{self.take_profit_min_gain_pct_from_entry:.2f}%,按规则止盈平空"
|
||||
f"现价{current_price:.2f}已反弹至≥{retrace_close_threshold_short:.2f}(3/4),且当根最低价相对当前K线开盘价{short_levels['open']:.2f}跌幅>{self.take_profit_min_gain_pct_from_entry:.2f}%,按规则止盈平空"
|
||||
)
|
||||
self._log_take_profit_action("止盈平空仓", reason)
|
||||
self.平仓()
|
||||
|
||||
Reference in New Issue
Block a user