@echo off
setlocal enabledelayedexpansion

REM StratAudit EA installer.
REM Run this AFTER downloading StratAuditEA.mq5 into the SAME folder as this
REM .cmd file (they should already be together if both came from the
REM Downloads folder). It finds every MetaTrader 5 installation on this PC
REM and copies the EA into its MQL5\Experts folder for you.
REM
REM What this does NOT do: compile the EA, allow WebRequest, or enable Algo
REM Trading — those are one-time MT5 settings you still do by hand inside the
REM terminal (see the "How to install" steps on the Signals page). This
REM script only saves you the manual file-copy step.

set "SCRIPT_DIR=%~dp0"
set "EA_FILE=%SCRIPT_DIR%StratAuditEA.mq5"

if not exist "%EA_FILE%" (
    echo ERROR: StratAuditEA.mq5 was not found next to this script.
    echo Make sure both files are in the same folder, e.g. your Downloads folder.
    pause
    exit /b 1
)

set FOUND=0

for /d %%T in ("%APPDATA%\MetaQuotes\Terminal\*") do (
    if exist "%%T\MQL5\Experts" (
        set /a FOUND+=1
        echo Found MT5 terminal: %%T
        copy /Y "%EA_FILE%" "%%T\MQL5\Experts\StratAuditEA.mq5" >nul
        if !errorlevel! EQU 0 (
            echo   -> Copied EA into MQL5\Experts
        ) else (
            echo   -> COPY FAILED - try running this script as Administrator
        )
    )
)

if %FOUND% EQU 0 (
    echo No MetaTrader 5 installation found under:
    echo   %APPDATA%\MetaQuotes\Terminal\
    echo.
    echo If MT5 is installed in a non-standard location, copy StratAuditEA.mq5
    echo manually into that installation's MQL5\Experts folder instead
    echo ^(in MT5: File -^> Open Data Folder -^> MQL5 -^> Experts^).
    pause
    exit /b 1
)

echo.
echo Done. %FOUND% terminal(s) updated.
echo.
echo Next steps in MetaTrader 5:
echo   1. Open the Navigator panel (Ctrl+N) -^> Expert Advisors -^> StratAuditEA
echo   2. Double-click it to open in MetaEditor, press F7 to compile
echo   3. Tools -^> Options -^> Expert Advisors -^> allow WebRequest for your API URL
echo   4. Turn on "Algo Trading" in the MT5 toolbar
echo   5. Drag StratAuditEA onto a chart and paste in your API key
echo.
pause
