添加后缀映射功能
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import Dict, List, Any, Optional
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from mt5_paths import resolve_mt5_settings
|
||||
from symbol_resolver import resolve_symbol
|
||||
|
||||
|
||||
class INIGenerator:
|
||||
@@ -115,12 +116,16 @@ class INIGenerator:
|
||||
else:
|
||||
ini_lines.append("ExpertParameters=")
|
||||
|
||||
# MT5 tester delay is controlled by ExecutionMode itself:
|
||||
# 0 = no delay
|
||||
# -1 = random delay
|
||||
# > 0 = fixed delay in milliseconds
|
||||
execution_delay = int(bt_settings.get('execution_delay', 0) or 0)
|
||||
ini_lines.extend([
|
||||
f"Symbol={symbol}",
|
||||
f"Period={self._get_timeframe_code(timeframe)}",
|
||||
f"Model={bt_settings['model']}",
|
||||
f"ExecutionMode={bt_settings.get('execution_mode', 0)}",
|
||||
f"ExecutionDelay={bt_settings.get('execution_delay', 0)}",
|
||||
f"ExecutionMode={execution_delay}",
|
||||
f"Optimization={bt_settings['optimization']}",
|
||||
])
|
||||
if bt_settings.get("optimization"):
|
||||
@@ -184,14 +189,15 @@ class INIGenerator:
|
||||
param_combinations = self._generate_parameter_combinations(parameters)
|
||||
|
||||
for symbol in bt_settings["symbols"]:
|
||||
resolved_symbol = resolve_symbol(symbol, bt_settings)
|
||||
for timeframe in bt_settings["timeframes"]:
|
||||
for param_combo in param_combinations:
|
||||
ini_content = self._build_ini_content(
|
||||
ea_filename, symbol, timeframe,
|
||||
ea_filename, resolved_symbol, timeframe,
|
||||
bt_settings, param_combo, ea_name, set_file
|
||||
)
|
||||
ini_filename = self._generate_filename(
|
||||
ea_name, symbol, timeframe, param_combo
|
||||
ea_name, resolved_symbol, timeframe, param_combo
|
||||
)
|
||||
ini_path = os.path.join(self.output_dir, ini_filename)
|
||||
|
||||
@@ -253,4 +259,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -225,6 +225,13 @@ class MT5AutoRunner:
|
||||
|
||||
logger.info(f"Total INI files: {total}")
|
||||
|
||||
# First run must also start from a clean tester state. Otherwise the first test
|
||||
# can inherit an already-open terminal's previous deposit/delay/symbol settings,
|
||||
# while later tests look correct only because kill_between_tests runs after them.
|
||||
if kill_between_tests:
|
||||
self._kill_mt5()
|
||||
time.sleep(2)
|
||||
|
||||
for idx, ini_path in enumerate(ini_files, 1):
|
||||
logger.info(f"[{idx}/{total}] {os.path.basename(ini_path)}")
|
||||
|
||||
@@ -352,4 +359,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -13,6 +13,7 @@ from ea_config_parser import load_ea_config, load_all_ea_configs, EAConfig
|
||||
from parameter_constraint import create_constraint_engine
|
||||
from smart_search import SmartSearch
|
||||
from analyze_results import ResultAnalyzer
|
||||
from symbol_resolver import resolve_symbol
|
||||
|
||||
|
||||
class EABatchOptimizer:
|
||||
@@ -157,7 +158,7 @@ class EABatchOptimizer:
|
||||
'[Tester]',
|
||||
'Expert=' + ea_config.ea_path,
|
||||
'ExpertParameters=' + set_filename,
|
||||
'Symbol=' + test_config.get('symbol', 'EURUSD'),
|
||||
'Symbol=' + resolve_symbol(test_config.get('symbol', 'EURUSD'), test_config),
|
||||
'Period=' + test_config.get('period', 'H1'),
|
||||
'Model=' + str(test_config.get('model', 1)),
|
||||
'FromDate=' + date_from,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Root symbol alias resolver (pure lookup, no auto-switching).
|
||||
|
||||
用户视角的"逻辑品种"(如 XAUUSD)映射到 MT5 里实际使用的品种。
|
||||
|
||||
ponytail:
|
||||
- 没有别名表 / 没条目 -> 原样返回(零行为变化,向后兼容)
|
||||
- 有条目 -> 一比一映射,写啥用啥,不做任何基于日期/优化/周期的判断
|
||||
- 升级路径:要从 yaml 切到数据库 / MT5 SymbolSelect 校验,只改这里
|
||||
|
||||
配置示例(ea_configs.yaml):
|
||||
symbol_aliases:
|
||||
XAUUSD: XAUUSDc # 逻辑 XAUUSD -> 实际 XAUUSDc
|
||||
XAGUSD: XAGUSDm # 逻辑 XAGUSD -> 实际 XAGUSDm
|
||||
# EURUSD 没列 -> 始终 EURUSD
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
def resolve_symbol(symbol: str, bt_settings: Dict[str, Any]) -> str:
|
||||
"""逻辑品种 -> 实际 MT5 品种。无任何自动判断,按表直查。"""
|
||||
if not symbol:
|
||||
return symbol
|
||||
aliases = bt_settings.get("symbol_aliases") or {}
|
||||
mapped = aliases.get(symbol)
|
||||
if not mapped: # None / "" / 缺失 -> 直通
|
||||
return symbol
|
||||
return mapped
|
||||
Reference in New Issue
Block a user