从零写出你自己的 MT5 EA
一门用 MQL5 编写 MT5 EA 的课程,从第一个 OnTick 讲到能自己管理风险、自己上报成绩的系统。每一课的结尾都对应一个真正在跑的 EA,代码和回测全部公开。
- 按顺序读。每一课都建立在上一课的基础上。
- 进入下一课之前,先把这一课的代码编译并跑一遍——只看 MQL5 学不到什么。
- 如果某一课的结尾用到我们的 EA,它的实盘成绩和回测都在一步之内,包括没通过的那些。
- 研究日志: 这门课的方法,每周实际应用的记录。
-
01Your First EA Places No Trades
Your first Expert Advisor should read the market and publish what it thinks — nothing more. Build the signal-only EA that fills our signals page, from its real source, and learn why every read uses the last closed bar.
-
02One File Decides, Another File Acts
Where you draw the line between deciding and trading is the most consequential decision in an EA. A strategy module you can call with plain numbers, a verdict that explains itself — and the failed strategy that proved it was worth it.
-
03The Numbers Are Not in the Code
A backtest belongs to a set of values, not to the source that produced it. Input schemas, three kinds of version, why every number should carry its reason, and the .set file format trap that turns generated presets into junk.
-
04Every Failure Must Fail Toward Zero
Sizing is the only code in an EA that can end the account in one order. Lot size from real tick values, why risk-based sizing must refuse rather than round up, the floating-point bug that eats a whole volume step, and what happens when the broker widens the stop you already sized for.
-
05A Bad Day Is Not a Bad Strategy
Three layers decide whether an EA may trade at all, watching three different lengths of time: this bar, today, and this quarter. Session and spread gates, account-level caps that count currencies rather than symbols, and the rolling profit factor that notices when a regime edge stops working.
-
06A Backtest Is Not Evidence
The MT5 strategy tester will always find settings that would have worked. The nine-rule gate we run our own presets through, the two rules we had to add after our own results slipped past the first seven, and why every rejected tune stays published.
-
07The Track Record Starts at One
Live is the one window you cannot re-run or retune. The bug that made every backtest run a different program, a reporting pipeline that cannot lose a trade, the divergences nobody warns you about — and our own record, published from its first trade rather than its thirtieth.
-
08Retuning Is Not Diagnosis
When a result disappoints, the optimiser will always find better parameters — which is why it is the wrong first move. Measurement artifacts, clock assumptions, control arms, improvements that are only leverage, and the case where the losses are the mechanism.
-
09Do Not Test This Again
Pairs, sessions and timeframes are finite sets, and finishing one is a result. How a timeframe curve tells you the axis is closed, how four studies of scheduled events composed into a single rule, and why a rejection note should say what would have to change before you test it again.
-
10What We Actually Know
The balance sheet after nine modules of method: one mechanism edge across four pairs, four instances explicitly labelled weaker, eighteen rejections, a kill switch that trims rather than rescues, and the list of things we still do not know.