mirror of
https://github.com/silencesdg/mt5_python_ea_suite.git
synced 2026-07-28 03:07:48 +00:00
feat: 每日自动优化完整流程 + 优化器参数范围适配保证金%
- daily_optimize.py: restart_ea() 直接杀旧启新,不再依赖信号文件 - optimize.py: 风控参数搜索范围改为保证金%(SL -100%~-10%, TP +50%~+300%) - cron: 每日凌晨2点自动跑优化→重启EA
This commit is contained in:
@@ -110,13 +110,13 @@ PARAMETER_DEFINITIONS = [
|
||||
# Signal Thresholds
|
||||
{'name': 'buy_threshold', 'type': 'float', 'min': 0.5, 'max': 3.0, 'strategy': 'signal'},
|
||||
{'name': 'sell_threshold', 'type': 'float', 'min': -3.0, 'max': -0.5, 'strategy': 'signal'},
|
||||
# Risk Management
|
||||
{'name': 'stop_loss_pct', 'type': 'float', 'min': -0.05, 'max': -0.01, 'strategy': 'risk'},
|
||||
{'name': 'profit_retracement_pct', 'type': 'float', 'min': 0.05, 'max': 0.20, 'strategy': 'risk'},
|
||||
{'name': 'min_profit_for_trailing', 'type': 'float', 'min': 0.005, 'max': 0.02, 'strategy': 'risk'},
|
||||
{'name': 'take_profit_pct', 'type': 'float', 'min': 0.10, 'max': 0.50, 'strategy': 'risk'},
|
||||
# Risk Management(范围适配保证金%基准)
|
||||
{'name': 'stop_loss_pct', 'type': 'float', 'min': -1.00, 'max': -0.10, 'strategy': 'risk'},
|
||||
{'name': 'profit_retracement_pct', 'type': 'float', 'min': 0.10, 'max': 0.80, 'strategy': 'risk'},
|
||||
{'name': 'min_profit_for_trailing', 'type': 'float', 'min': 0.30, 'max': 2.00, 'strategy': 'risk'},
|
||||
{'name': 'take_profit_pct', 'type': 'float', 'min': 0.50, 'max': 3.00, 'strategy': 'risk'},
|
||||
{'name': 'max_holding_minutes', 'type': 'int', 'min': 30, 'max': 180, 'strategy': 'risk'},
|
||||
{'name': 'min_profit_for_time_exit', 'type': 'float', 'min': 0.002, 'max': 0.01, 'strategy': 'risk'},
|
||||
{'name': 'min_profit_for_time_exit', 'type': 'float', 'min': 0.02, 'max': 0.20, 'strategy': 'risk'},
|
||||
# ★ Strategy Weights — 这些基因现在真正影响适应度
|
||||
{'name': 'weight_MACrossStrategy', 'type': 'float', 'min': 0.0, 'max': 2.0, 'strategy': 'weight'},
|
||||
{'name': 'weight_RSIStrategy', 'type': 'float', 'min': 0.0, 'max': 2.0, 'strategy': 'weight'},
|
||||
|
||||
@@ -218,9 +218,34 @@ def update_config(best_params: dict):
|
||||
|
||||
|
||||
def restart_ea():
|
||||
"""通过信号文件通知 restart_ea.sh 重启"""
|
||||
RESTART_SIGNAL.write_text(datetime.now().isoformat())
|
||||
logger.info("📡 已发送重启信号")
|
||||
"""杀掉旧 EA → 清日志 → 启动新 EA(应用优化后的配置)"""
|
||||
import subprocess
|
||||
logger.info("🔄 重启 EA...")
|
||||
|
||||
# 杀旧进程
|
||||
subprocess.run(["pkill", "-f", "python.*run/realtime.py"], capture_output=True)
|
||||
import time; time.sleep(2)
|
||||
subprocess.run(["pkill", "-9", "-f", "python.*run/realtime.py"], capture_output=True)
|
||||
time.sleep(1)
|
||||
|
||||
# 清空旧交易记录
|
||||
for f in PROJECT_DIR.glob("realtime_trades_*"):
|
||||
f.unlink(missing_ok=True)
|
||||
|
||||
# 清日志
|
||||
log_file = PROJECT_DIR / "logs" / "strategy.log"
|
||||
log_file.write_text("")
|
||||
|
||||
# 启动新 EA(后台)
|
||||
log = open(log_file, "a")
|
||||
proc = subprocess.Popen(
|
||||
[sys.executable, "run/realtime.py"],
|
||||
cwd=str(PROJECT_DIR),
|
||||
stdout=log, stderr=subprocess.STDOUT,
|
||||
)
|
||||
pid_file = PROJECT_DIR / ".ea_pid"
|
||||
pid_file.write_text(str(proc.pid))
|
||||
logger.info(f"✅ EA 已重启 PID={proc.pid}")
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user