Loading…

Attach Time Smoke Tests

Most EAs either skip readiness checking entirely (and fail confusingly on the first tick with no clear reason why) or hand-roll a handful of ad-hoc checks inline inside OnInit(), scattered among other setup logic. This header separates "what to check" from "how to report it": each check is one function that runs a single readiness condition, records a pass/fail plus a human-readable detail string into a shared registry, and returns the bool immediately so calling code can branch on it right away if needed. SmokeTestRunStandard() bundles five checks that cover the readiness gaps that bite nearly every EA or indicator at attach time: AutoTrading enabled, the symbol actually selectable and tradable (not just "exists"), enough bar history loaded for the strategy's lookback, the current spread within a sane cap, and enough free margin. The registry is additive - a project can call SmokeTestRunStandard() first and then add its own SmokeTestRecord() or SmokeCheckXxx() calls for strategy-specific conditions, all appearing together in one final report from SmokeTestReportPrint(). The demo shows exactly that pattern: it runs the standard bundle against the current chart's symbol, then adds one made-up project- specific check (MODE_DIGITS in a sane range) with an ordinary SmokeTestRecord() call - no change to the header itself needed to extend the check list for a specific project's own rules. Notes and limitations - The registry is capped at 64 entries (SMOKETEST_MAX_RESULTS), well above what a realistic attach-time bundle needs. - SmokeCheckSpreadReasonable() fails on a spread of exactly 0 as well as one above the cap - a reported spread of 0 usually means the symbol has not received a fresh quote yet, not that the spread is genuinely free, so it is treated as not-yet-ready rather than a pass. - These are attach-time snapshot checks, not continuous monitoring - they answer "is it safe to START now", not "is it still safe five minutes from now". A spread or margin check that passed on attach can still change afterward; re-run relevant checks inside OnTick() if ongoing monitoring is actually needed. - SmokeCheckSymbolTradable() calls SymbolSelect(symbol, true), which can trigger a brief history/quote sync on a symbol not already in Market Watch - the same readiness gap this check exists to surface.

Script · MT5 · v1.0 · Free

About Attach Time Smoke Tests

Attach Time Smoke Tests is a script for MetaTrader 5. It has 3 settings, such as Min bars, Max spread points and Min free margin. MQL source code included.

Files in the download: AttachTimeSmokeTests.mq5.mqh, AttachTimeSmokeTests.txt, AttachTimeSmokeTestsDemo.ex5, AttachTimeSmokeTestsDemo.mq5.

Settings

SettingDefaultWhat it does
Min bars100Minimum bars of history required before this "tool" would start acting
Max spread points300Refuse readiness if the current spread is wider than this many points
Min free margin0.0Minimum free margin required, 0 = no requirement for this demo

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria