mirror of
https://github.com/rithsila/MT5-EA-Sniper-Strategy.git
synced 2026-07-27 18:47:57 +00:00
2a998b1e2a
✅ Phase 1 Core Trading Logic - COMPLETE (100%) - All core trading functions implemented and tested - Pattern detection working (OB, FVG, BOS, Liquidity Sweeps) - Risk management system functional (1% risk per trade) - Multi-timeframe analysis operational - Trade execution logic complete - Strategy Tester validation successful 📚 Development Workflow Framework - NEW - Complete MT5 EA development workflow documentation - 4-tier testing protocol (Unit → Integration → Strategy → Live Demo) - Compilation automation and validation scripts - Feature branch methodology for incremental development - Performance regression testing framework - Standardized test datasets for consistent backtesting 🧪 Testing Infrastructure - NEW - Baseline testing scripts and procedures - Pattern validation framework - Risk management stress testing - Quick monitoring and troubleshooting guides - Comprehensive testing documentation 📊 Updated Implementation Plan - Corrected completion status from 45% to 85% - Phase 1 marked as complete with all tasks checked off - Updated priority focus to Phase 3 (Visualization) or Phase 4 (Performance Tracking) 🔧 Technical Improvements - Updated SniperEA.mq5 with debug mode enabled - Compiled EA successfully (85KB .ex5 file) - Validated all core functions through Strategy Tester - Clean initialization and deinitialization confirmed Next: Focus on Phase 3 (Chart Visualization) or Phase 4 (Performance Tracking)
394 lines
11 KiB
Markdown
394 lines
11 KiB
Markdown
# 🔧 MT5 EA Compilation & Validation Automation
|
|
|
|
## 🎯 Objective
|
|
Establish automated compilation checkpoints and validation scripts to streamline the development process and catch issues early.
|
|
|
|
## 📋 Compilation Checkpoint Strategy
|
|
|
|
### Checkpoint Frequency
|
|
```
|
|
✅ After every 50-100 lines of code
|
|
✅ After completing each function
|
|
✅ Before running any tests
|
|
✅ Before committing changes
|
|
✅ Before deploying to demo/live
|
|
```
|
|
|
|
### Automated Compilation Script
|
|
|
|
**File**: `compile_ea.ps1` (PowerShell Script)
|
|
|
|
```powershell
|
|
# MT5 EA Compilation Automation Script
|
|
param(
|
|
[string]$EAName = "SniperEA",
|
|
[string]$SourcePath = "D:\Projects\MT5-EA-Sniper-Strategy\src",
|
|
[string]$MT5Path = "C:\Users\$\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075",
|
|
[switch]$Verbose
|
|
)
|
|
|
|
Write-Host "=== MT5 EA Compilation Automation ===" -ForegroundColor Green
|
|
Write-Host "EA Name: $EAName" -ForegroundColor Yellow
|
|
Write-Host "Source: $SourcePath\$EAName.mq5" -ForegroundColor Yellow
|
|
|
|
# Check if source file exists
|
|
$SourceFile = "$SourcePath\$EAName.mq5"
|
|
if (-not (Test-Path $SourceFile)) {
|
|
Write-Host "ERROR: Source file not found: $SourceFile" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# Get file modification time
|
|
$SourceModified = (Get-Item $SourceFile).LastWriteTime
|
|
Write-Host "Source Modified: $SourceModified" -ForegroundColor Cyan
|
|
|
|
# Check if MetaEditor is available
|
|
$MetaEditorPath = "$MT5Path\MetaEditor64.exe"
|
|
if (-not (Test-Path $MetaEditorPath)) {
|
|
Write-Host "ERROR: MetaEditor not found: $MetaEditorPath" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# Compile the EA
|
|
Write-Host "Compiling $EAName..." -ForegroundColor Yellow
|
|
$CompileArgs = "/compile:$SourceFile"
|
|
if ($Verbose) {
|
|
$CompileArgs += " /log"
|
|
}
|
|
|
|
$Process = Start-Process -FilePath $MetaEditorPath -ArgumentList $CompileArgs -Wait -PassThru -WindowStyle Hidden
|
|
|
|
# Check compilation result
|
|
$ExpertPath = "$MT5Path\MQL5\Experts\$EAName.ex5"
|
|
if (Test-Path $ExpertPath) {
|
|
$CompiledModified = (Get-Item $ExpertPath).LastWriteTime
|
|
$FileSize = (Get-Item $ExpertPath).Length
|
|
|
|
if ($CompiledModified -gt $SourceModified.AddSeconds(-10)) {
|
|
Write-Host "✅ COMPILATION SUCCESSFUL" -ForegroundColor Green
|
|
Write-Host "Compiled: $CompiledModified" -ForegroundColor Cyan
|
|
Write-Host "File Size: $([math]::Round($FileSize/1KB, 2)) KB" -ForegroundColor Cyan
|
|
|
|
# Log successful compilation
|
|
$LogEntry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - COMPILE SUCCESS - $EAName - $([math]::Round($FileSize/1KB, 2)) KB"
|
|
Add-Content -Path "$SourcePath\compilation.log" -Value $LogEntry
|
|
|
|
exit 0
|
|
} else {
|
|
Write-Host "⚠️ COMPILATION MAY HAVE FAILED - File not updated" -ForegroundColor Yellow
|
|
exit 2
|
|
}
|
|
} else {
|
|
Write-Host "❌ COMPILATION FAILED - No .ex5 file generated" -ForegroundColor Red
|
|
|
|
# Log failed compilation
|
|
$LogEntry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - COMPILE FAILED - $EAName"
|
|
Add-Content -Path "$SourcePath\compilation.log" -Value $LogEntry
|
|
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
### Quick Compilation Batch File
|
|
|
|
**File**: `quick_compile.bat`
|
|
|
|
```batch
|
|
@echo off
|
|
echo === Quick EA Compilation ===
|
|
cd /d "D:\Projects\MT5-EA-Sniper-Strategy"
|
|
powershell -ExecutionPolicy Bypass -File "compile_ea.ps1" -EAName "SniperEA"
|
|
if %ERRORLEVEL% EQU 0 (
|
|
echo.
|
|
echo ✅ Ready for testing!
|
|
echo.
|
|
) else (
|
|
echo.
|
|
echo ❌ Fix compilation errors before proceeding
|
|
echo.
|
|
)
|
|
pause
|
|
```
|
|
|
|
## 🔍 Automated Validation Scripts
|
|
|
|
### Pre-Compilation Validation
|
|
|
|
**File**: `validate_code.ps1`
|
|
|
|
```powershell
|
|
# Code Validation Script
|
|
param(
|
|
[string]$SourceFile = "D:\Projects\MT5-EA-Sniper-Strategy\src\SniperEA.mq5"
|
|
)
|
|
|
|
Write-Host "=== Code Validation Checks ===" -ForegroundColor Green
|
|
|
|
$Issues = @()
|
|
$Content = Get-Content $SourceFile -Raw
|
|
|
|
# Check 1: Required Functions Present
|
|
$RequiredFunctions = @(
|
|
"OnInit()",
|
|
"OnTick()",
|
|
"ProcessTradingLogic()",
|
|
"CalculatePositionSize(",
|
|
"ExecuteBuyTrade(",
|
|
"ExecuteSellTrade("
|
|
)
|
|
|
|
foreach ($Function in $RequiredFunctions) {
|
|
if ($Content -notmatch [regex]::Escape($Function)) {
|
|
$Issues += "Missing required function: $Function"
|
|
}
|
|
}
|
|
|
|
# Check 2: Risk Management Parameters
|
|
$RiskParams = @(
|
|
"RiskPercent",
|
|
"MaxPositionsPerSymbol",
|
|
"MaxTotalPositions"
|
|
)
|
|
|
|
foreach ($Param in $RiskParams) {
|
|
if ($Content -notmatch "input.*$Param") {
|
|
$Issues += "Missing risk parameter: $Param"
|
|
}
|
|
}
|
|
|
|
# Check 3: Debug Mode Available
|
|
if ($Content -notmatch "EnableDebugMode") {
|
|
$Issues += "Debug mode parameter not found"
|
|
}
|
|
|
|
# Check 4: Trade Object Initialization
|
|
if ($Content -notmatch "CTrade.*trade") {
|
|
$Issues += "CTrade object not properly declared"
|
|
}
|
|
|
|
# Check 5: Magic Number Set
|
|
if ($Content -notmatch "SetExpertMagicNumber") {
|
|
$Issues += "Magic number not set for trade identification"
|
|
}
|
|
|
|
# Report Results
|
|
if ($Issues.Count -eq 0) {
|
|
Write-Host "✅ All validation checks passed!" -ForegroundColor Green
|
|
exit 0
|
|
} else {
|
|
Write-Host "❌ Validation issues found:" -ForegroundColor Red
|
|
foreach ($Issue in $Issues) {
|
|
Write-Host " - $Issue" -ForegroundColor Yellow
|
|
}
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
### Post-Compilation Validation
|
|
|
|
**File**: `validate_compilation.ps1`
|
|
|
|
```powershell
|
|
# Post-Compilation Validation
|
|
param(
|
|
[string]$EAName = "SniperEA",
|
|
[string]$MT5Path = "C:\Users\$\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075"
|
|
)
|
|
|
|
Write-Host "=== Post-Compilation Validation ===" -ForegroundColor Green
|
|
|
|
$ExpertPath = "$MT5Path\MQL5\Experts\$EAName.ex5"
|
|
$Issues = @()
|
|
|
|
# Check 1: .ex5 file exists
|
|
if (-not (Test-Path $ExpertPath)) {
|
|
$Issues += ".ex5 file not found - compilation failed"
|
|
} else {
|
|
$FileInfo = Get-Item $ExpertPath
|
|
$FileSize = $FileInfo.Length
|
|
$LastModified = $FileInfo.LastWriteTime
|
|
|
|
Write-Host "File Size: $([math]::Round($FileSize/1KB, 2)) KB" -ForegroundColor Cyan
|
|
Write-Host "Last Modified: $LastModified" -ForegroundColor Cyan
|
|
|
|
# Check 2: File size reasonable (should be 80-100KB for Sniper EA)
|
|
if ($FileSize -lt 50KB) {
|
|
$Issues += "File size too small ($([math]::Round($FileSize/1KB, 2)) KB) - possible compilation issues"
|
|
} elseif ($FileSize -gt 200KB) {
|
|
$Issues += "File size unusually large ($([math]::Round($FileSize/1KB, 2)) KB) - check for bloat"
|
|
}
|
|
|
|
# Check 3: File recently modified (within last 5 minutes)
|
|
$FiveMinutesAgo = (Get-Date).AddMinutes(-5)
|
|
if ($LastModified -lt $FiveMinutesAgo) {
|
|
$Issues += "File not recently modified - may be stale compilation"
|
|
}
|
|
}
|
|
|
|
# Check 4: Log file for compilation errors
|
|
$LogPath = "$MT5Path\MQL5\Logs"
|
|
if (Test-Path $LogPath) {
|
|
$RecentLogs = Get-ChildItem $LogPath -Filter "*.log" |
|
|
Where-Object { $_.LastWriteTime -gt (Get-Date).AddMinutes(-10) }
|
|
|
|
foreach ($Log in $RecentLogs) {
|
|
$LogContent = Get-Content $Log.FullName -Tail 50
|
|
$ErrorLines = $LogContent | Where-Object { $_ -match "error|warning" -and $_ -match $EAName }
|
|
|
|
if ($ErrorLines) {
|
|
$Issues += "Compilation warnings/errors found in $($Log.Name)"
|
|
}
|
|
}
|
|
}
|
|
|
|
# Report Results
|
|
if ($Issues.Count -eq 0) {
|
|
Write-Host "✅ Post-compilation validation passed!" -ForegroundColor Green
|
|
Write-Host "EA is ready for testing" -ForegroundColor Green
|
|
exit 0
|
|
} else {
|
|
Write-Host "❌ Post-compilation issues found:" -ForegroundColor Red
|
|
foreach ($Issue in $Issues) {
|
|
Write-Host " - $Issue" -ForegroundColor Yellow
|
|
}
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
## 🚀 VS Code Integration
|
|
|
|
### VS Code Task Configuration
|
|
|
|
**File**: `.vscode/tasks.json`
|
|
|
|
```json
|
|
{
|
|
"version": "2.0.0",
|
|
"tasks": [
|
|
{
|
|
"label": "Compile Sniper EA",
|
|
"type": "shell",
|
|
"command": "powershell",
|
|
"args": [
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-File", "${workspaceFolder}/compile_ea.ps1",
|
|
"-EAName", "SniperEA",
|
|
"-Verbose"
|
|
],
|
|
"group": {
|
|
"kind": "build",
|
|
"isDefault": true
|
|
},
|
|
"presentation": {
|
|
"echo": true,
|
|
"reveal": "always",
|
|
"focus": false,
|
|
"panel": "shared"
|
|
},
|
|
"problemMatcher": []
|
|
},
|
|
{
|
|
"label": "Validate & Compile",
|
|
"dependsOrder": "sequence",
|
|
"dependsOn": [
|
|
"Validate Code",
|
|
"Compile Sniper EA",
|
|
"Post-Compile Validation"
|
|
]
|
|
},
|
|
{
|
|
"label": "Validate Code",
|
|
"type": "shell",
|
|
"command": "powershell",
|
|
"args": [
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-File", "${workspaceFolder}/validate_code.ps1"
|
|
]
|
|
},
|
|
{
|
|
"label": "Post-Compile Validation",
|
|
"type": "shell",
|
|
"command": "powershell",
|
|
"args": [
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-File", "${workspaceFolder}/validate_compilation.ps1"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### VS Code Keyboard Shortcuts
|
|
|
|
**File**: `.vscode/keybindings.json`
|
|
|
|
```json
|
|
[
|
|
{
|
|
"key": "ctrl+shift+b",
|
|
"command": "workbench.action.tasks.runTask",
|
|
"args": "Validate & Compile"
|
|
},
|
|
{
|
|
"key": "f5",
|
|
"command": "workbench.action.tasks.runTask",
|
|
"args": "Compile Sniper EA"
|
|
}
|
|
]
|
|
```
|
|
|
|
## 📊 Compilation Monitoring
|
|
|
|
### Compilation Log Analysis
|
|
|
|
**File**: `analyze_compilation_log.ps1`
|
|
|
|
```powershell
|
|
# Analyze compilation patterns
|
|
$LogFile = "D:\Projects\MT5-EA-Sniper-Strategy\src\compilation.log"
|
|
|
|
if (Test-Path $LogFile) {
|
|
$Logs = Get-Content $LogFile
|
|
$SuccessCount = ($Logs | Where-Object { $_ -match "COMPILE SUCCESS" }).Count
|
|
$FailCount = ($Logs | Where-Object { $_ -match "COMPILE FAILED" }).Count
|
|
$TotalCompilations = $SuccessCount + $FailCount
|
|
|
|
if ($TotalCompilations -gt 0) {
|
|
$SuccessRate = [math]::Round(($SuccessCount / $TotalCompilations) * 100, 2)
|
|
|
|
Write-Host "=== Compilation Statistics ===" -ForegroundColor Green
|
|
Write-Host "Total Compilations: $TotalCompilations" -ForegroundColor Cyan
|
|
Write-Host "Successful: $SuccessCount" -ForegroundColor Green
|
|
Write-Host "Failed: $FailCount" -ForegroundColor Red
|
|
Write-Host "Success Rate: $SuccessRate%" -ForegroundColor Yellow
|
|
|
|
# Recent compilation trend
|
|
$RecentLogs = $Logs | Select-Object -Last 10
|
|
$RecentSuccess = ($RecentLogs | Where-Object { $_ -match "COMPILE SUCCESS" }).Count
|
|
Write-Host "Recent Success Rate (last 10): $([math]::Round(($RecentSuccess/10)*100, 2))%" -ForegroundColor Cyan
|
|
}
|
|
}
|
|
```
|
|
|
|
## 🎯 Usage Instructions
|
|
|
|
### For Development Workflow:
|
|
|
|
1. **Before Coding**: Run `validate_code.ps1` to check current state
|
|
2. **During Coding**: Use `Ctrl+Shift+B` in VS Code for full validation & compilation
|
|
3. **Quick Compilation**: Use `F5` in VS Code or run `quick_compile.bat`
|
|
4. **After Major Changes**: Run full validation sequence
|
|
|
|
### Integration with Your Current Setup:
|
|
|
|
Since you already have the Strategy Tester open and ready:
|
|
|
|
1. **Save these scripts** in your project directory
|
|
2. **Set up VS Code tasks** for one-click compilation
|
|
3. **Use automated validation** before each Strategy Tester run
|
|
4. **Monitor compilation logs** to track development progress
|
|
|
|
---
|
|
|
|
**Next Step**: Set up these automation scripts, then proceed with your baseline testing in the Strategy Tester you have open.
|