Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Access the CodeBase from your MetaTrader 5 terminal
Couldn't find the right code? Order it in the Freelance section
How to Write an Expert Advisor or an Indicator

MQL4 and MQL5 Source Code Library

icon

You don't know where to start learning the MQL5 or MQL4 programming language? Various programs for your MetaTrader terminal are available here. Download and study published code examples, develop your own indicators and Expert Advisors. Publish your applications in the largest library of MQL5 and MQL4 codes, and they will be available in every MetaTrader terminal and MetaEditor.

Your code examples in MQL4 and MQL5 will be distributed worldwide, and thousands of traders will know about you!

Submit your code

A high-precision trend filter combining EMA dynamic momentum with ATR volatility bounds to pinpoint high-probability entries.

Dynamic Exponential Moving Average crossover Expert Advisor featuring volatility-based ATR Stop Loss/Take Profit and automatic account risk percentage position sizing.

Trend-following Expert Advisor for MetaTrader 5 combining Supertrend direction with ADX and DI confirmation. Uses an ATR-based stop loss and risks up to 0.5% of equity per trade.

Marks impulse candles: body at least ATR x multiplier, body at least a set share of the candle range, close near the extreme, optional tick volume confirmation. Green arrow below a bullish impulse, red above a bearish one. Closed bars only, no repainting. Signals are in the two buffers so an Expert Advisor can read them with iCustom.

Account level risk guard for prop firm accounts. One copy on any chart watches every position on the account, closes everything when the daily loss or maximum loss limit is hit, caps lot size and can flatten around high impact news. Logs every action to the Experts tab and a CSV.

Draggable on-chart manual trading panel with multi-timeframe bias, ATR SL/TP hints, a trailing stop and one-click BUY/SELL/CLOSE ALL.

Open-source MT5 indicator for confirmed market structure, volumetric order blocks and estimated buy/sell activity.

Marks swing highs and lows only after N closed bars have confirmed them, so a drawn swing never moves or disappears.

Turtle-style Donchian breakouts on gold, followed with three exits at once: an ATR trailing stop, the Turtle exit channel and a fixed target. Backtested on XAUUSD H1 and H4 in 2025 and 2026, where all twelve combinations were profitable. Non-repainting, with buffers for an Expert Advisor.

A Turtle-style breakout EA for gold. It buys when an H4 bar closes above the 20-bar high in an uptrend, with a 2 ATR stop and a 2R target. Backtested on XAUUSD from January 2020 to September 2026: +9,029.72 on 10,000 at 1% risk, profit factor 1.77, max drawdown 11.38%, 6 of 7 years profitable.

Finds the weekend CME gap on gold and on 24/7 Bitcoin charts, keeps every unfilled gap on the chart until price returns to it, and shows how often gaps filled, how fast, how far price ran first, and what fading them would have made. Non-repainting, with buffers for an Expert Advisor.

Posts your MT5 opens and closes to a Telegram chat: side, symbol, entry, stop and target in pips, lots, and on close the result, pips, R-multiple and time held. Retry queue, restart-safe, never trades. Free version of Trade Reporter Telegram and Discord.

MQL5 port of a Pine Script ATR trailing-stop indicator: nLoss = ATR-multiple, the stop ratchets under price in an uptrend and over price in a downtrend, and flips (with a buy/sell arrow) when price closes through it. Includes a Python reference port and a parity test that checks both agree with a literal, bar-by-bar transcription of the Pine semantics (na/nz/series history).

A small demo Expert Advisor: EMA fast/slow cross entries (evaluated on closed bars only, no repainting), ATR-based stop-loss and take-profit, spread filter, and position handling that works on both hedging and netting accounts. Includes a Python reference implementation for parity testing. This is a deliverable example, not a trading recommendation - the attached equity curve is from synthetic data and shows the method, not an edge.

Time weighted average price of the running session, anchored at the cash open of Frankfurt, London, New York or Tokyo with automatic daylight saving. Every second counts the same, minutes without a tick carry the last price, and two bands show the time weighted standard deviation around the line.

Panel that samples the spread once per second and shows it in points and in the symbol's natural unit (pips on FX, index points on index CFDs), with rolling min/avg/median/max, a session statistic since server midnight, the spread as percent of ATR, a hold-time alert and an optional CSV log. It never sends an order.

Marks the Asian session range, signals when London or New York sweeps one side of it and reverses, and keeps a scorecard of how every past signal ended in R, spread included. Non-repainting, with buffers ready for an Expert Advisor.

An intraday Smart Money Concepts EA for gold. It waits for price to sweep a recent swing high or low, confirms the reversal with a close through the sweep candle's body, and trades only with the H1 trend. Backtested on XAUUSD M15 over 2025 and 2026 at 1% risk per trade.

Free risk-based position size calculator built specifically for Gold (XAUUSD). Enter your account balance, risk percentage, entry price and stop-loss price - the indicator calculates the exact lot size, risk amount, stop distance, risk/reward ratio and potential profit, and draws entry, stop and take-profit lines on the chart. Contract size is read automatically from the symbol specification, so it works on any gold symbol without manual setup.

Hull Moving Average indicator displaying four periods on a single chart, colour-coded by direction (green for rising, red for falling, grey for flat). Implemented with a ring buffer and incremental running-sum math, so memory and CPU use remain constant regardless of chart history length. Buffer layout is documented and stable, making the indicator suitable for use with iCustom() from EAs. Supports 2, 3, or 4 Hull lines depending on configuration.

Protect Your Funded Account with Institutional-Grade Risk Monitoring. The #1 reason traders fail prop firm challenges is not a bad strategy; it is breaching daily drawdown limits. The AlphaQuant Prop Firm Daily Drawdown Dashboard is a free, high-visibility Expert Advisor

A real economic-calendar news filter that also works in backtests. Export the events once with a script, then block new entries around news both live and in the Strategy Tester. Fixes the one-hour DST shift of historical calendar times.

Educational MT5 hedging-account trade panel with risk sizing, spread protection, a persistent daily-loss lock, break-even and trailing stops.

TREND Follower (Daily) is a lightweight, development-oriented Expert Advisor (EA) created as a base trading architecture for research, learning, experimentation, and further development. The EA is intentionally designed around a simple concept: follow the market direction using the relationship between price and the Parabolic SAR. It is not presented as a fully optimized or finished trading system. Instead, it provides a clean and accessible foundation that developers can study, modify, test, and expand.

Account-wide MT5 risk protection EA for prop-firm and personal accounts. Monitors daily and overall drawdown, position losses, safety buffers, and automatically protects the account when configured limits are reached.

Spread histogram in a sub-window with current/avg/max/min stats, cost per trade, and threshold alerts for scalpers.

Educational MT5 EA: closed-bar EMA crossover entries, ATR-based stop loss and take profit, lot size from a fixed percent of equity via OrderCalcProfit, spread filter, magic-number isolation and server return-code checks. A clean template for building risk-controlled EAs. No profit claim.

Numbers every candle of the current trading day starting at the cash open of Frankfurt, London, New York or Tokyo. The anchor is converted from exchange local time to broker server time with automatic daylight saving, so the first candle after the open is always number one, in summer and in winter.

Professional Utility EA for prop firm risk management. It features daily equity monitoring, phased mitigation of losing positions, and absolute hard stops via a self-healing graphical dashboard.

Works out the lot from your risk percent and the stop distance, then opens the trade with the stop loss and take profit already attached. Never trades by itself.

Classifies the market with ADX, the Hurst exponent and lag-1 autocorrelation, routes each bar to a breakout module or a mean-reversion module, and keeps a separate win rate ledger for each regime with a Wilson 95% lower bound, so you can see which half of it is actually working.

Scores every setup type in your EA on its own record instead of lumping them into one equity curve. Rebuilds itself from the account's deal history on init so a restart cannot wipe the record. Prints a Wilson score lower bound next to the raw win rate so a three trade hot streak stops looking like an edge.

Position size from a risk amount, computed from the symbol's real tick value, tick size and volume step rather than an assumed pip value. It always rounds volume down, and when your risk is smaller than the minimum lot it says so and reports what that lot actually costs. No terminal state, so the sizing logic is testable offline - a 41-assertion test script is included.

Heiken Ashi ATR Blend combines smoothed Heiken Ashi candles, ATR-based volatility filtering, and fast/slow EMA trend confirmation to identify potential trend-change signals.

Closes losing positions early, before the full stop-loss, when a rule says the trade is not coming back: adverse move beyond N x ATR, too long in loss, EMA trend flipped, RSI against the position, or a money cap. Never touches a position in profit. Observe-only mode journals what would be closed without closing anything. Every exit is written to CSV with the rule, the age and the maximum adverse excursion, so the rules can be tuned from data.

Enforces your own risk rules on every position, whether opened by hand or by another EA: shows the lot size that matches your risk, locks the account for the day after a set loss, caps open positions, trims positions that risk more than allowed, and adds a stop-loss to any position opened without one.

Strict risk management utility for prop-firm challenges. Automatically monitors your entire account to prevent daily and max drawdown failures. It acts as a safety buffer against spread spikes and revenge trading by instantly closing all positions and pending orders before your evaluation is terminated.

Free MT5 position risk monitor displaying stop-loss risk, account risk percentage, positions without SL and individual position risk directly on the chart.

Free neon-style MT5 account dashboard displaying balance, equity, floating P/L, daily realized P/L, win rate and open positions directly on the chart.

GDS Renko Canvas + Donchian is a compact educational indicator for MetaTrader 5. It renders classic fixed-size Renko bricks on a single CCanvas bitmap layer and overlays a Donchian Channel calculated directly from completed Renko bricks. The horizontal axis represents Renko sequence rather than time. The internal builder uses incoming BID ticks and the classic two-brick reversal rule. The Donchian Channel is causal: for each newly completed brick, the channel is calculated from the previous N completed Renko bricks only. The current brick is excluded from its own channel calculation.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207