Writing an Expert Advisor used to mean learning a C-like language, memorising the trade server's quirks, and spending a weekend on error handling before you saw a single order. That barrier is mostly gone. A language model that has read the MQL5 reference can produce a compiling EA from a sentence, provided the sentence is specific enough and the generated code is checked in the right places.
What a good strategy sentence looks like
The quality of the output tracks the quality of the input almost linearly. "Make me a profitable gold robot" produces nonsense, because it contains no decision rule. A sentence that works names five things: the instrument, the timeframe, the entry condition, the stop placement, and the exit.
Compare these two. The first is a wish: "a scalping EA for gold". The second is a specification: "On XAUUSD M5, go long when the 20 EMA crosses above the 50 EMA and price is above the 200 EMA; stop loss 1.5x ATR(14) below entry; take profit at 2R; close everything at 21:00 server time; risk 0.5% per trade." The second one compiles into something you can actually test, because every branch has a defined answer.
How the generation actually works
The model emits a standard MQL5 skeleton: property directives, input parameters, an OnInit that validates settings, an OnTick that evaluates the rule, and helper functions for lot sizing and order sending. Indicator handles are created once in OnInit and read with CopyBuffer on each tick — the correct pattern, and the one most hand-written EAs get wrong by calling iMA inside OnTick and leaking handles until the terminal slows to a crawl.
Risk sizing is where generated code earns its keep. A proper implementation reads SYMBOL_TRADE_TICK_VALUE, SYMBOL_TRADE_TICK_SIZE and SYMBOL_VOLUME_STEP, converts your percentage risk into a distance in ticks, then rounds the result down to a valid lot and clamps it between the symbol's minimum and maximum. Hard-coding 0.01 lots looks fine on a demo and blows up on a $50,000 account.
The five things to check before you compile
Filling mode. Every broker accepts a different set of fill policies. If the EA hard-codes ORDER_FILLING_FOK and the broker only allows IOC, every order fails with retcode 10030. Good generated code detects the symbol's allowed modes and picks one.
Stops level. Brokers enforce a minimum distance between price and stop. If your 1.5x ATR stop lands inside that band the order is rejected with 10016. The EA must read SYMBOL_TRADE_STOPS_LEVEL and widen the stop if necessary.
Freeze level and expiry. Pending orders need an expiry that respects the broker's minimum distance from the current time, and a freeze level that keeps modification legal.
Magic number and comment. A unique magic number is how the EA recognises its own trades. Without it, two EAs on the same account will fight over each other's positions, closing trades they never opened.
Server time. Session filters must use TimeCurrent(), not local time. An EA that thinks it is closing at 21:00 will actually close at whatever the broker's GMT offset makes that, and the difference is often three hours.
Compile, then backtest, then distrust the backtest
Drop the .mq5 file into MQL5/Experts, press F7 in MetaEditor, and fix anything the compiler flags — usually a missing include or a type mismatch on a lot size. Then run the Strategy Tester on "every tick based on real ticks" for at least a year, with a spread that matches your broker rather than the tester's default.
A generated EA that shows a beautiful equity curve is the most dangerous artifact in this whole workflow. Check the trade count first: under 50 trades and the result is noise. Check the maximum drawdown relative to your risk setting: if 0.5% risk produces 30% drawdown, the stop logic is not doing what the sentence asked. Then run it on a different six-month window. Strategies that only work in one period were fitted to that period, whether a human or a model wrote them.
Where generation genuinely saves time
Not in inventing edges — that is still your job. It saves time in the unglamorous middle: translating a rule you already trust into code, adding the order-management plumbing, writing the trailing stop you keep putting off, and producing a readable version you can hand to someone else. That is several days of work compressed into a few minutes, and the output is a file you own, compile yourself and can edit by hand afterwards.
Put this into practice
MetaSync AI connects MetaTrader 5 and cTrader accounts, generates MQL5 Expert Advisors and executes strategies from one console.
Open the terminal More articles →