From 5c6c5e4741eef7938f54bb0e2f04766e1fe9ec55 Mon Sep 17 00:00:00 2001 From: Garfield Date: Tue, 24 Mar 2026 13:36:55 -0400 Subject: [PATCH] Add MT5 safety tools to prevent MetaEditor freezes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- scripts/check-syntax.sh | 37 ++++++++++++++++++++++++++++++++++ scripts/metaeditor-watchdog.sh | 23 +++++++++++++++++++++ scripts/safe-compile.sh | 31 ++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100755 scripts/check-syntax.sh create mode 100755 scripts/metaeditor-watchdog.sh create mode 100755 scripts/safe-compile.sh diff --git a/scripts/check-syntax.sh b/scripts/check-syntax.sh new file mode 100755 index 0000000..00347b8 --- /dev/null +++ b/scripts/check-syntax.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Syntax checker for MQL5 files before compilation + +FILE="$1" + +if [ -z "$FILE" ]; then + echo "Usage: $0 " + 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 diff --git a/scripts/metaeditor-watchdog.sh b/scripts/metaeditor-watchdog.sh new file mode 100755 index 0000000..2a9154d --- /dev/null +++ b/scripts/metaeditor-watchdog.sh @@ -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 diff --git a/scripts/safe-compile.sh b/scripts/safe-compile.sh new file mode 100755 index 0000000..8f5ece6 --- /dev/null +++ b/scripts/safe-compile.sh @@ -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