88 lines
3.2 KiB
Python
88 lines
3.2 KiB
Python
import os
|
|
import glob
|
|
import re
|
|
from typing import Dict, List, Any, Optional
|
|
|
|
class EAAutoScanner:
|
|
def __init__(self, mt5_data_dir: str = None):
|
|
self.mt5_data_dir = mt5_data_dir
|
|
self.experts_dir = os.path.join(mt5_data_dir, "MQL5", "Experts") if mt5_data_dir else None
|
|
|
|
def scan_experts(self) -> List[Dict]:
|
|
experts = []
|
|
if not self.experts_dir or not os.path.exists(self.experts_dir):
|
|
return experts
|
|
for root, dirs, files in os.walk(self.experts_dir):
|
|
for f in files:
|
|
if f.endswith('.ex5'):
|
|
full_path = os.path.join(root, f)
|
|
rel_path = os.path.relpath(full_path, self.experts_dir)
|
|
ea_name = os.path.splitext(f)[0]
|
|
experts.append({'name': ea_name, 'filename': f, 'path': rel_path, 'full_path': full_path})
|
|
return experts
|
|
|
|
def generate_json_config(self, ea_info: Dict, params: Dict = None) -> Dict:
|
|
ea_name = ea_info["name"]
|
|
config = {
|
|
"ea_name": ea_name,
|
|
"ea_path": ea_info["path"],
|
|
"description": "Auto-scanned EA",
|
|
"search_strategy": "auto",
|
|
"optimization_criterion": "profit_factor",
|
|
"parameters": {},
|
|
"test_config": {
|
|
"symbol": "EURUSD", "period": "H1",
|
|
"from_date": "2025.01.01", "to_date": "2025.12.31",
|
|
"model": 1, "deposit": 10000, "leverage": "1:100", "timeout_min": 60
|
|
},
|
|
"walk_forward": {"enabled": False, "forward_mode": 0, "forward_date": ""}
|
|
}
|
|
if params:
|
|
for pname, pinfo in params.items():
|
|
config["parameters"][pname] = {
|
|
"type": pinfo.get("type", "int"),
|
|
"default": pinfo.get("default", 0),
|
|
"min": pinfo.get("min", 0),
|
|
"max": pinfo.get("max", 100),
|
|
"step": pinfo.get("step", 1),
|
|
"description": "Auto-scanned"
|
|
}
|
|
return config
|
|
|
|
def auto_scan_all(self) -> List[Dict]:
|
|
configs = []
|
|
experts = self.scan_experts()
|
|
for expert in experts:
|
|
config = self.generate_json_config(expert)
|
|
configs.append(config)
|
|
return configs
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--data-dir", "-d")
|
|
parser.add_argument("--output", "-o", default="configs")
|
|
parser.add_argument("--list", "-l", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
scanner = EAAutoScanner(args.data_dir)
|
|
experts = scanner.scan_experts()
|
|
|
|
if args.list:
|
|
print(f"Found {len(experts)} EAs:")
|
|
for e in experts:
|
|
print(f" - {e['name']}")
|
|
|
|
configs = scanner.auto_scan_all()
|
|
print(f"Generated {len(configs)} configs")
|
|
|
|
if args.output and configs:
|
|
import json
|
|
import os
|
|
os.makedirs(args.output, exist_ok=True)
|
|
for cfg in configs:
|
|
fname = cfg["ea_name"].replace(" ", "_") + ".json"
|
|
with open(os.path.join(args.output, fname), "w", encoding="utf-8") as f:
|
|
json.dump(cfg, f, indent=4, ensure_ascii=False)
|
|
print(f"Saved: {fname}")
|