Large language models are great at sketching a trading idea, but paste their MQL5 into MetaEditor and it often won't compile. Here are the five failures we see most, and how to fix each.
The classic tell is a single-line indicator call with a shift argument, e.g. iMA(_Symbol, 0, 14, 0, MODE_EMA, PRICE_CLOSE, 0) used directly in a comparison. That is MQL4. In MQL5 you create a handle once, then copy values.
MQL5 indicators are handle-based. Create the handle in OnInit, read it with CopyBuffer in OnTick, and release it in OnDeinit.
int emaHandle;
int OnInit(){ emaHandle = iMA(_Symbol, _Period, 200, 0, MODE_EMA, PRICE_CLOSE); return INIT_SUCCEEDED; }
void OnTick(){
double ema[]; ArraySetAsSeries(ema, true);
if(CopyBuffer(emaHandle, 0, 0, 2, ema) < 2) return;
// use ema[0], ema[1]
}
void OnDeinit(const int r){ IndicatorRelease(emaHandle); }
Without it, the EA acts on every tick and fires dozens of orders per bar. Guard on the bar time:
datetime lastBar = 0;
bool NewBar(){ datetime t = iTime(_Symbol, _Period, 0); if(t == lastBar) return false; lastBar = t; return true; }
OrderSend fails silently on some brokers if the filling mode is unsupported. Use CTrade from <Trade/Trade.mqh> and let it manage filling, or set type_filling to a mode the symbol allows.
MQL5 arrays are not series-indexed by default, so array[0] may be the oldest bar, not the newest. Call ArraySetAsSeries(arr, true) before you read [0] as "current".
Fixing these by hand is the slow part. Ranar Algo generates the MQL5 from a plain-English strategy, compiles it against real MetaEditor in a loop until it builds clean, then runs a real MetaTrader 5 Strategy Tester backtest — so you skip the compile-error churn. You keep your IP and download the source. It's still improving; feedback welcome.
Build & backtest your own EA free →