Add MT5 safety tools to prevent MetaEditor freezes

- check-syntax.sh: Pre-compilation syntax checker for MT4→MT5 issues
- metaeditor-watchdog.sh: Auto-kills stuck MetaEditor processes
- safe-compile.sh: Wrapper with 2-minute timeout for compilations

These tools help prevent the container freeze that occurred when
trying to compile OrdersEA with 100 MT4 syntax errors.
This commit is contained in:
2026-03-24 13:36:55 -04:00
parent c415cd9919
commit 5c6c5e4741
3 changed files with 91 additions and 0 deletions

37
scripts/check-syntax.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
# Syntax checker for MQL5 files before compilation
FILE="$1"
if [ -z "$FILE" ]; then
echo "Usage: $0 <filename.mq5>"
exit 1
fi
echo "=== Checking $FILE for obvious MT4→MT5 conversion issues ==="
echo ""
echo "MT4 functions that won't work in MT5:"
grep -n "OrderSend(\|OrderClose(\|OrderSelect(\|MarketInfo(\|WindowExpertName(\|IsOptimization(" "$FILE" | head -10
echo ""
echo "Global variables that should be functions in MT5:"
grep -n "\bBid\b\|\bAsk\b\|\bDigits\b\|\bPoint\b" "$FILE" | grep -v "SymbolInfoDouble\|SymbolInfoInteger" | head -10
echo ""
echo "Ticket types (should be ulong, not int):"
grep -n "int.*ticket\|int.*Ticket" "$FILE" | head -5
echo ""
echo "WinAPI includes (will fail in Wine/MT5):"
grep -n "WinAPI\|winuser\|WinUser" "$FILE"
echo ""
echo "=== Quick Fix Check ==="
ERRORS=$(grep -c "OrderSelect(\|MarketInfo(\|WindowExpertName(\|IsOptimization(" "$FILE" 2>/dev/null)
if [ "$ERRORS" -gt 0 ]; then
echo "⚠️ WARNING: Found $ERRORS MT4-only functions!"
echo "This file will NOT compile in MT5. It needs conversion."
else
echo "✅ No obvious MT4 functions found"
fi

23
scripts/metaeditor-watchdog.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Watchdog to kill stuck MetaEditor processes
while true; do
# Find MetaEditor processes running for more than 5 minutes with high CPU
docker exec mt5 sh -c '
ps aux | grep metaeditor64 | grep -v grep | while read line; do
pid=$(echo $line | awk "{print \$2}")
cpu=$(echo $line | awk "{print \$3}")
time=$(echo $line | awk "{print \$10}")
# Kill if running more than 5 mins or using >50% CPU for >2 mins
if echo "$time" | grep -qE "[5-9]:[0-9]{2}|[0-9]{2,}:"; then
echo "Killing long-running MetaEditor: $pid (time: $time)"
kill -9 $pid 2>/dev/null
elif [ "${cpu%.*}" -gt 50 ] 2>/dev/null; then
echo "Killing high-CPU MetaEditor: $pid (CPU: $cpu%)"
kill -9 $pid 2>/dev/null
fi
done
' 2>/dev/null
sleep 60
done

31
scripts/safe-compile.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
# Safe compilation wrapper
echo "=== Safe Compile Mode ==="
echo ""
echo "1. Checking file syntax first..."
echo ""
echo "2. Killing any existing MetaEditor processes..."
docker exec mt5 pkill -9 metaeditor64 2>/dev/null
sleep 2
echo ""
echo "3. Starting MetaEditor in background with timeout..."
# MetaEditor has 2 minute timeout
timeout 120 docker exec mt5 wine "/config/.wine/drive_c/Program Files/MetaTrader 5/metaeditor64.exe" "$@" 2>&1 &
PID=$!
echo ""
echo "4. Monitoring for 2 minutes max..."
wait $PID
EXITCODE=$?
if [ $EXITCODE -eq 124 ]; then
echo "⚠️ Compilation timed out - MetaEditor was killed"
docker exec mt5 pkill -9 metaeditor64 2>/dev/null
elif [ $EXITCODE -eq 0 ]; then
echo "✅ Compilation completed"
else
echo "⚠️ Compilation exited with code $EXITCODE"
fi