Preset Sanity Linter
A downloaded .set preset file is normally trusted without question - the values just get read into inputs and used. A preset built for a different symbol's tick size, or one where TrailingEnabled=1 sits alongside StopLossPips=0 (nothing for the trail to trail from), compiles and runs fine right up until it does something nobody intended. This header expresses those constraints once, as data, instead of as a wall of if-statements duplicated inside every EA that wants to validate its own presets. Two rule types cover the common cases: PresetRangeRule (a named parameter must stay within a min, and optionally a max), and PresetExclusionRule (when parameter A equals a trigger value, parameter B must not equal a forbidden value - either condition alone is fine, only the combination is a violation). PresetLintAll() runs both rule families against a preset and returns every issue found, not just the first one, so a bad preset shows its whole problem list in one pass rather than one fix-and-rerun cycle per issue. The demo builds a small preset that looks plausible at a glance - a lot size, a stop loss, a take profit, a trailing-stop flag, a risk percentage - but breaks two declared rules: the lot size is below a typical broker minimum, and trailing is enabled with no stop loss for it to trail from. Both are caught and reported by name. Notes and limitations - Parameters are matched by exact name string; a typo in a rule's ParamName simply means that rule never fires (silently, since the parameter "doesn't exist" from the rule's point of view) rather than raising an error - double-check rule names against the preset's parameter names. - Numeric comparisons use a small epsilon (0.0000001) for equality checks in exclusion rules, to avoid floating-point representation issues causing a trigger value to be missed by a fraction. - A PresetRangeRule with Max < Min is treated as "no upper bound" by design, not as an error - this lets one rule type express both one-sided and two-sided constraints. - This lints VALUES only. It has no knowledge of what a parameter actually does; the rules themselves (what counts as a valid range, which combinations conflict) must be declared by whoever knows the EA's own logic.
Script · MT4 · v1.0 · Free
About Preset Sanity Linter
Preset Sanity Linter is a script for MetaTrader 4. It has 5 settings, such as Preset lots, Preset stop loss pips and Preset take profit pips. MQL source code included.
Files in the download: PresetSanityLinter.mqh, PresetSanityLinter.txt, PresetSanityLinterDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Preset lots | 0.001 | Deliberately below a typical 0.01 minimum lot, to trigger the range rule |
| Preset stop loss pips | 0.0 | Deliberately zero, to trigger the exclusion rule below alongside trailing |
| Preset take profit pips | 40.0 | Take profit distance |
| Preset trailing enabled | 1.0 | 1 = on. Combined with StopLossPips=0 this should be flagged |
| Preset risk percent | 2.0 | Risk per trade (percent of balance) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Trailing Stop & Break-even · MT4 Script · MQL4 Source Code