$npx -y skills add kecoma1/MQL5-SKILLS --skill optimizeRun MetaTrader 5 parameter optimizations in this workspace and summarize real results from exported optimization reports. Use when Codex needs to optimize EA inputs such as SL, TP, RSI values, or other inputs for experts under MQL5\Experts, by generating a tester .ini with [Teste
| 1 | # Optimization |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill for MT5 strategy optimizations in this workspace. |
| 6 | |
| 7 | Confirm the optimization setup, write a tester `.ini` under `MQL5\config\`, place the parameter ranges in `[TesterInputs]`, close any running MT5 instance, launch `terminal64.exe` with `/config:...`, and summarize the actual ranking from the exported XML report. |
| 8 | |
| 9 | ## Required workflow |
| 10 | |
| 11 | 1. Confirm the test configuration before launching. |
| 12 | 2. Ask for these fields in this order unless the user has already specified them clearly: |
| 13 | - Expert or strategy file |
| 14 | - Symbol |
| 15 | - Timeframe |
| 16 | - Date range |
| 17 | - Deposit |
| 18 | - Deposit currency |
| 19 | - Leverage |
| 20 | - Tick model |
| 21 | - Optimization on or off |
| 22 | - Visualization on or off |
| 23 | 3. Ask which input parameters will be optimized and the exact ranges. |
| 24 | 4. Create or update a tester `.ini` under `MQL5\config\`. |
| 25 | 5. Put the optimization ranges inside a `[TesterInputs]` section in that `.ini`. |
| 26 | 6. Create `MQL5\backtest\reports\` if missing. |
| 27 | 7. If MT5 is already running, close it before launch. |
| 28 | 8. Launch MT5 with the generated `.ini`. |
| 29 | 9. Read terminal and tester logs to confirm the optimization really started and finished. |
| 30 | 10. Read the exported optimization XML and summarize the best passes. |
| 31 | |
| 32 | ## Critical local rule |
| 33 | |
| 34 | In this workspace, command-line optimization works when the parameter ranges are defined in `[TesterInputs]` inside the tester `.ini`. |
| 35 | |
| 36 | Do not rely on `ExpertParameters=...set` for optimization ranges here. That produced the tester error: |
| 37 | `no optimized parameter selected, please check input(s) to be optimized and set start, step and stop values` |
| 38 | |
| 39 | ## Tester ini pattern |
| 40 | |
| 41 | Use this structure: |
| 42 | |
| 43 | ```ini |
| 44 | [Tester] |
| 45 | Expert=codex\RSICrossTrader.ex5 |
| 46 | Symbol=GBPUSD |
| 47 | Period=M15 |
| 48 | Model=4 |
| 49 | Optimization=1 |
| 50 | FromDate=2026.02.28 |
| 51 | ToDate=2026.03.28 |
| 52 | ForwardMode=0 |
| 53 | Deposit=100000 |
| 54 | Currency=USD |
| 55 | Leverage=1:100 |
| 56 | ExecutionMode=0 |
| 57 | OptimizationCriterion=0 |
| 58 | Visual=0 |
| 59 | Report=MQL5\backtest\reports\report_name |
| 60 | ReplaceReport=1 |
| 61 | ShutdownTerminal=1 |
| 62 | UseLocal=1 |
| 63 | UseRemote=0 |
| 64 | UseCloud=0 |
| 65 | |
| 66 | [TesterInputs] |
| 67 | InpRSIPeriod=4||4||1||4||N |
| 68 | InpRSIPrice=1||1||0||7||N |
| 69 | InpBuyLevel=30.0||30.0||3.000000||300.000000||N |
| 70 | InpSellLevel=70.0||70.0||7.000000||700.000000||N |
| 71 | InpLots=0.01||0.01||0.001000||0.100000||N |
| 72 | InpStopLossPoints=100||100||10||120||Y |
| 73 | InpTakeProfitPoints=100||100||10||120||Y |
| 74 | InpMagicNumber=20260328||20260328||1||202603280||N |
| 75 | InpOnePositionPerSymbol=true||false||0||true||N |
| 76 | ``` |
| 77 | |
| 78 | ## Input range format |
| 79 | |
| 80 | Use MT5 optimization format: |
| 81 | |
| 82 | ```text |
| 83 | ParameterName=current||start||step||stop||selected |
| 84 | ``` |
| 85 | |
| 86 | Rules: |
| 87 | - Use `Y` only for parameters being optimized. |
| 88 | - Use `N` for fixed parameters. |
| 89 | - Keep the current value equal to the chosen start value unless there is a reason not to. |
| 90 | - Preserve the parameter names exactly as declared in the EA inputs. |
| 91 | |
| 92 | Example: |
| 93 | |
| 94 | ```text |
| 95 | InpStopLossPoints=100||100||10||120||Y |
| 96 | InpTakeProfitPoints=100||100||10||120||Y |
| 97 | ``` |
| 98 | |
| 99 | ## Path rules |
| 100 | |
| 101 | - Write `Expert=` relative to `MQL5\Experts\`. Use `codex\RSICrossTrader.ex5`, not `Experts\codex\RSICrossTrader.ex5`. |
| 102 | - Write the tester `.ini` under `MQL5\config\`. |
| 103 | - Export reports to `MQL5\backtest\reports\report_name`. |
| 104 | - Optimization exports a readable XML workbook. Use that XML as the primary source. |
| 105 | |
| 106 | ## Launch command |
| 107 | |
| 108 | Use this command pattern: |
| 109 | |
| 110 | ```powershell |
| 111 | Start-Process -FilePath 'C:\Program Files\MetaTrader 5\terminal64.exe' -ArgumentList '/config:C:\Users\<user-id>\AppData\Roaming\MetaQuotes\Terminal\<terminal-id>\MQL5\config\your-optimization.ini' -Wait |
| 112 | ``` |
| 113 | |
| 114 | Before launching, close any existing MT5 process. Otherwise the tester may not run. |
| 115 | |
| 116 | ## Validation |
| 117 | |
| 118 | Read these logs after launch: |
| 119 | |
| 120 | - `Terminal\...\logs\YYYYMMDD.log` |
| 121 | - `Terminal\...\tester\logs\YYYYMMDD.log` |
| 122 | |
| 123 | Treat these tester log lines as authoritative: |
| 124 | |
| 125 | - Start confirmed: `complete optimization started` |
| 126 | - Success confirmed: `optimization finished, total passes N` |
| 127 | - Broken config: `no optimized parameter selected` |
| 128 | |
| 129 | If the optimization did not start, inspect the `.ini` and especially `[TesterInputs]` before retrying. |
| 130 | |
| 131 | ## Reading the report |
| 132 | |
| 133 | Optimization results are exported as an XML workbook under `MQL5\backtest\reports\`. |
| 134 | |
| 135 | Read that XML and extract at least: |
| 136 | - Pass |
| 137 | - Result |
| 138 | - Profit |
| 139 | - Profit Factor |
| 140 | - Equity DD % |
| 141 | - Trades |
| 142 | - All optimized input columns, such as `InpStopLossPoints` and `InpTakeProfitPoints` |
| 143 | |
| 144 | Summarize: |
| 145 | - The best combination |
| 146 | - The top ranking passes |
| 147 | - The report path used |
| 148 | - Whether the optimization finished successfully |
| 149 | |
| 150 | ## Example from this workspace |
| 151 | |
| 152 | This exact optimization was validated successfully: |
| 153 | - Expert: `codex\RSICrossTrader.ex5` |
| 154 | - Symbol: `GBPUSD` |
| 155 | - Period: `M15` |
| 156 | - Dates: `2026.02.28` to `2026.03.28` |
| 157 | - Mo |