Loading…

Optimisation Friendly Input Template

The genetic optimiser treats every plain `input` as a dimension of its search space. An EA written with fifteen loose inputs - retry counts, magic numbers, slippage tolerance mixed in alongside the actual strategy parameters - hands the optimiser a search space many times larger than the strategy needs, and generations get spent exploring combinations of settings that were never meant to vary between runs. This template fixes that structurally rather than by convention: the genuinely optimisable parameters (moving average lengths, stop and target distance) are declared with `input`, and everything that must stay constant across every run in a batch (lot size, magic number, slippage, retry policy) is declared with `sinput`, which MT4's optimiser never includes in its parameter grid at all. The distinction is enforced by the compiler, not just documented in a comment. It also implements OnTester(), returning net return divided by the run's own maximum drawdown rather than raw profit. Ranking optimisation results by profit alone rewards the single highest-variance lucky run in the batch - exactly the mechanism by which a genetic optimisation quietly curve-fits itself onto a parameter set that dies in its first real drawdown. A trading signal (a plain EMA cross) is included so the template compiles into something that actually runs end to end in the tester rather than being an empty shell with nothing to optimise. Notes and limitations The bundled EMA cross signal is a working placeholder, not a strategy worth optimising on its own merits - replace it before drawing conclusions from an optimisation run. The custom criterion falls back to plain net return when a run records negligible drawdown, since dividing by a near-zero drawdown would produce a meaningless, unbounded score.

Expert advisor · MT4 · v1.0 · Free

About Optimisation Friendly Input Template

Optimisation Friendly Input Template is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average. It has 9 settings, such as Fast ma period, Slow ma period and Stop loss pips. MQL source code included.

Files in the download: OptimisationTemplate.ex4, OptimisationTemplate.mq4, OptimisationTemplate.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Fast ma period10Fast EMA period - a real optimisation candidate
Slow ma period30Slow EMA period - a real optimisation candidate
Stop loss pips30Stop loss, in pips - a real optimisation candidate
Take profit pips45Take profit, in pips - a real optimisation candidate
Lots0.01Fixed lot size - constant across every optimisation run
Magic number20261209Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds

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 → Experts.
  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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Moving Average · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria