Ranar Algo Blog

Guides on building & backtesting MetaTrader EAs.

2026-11-06

How to Move Stop Loss to Breakeven in MQL5 (EA Code + Real Backtest)

Move an MQL5 position's stop loss to breakeven once it is N points in profit using CTrade::PositionModify, with stops-level checks, full EA code and a real MT5 backtest comparison.

Read →
2026-11-03

MQL5 Error 10030 Unsupported Filling Mode: How to Fix It (EA Code + Real Backtest)

Fix MQL5 OrderSend error 10030 (TRADE_RETCODE_INVALID_FILL) by reading SYMBOL_FILLING_MODE and picking FOK, IOC or RETURN per symbol. Full EA code and a real MT5 backtest.

Read →
2026-10-30

How to Add a Spread Filter to an MQL5 EA (Points vs Pips)

Add an entry-only spread filter to an MQL5 Expert Advisor using SymbolInfoTick. Understand points vs pips, protect exits, and test threshold behavior.

Read →
2026-10-27

How to Add a Trading Hours (Session) Filter to an MQL5 EA (Code + Real Backtest)

Restrict an MQL5 Expert Advisor to set trading hours: TimeCurrent with MqlDateTime, midnight-crossing windows, weekend/Friday skips, closing outside the session — plus a real MT5 backtest with and without the filter.

Read →
2026-10-24

How to Calculate Lot Size by Risk Percentage in MQL5 (EA Code + Real Backtest)

Size MQL5 positions so a stop-loss hit costs a fixed % of balance: OrderCalcProfit for loss per lot, then round down to SYMBOL_VOLUME_STEP. Full EA code and a real backtest.

Read →
2026-10-20

MQL5 CopyBuffer Returns -1: Fix Error 4806 and Read Closed Bars

Diagnose MQL5 CopyBuffer error 4806 with handle checks, BarsCalculated, exact-copy validation, and correct closed-bar array ordering.

Read →
2026-10-13

How to Code an ATR Trailing Stop in MQL5 (Full EA Example + Real Backtest)

A compiling MQL5 Expert Advisor with an ATR-based initial and trailing stop loss: iATR handle, CopyBuffer on closed bars, CTrade.PositionModify, the SYMBOL_TRADE_STOPS_LEVEL check, and a real MT5 backtest of the exact code.

Read →
2026-10-06

How to Code a MACD EA in MQL5 (Signal Line Crossover Example + Real Backtest)

A complete, compiling MQL5 MACD signal-line crossover Expert Advisor — correct iMACD buffers, new-bar detection, CTrade with SetTypeFillingBySymbol, and a real MetaTrader 5 Strategy Tester backtest of the exact code.

Read →
2026-09-29

How to Code a Bollinger Bands EA in MQL5 (Mean-Reversion Example + Real Backtest)

A complete, compiling MQL5 Bollinger Bands mean-reversion Expert Advisor — iBands handle, the 0/1/2 buffer order, new-bar detection, close-back-inside-the-band entries with a middle-line exit via CTrade — plus a real MetaTrader 5 Strategy Tester backtest of the exact code.

Read →
2026-09-22

How to Code an RSI EA in MQL5 (Full Example + Real Backtest)

A complete, compiling MQL5 RSI mean-reversion Expert Advisor — iRSI handle, CopyBuffer, new-bar detection, RSI cross entries with SL/TP via CTrade — plus a real MetaTrader 5 Strategy Tester backtest of the exact code.

Read →
2026-09-15

How to Convert a TradingView Pine Script Strategy to MetaTrader 5 (MQL5)

A practical Pine Script to MQL5 translation guide: indicator handles, CTrade order placement, new-bar timing, and a compiling EMA cross + RSI filter example — plus a real MetaTrader 5 Strategy Tester backtest of the exact code.

Read →
2026-09-13

How to Code an EMA Crossover EA in MQL5 (Full Example + Backtest)

A complete, compiling MQL5 EMA crossover Expert Advisor — indicator handles, CopyBuffer, new-bar detection, CTrade order placement — plus a real MetaTrader 5 backtest of the exact code.

Read →
2026-09-13

Why AI-Generated MQL5 Won't Compile (and How to Fix It)

The five most common reasons ChatGPT-style MQL5 Expert Advisors fail to compile in MetaEditor — MQL4 syntax, indicator handles, new-bar detection, order filling, and array indexing — with fixes.

Read →