diff --git a/bitmart/三分之一策略交易.py b/bitmart/三分之一策略交易.py index 125d447..2968b2f 100644 --- a/bitmart/三分之一策略交易.py +++ b/bitmart/三分之一策略交易.py @@ -260,8 +260,8 @@ class BitmartFuturesTransaction: prev_entity_lower = prev_entity_edge['lower'] # 实体下边 # 计算触发价(基于上一根K线实体位置) - long_trigger = prev_entity_lower + prev_entity / 3 # 做多触发价 = 实体下边 + 实体/3(下三分之一处) - short_trigger = prev_entity_upper - prev_entity / 3 # 做空触发价 = 实体上边 - 实体/3(上三分之一处) + long_trigger = prev_entity_lower + prev_entity / 4 # 做多触发价 = 实体下边 + 实体/4(下四分之一处) + short_trigger = prev_entity_upper - prev_entity / 4 # 做空触发价 = 实体上边 - 实体/4(上四分之一处) # 上一根阴线 + 当前阳线:做多形态,不按上一根K线上三分之一做空 prev_is_bearish = prev_kline['close'] < prev_kline['open'] @@ -274,26 +274,26 @@ class BitmartFuturesTransaction: logger.info(f"当前价格: {current_price:.2f}, 上一根实体: {prev_entity:.4f}") logger.info(f"上一根实体上边: {prev_entity_upper:.2f}, 下边: {prev_entity_lower:.2f}") - logger.info(f"做多触发价(下1/3): {long_trigger:.2f}, 做空触发价(上1/3): {short_trigger:.2f}") + logger.info(f"做多触发价(下1/4): {long_trigger:.2f}, 做空触发价(上1/4): {short_trigger:.2f}") if skip_short_by_upper_third: - logger.info("上一根阴线+当前阳线(做多形态),不按上三分之一做空") + logger.info("上一根阴线+当前阳线(做多形态),不按上四分之一做空") if skip_long_by_lower_third: - logger.info("上一根阳线+当前阴线(做空形态),不按下三分之一做多") + logger.info("上一根阳线+当前阴线(做空形态),不按下四分之一做多") # 无持仓时检查开仓信号 if self.start == 0: if current_price >= long_trigger and not skip_long_by_lower_third: - logger.info(f"触发做多信号!价格 {current_price:.2f} >= 触发价(下1/3) {long_trigger:.2f}") + logger.info(f"触发做多信号!价格 {current_price:.2f} >= 触发价(下1/4) {long_trigger:.2f}") return ('long', long_trigger) elif current_price <= short_trigger and not skip_short_by_upper_third: - logger.info(f"触发做空信号!价格 {current_price:.2f} <= 触发价(上1/3) {short_trigger:.2f}") + logger.info(f"触发做空信号!价格 {current_price:.2f} <= 触发价(上1/4) {short_trigger:.2f}") return ('short', short_trigger) # 持仓时检查反手信号 elif self.start == 1: # 持多仓 # 反手条件1: 价格跌到上一根K线的上三分之一处(做空触发价);上一根阴线+当前阳线做多时跳过 if current_price <= short_trigger and not skip_short_by_upper_third: - logger.info(f"持多反手做空!价格 {current_price:.2f} <= 触发价(上1/3) {short_trigger:.2f}") + logger.info(f"持多反手做空!价格 {current_price:.2f} <= 触发价(上1/4) {short_trigger:.2f}") return ('reverse_short', short_trigger) # 反手条件2: 上一根K线上阴线涨幅>0.01%,当前跌到上一根实体下边 @@ -306,7 +306,7 @@ class BitmartFuturesTransaction: elif self.start == -1: # 持空仓 # 反手条件1: 价格涨到上一根K线的下三分之一处(做多触发价);上一根阳线+当前阴线做空时跳过 if current_price >= long_trigger and not skip_long_by_lower_third: - logger.info(f"持空反手做多!价格 {current_price:.2f} >= 触发价(下1/3) {long_trigger:.2f}") + logger.info(f"持空反手做多!价格 {current_price:.2f} >= 触发价(下1/4) {long_trigger:.2f}") return ('reverse_long', long_trigger) # 反手条件2: 上一根K线下阴线跌幅>0.01%,当前涨到上一根实体上边 @@ -460,7 +460,7 @@ class BitmartFuturesTransaction: def action(self): """主循环""" - logger.info("开始运行三分之一策略交易...") + logger.info("开始运行四分之一策略交易...") # 启动时设置全仓高杠杆 if not self.set_leverage(): @@ -517,13 +517,14 @@ class BitmartFuturesTransaction: trade_success = self.execute_trade(signal, size=1) if trade_success: logger.success(f"交易执行完成: {signal[0]}, 当前持仓状态: {self.start}") + page_start = True else: logger.warning(f"交易执行失败或被阻止: {signal[0]}") # 6. 短暂等待后继续循环(同一根K线遇到信号就操作) time.sleep(3) - if random.randint(1, 11) > 7: + if page_start: self.page.close() time.sleep(5)