-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbatch_compile.ps1
More file actions
89 lines (72 loc) · 3.29 KB
/
Copy pathbatch_compile.ps1
File metadata and controls
89 lines (72 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Batch Compile All Unique MQ5 Files
# Protocol v2 - Evidence-Based (Verified 2026-04-09)
$metaEditor = "C:\Program Files\MetaTrader 5 EXNESS\MetaEditor64.exe"
$mql5Root = (Get-ChildItem "C:\Users\ppnh1\AppData\Roaming\MetaQuotes\Terminal" -Directory `
| Where-Object { Test-Path (Join-Path $_.FullName "MQL5\Include") } `
| Select-Object -First 1).FullName + "\MQL5"
$expertDir = "$mql5Root\Experts"
$logDir = "D:\code\ex5-backtest\compile_logs"
if (-not (Test-Path $expertDir)) { New-Item -ItemType Directory -Path $expertDir -Force | Out-Null }
if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }
Write-Output "MQL5 Root: $mql5Root"
Write-Output "Expert Dir: $expertDir"
Write-Output ""
# Collect unique MQ5 files (skip GUID duplicates like _0257c, _1f06a)
$allMq5 = Get-ChildItem "D:\code\ex5-backtest" -Recurse -Filter "*.mq5" -File
$uniqueFiles = @{}
foreach ($f in $allMq5) {
$normalized = $f.BaseName -replace '_[0-9a-f]{5}$', ''
if (-not $uniqueFiles.ContainsKey($normalized)) {
$uniqueFiles[$normalized] = $f
}
}
Write-Output "Total MQ5 files: $($allMq5.Count)"
Write-Output "Unique (after dedup): $($uniqueFiles.Count)"
Write-Output "========================="
Write-Output ""
$results = @()
$successCount = 0
$errorCount = 0
foreach ($entry in $uniqueFiles.GetEnumerator()) {
$name = $entry.Key
$file = $entry.Value
# Copy source to MQL5 Experts dir
$destMq5 = "$expertDir\$($file.Name)"
Copy-Item $file.FullName -Destination $destMq5 -Force
# Compile
Start-Process -FilePath $metaEditor `
-ArgumentList "/compile:`"$destMq5`" /log /include:`"$mql5Root`"" `
-Wait -NoNewWindow
Start-Sleep -Milliseconds 1500
# Read log
$logFile = "$expertDir\$($file.BaseName).log"
$status = "UNKNOWN"
$errors = 0
$warnings = 0
if (Test-Path $logFile) {
$logContent = Get-Content $logFile -ErrorAction SilentlyContinue
$resultLine = $logContent | Where-Object { $_ -match "Result:" } | Select-Object -Last 1
if ($resultLine -match "(\d+)\s+error") { $errors = [int]$Matches[1] }
if ($resultLine -match "(\d+)\s+warning") { $warnings = [int]$Matches[1] }
if ($errors -eq 0) { $status = "OK"; $successCount++ }
else { $status = "FAIL"; $errorCount++ }
# Save log to compile_logs dir
Copy-Item $logFile -Destination "$logDir\$($file.BaseName).log" -Force
} else {
$status = "NO_LOG"
$errorCount++
}
$line = "{0,-45} {1,-6} {2} errors, {3} warnings" -f $name, $status, $errors, $warnings
Write-Output $line
$results += [PSCustomObject]@{ Name=$name; Status=$status; Errors=$errors; Warnings=$warnings; Source=$file.FullName }
# Cleanup compiled files from expertDir
Remove-Item "$expertDir\$($file.BaseName).ex5" -ErrorAction SilentlyContinue
Remove-Item $destMq5 -ErrorAction SilentlyContinue
Remove-Item $logFile -ErrorAction SilentlyContinue
}
Write-Output ""
Write-Output "========================="
Write-Output "TOTAL: $($uniqueFiles.Count) | SUCCESS: $successCount | FAIL: $errorCount"
# Save summary
$results | Export-Csv "$logDir\_compile_summary.csv" -NoTypeInformation -Encoding UTF8
Write-Output "Summary saved to: $logDir\_compile_summary.csv"