Loading…

Search Harness With Result Store

Sweeping a strategy's parameters usually means two separate, easy-to-get-wrong problems bolted together: enumerating the candidate points, and remembering which ones have already been tested. This library solves both without ever calling your objective function itself - MQL4 has no safe function-pointer callback for a reusable library build, so instead it hands you the next candidate parameter vector (a specific grid cell, or a random draw), you evaluate your own strategy at that point, and you hand the score back for it to store. Every evaluation is appended to a plain-text file as one row of "index,score,p0,p1,...". That file is the actual persistence layer: a sweep that gets interrupted, or a script that runs once per day and adds a batch of new draws, can reload it, find the best row so far, and - for random search - skip any new draw that lands within a chosen tolerance of a point already on file, so a slow, expensive backtest per evaluation is never repeated for a point you already have an answer for. Grid enumeration uses mixed-radix decoding against a per-dimension step count, so point number N can be produced directly (useful for resuming a grid at exactly the row count already on file) rather than only by iterating from zero. Notes and limitations Result files live in the sandboxed MQL4\Files\ (or MQL5\Files\ on the native MQL5 build) folder, like every MQL4 file operation - there is no way to write the log anywhere else. The store keeps every row ever appended; it never rewrites or compacts the file, so a very long-running sweep produces a proportionally large text file. Rotate or archive the file yourself between unrelated sweeps. SearchHarnessAlreadyEvaluated and SearchHarnessLoadBest both do a full linear scan of the file on every call, since MQL4 has no lightweight indexed file format available in the sandbox. Fine for the thousands-of-rows scale a manual or slow-backtest sweep produces; not intended for a tight inner loop scanning millions of rows per tick. Grid search assumes every dimension's (max-min)/step is close to a whole number; a wildly inexact ratio gets rounded to the nearest integer step count, so the last grid point per dimension may fall slightly short of max. Random search never reseeds MathRand() itself - call MathSrand() yourself before a batch of draws if you want a reproducible sequence across runs.

Script · MT4 · v1.0 · Free

About Search Harness With Result Store

Search Harness With Result Store is a script for MetaTrader 4. It has 1 setting, such as Random draws. MQL source code included.

Files in the download: SearchHarness.mqh, SearchHarness.txt, SearchHarnessDemo.mq4.

Settings

SettingDefaultWhat it does
Random draws15Number of random search draws to run

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Grid · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria