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

Look after open positions in an Expert Advisor: break-even, trailing stop, two partial closes, and a stop and target for positions that have none. It never opens a trade.

Checks the broker's session table against the M1 history. For every minute of the week it counts on how many of the last N days the symbol really has a bar, and sets that next to SymbolInfoSessionQuote and SymbolInfoSessionTrade: declared minutes that are usually empty (rollover holes), bars in minutes the table calls closed, trade and quote tables that disagree, and one-off outages such as an early holiday close. Prints the real sessions per weekday, writes every finding to CSV and prints its own arithmetic. Read only: no trade function, no DLL, no network.

A manual trading panel with a built-in prop-firm risk guard and a hidden Support/Resistance finder for MetaTrader 5.

A MetaTrader 5 utility that treats the bid and ask quote streams as two independent physical trajectories and fits a local quadratic to each, producing position, velocity, and acceleration with honest error bars and an out-of-sample forecast scoreboard.

Draws ICT structure on the chart (liquidity pools, sweeps, market structure shift, fair value gaps) from closed bars only, adds a trade plan for every confirmed setup and keeps an honest statistics panel of what those setups did on your symbol. Analysis only – it does not trade.

One panel for the rules of a prop firm challenge: daily loss, maximum loss (static or trailing), profit target, minimum trading days and the best-day (consistency) rule. For each one it shows how much is used and how much room is left, in money. "One more trade" tells you the largest lot size that still keeps a stop-out inside the room left today and in the max-loss room. Read-only: it never opens, changes or closes a trade. The presets hold typical values; firms change their rules, so check yours and use the Custom preset. Built on the ATS Risk Library (ATS_RiskLib.mqh, included).

A small include file for Expert Advisors and trade managers. It turns your risk rules into yes/no answers: how many lots does this stop allow, is the daily loss limit reached, is the maximum drawdown (static or trailing) reached, how much is at risk across all open positions, and are spread and session acceptable. The lot is never rounded up: if the broker minimum lot would risk more than allowed, the trade is skipped and the reason is returned. Limits survive a terminal restart. The library only measures: it sends no order. Includes a demo account guard (no trading by default) and a self-test with 78 checks.

The Trend BOSS Indicator identifies regimes such as trending, ranging or volatile using a Bag-of-SFA-Symbols (BOSS) classifier. Gate your strategies behind specific regimes or use the indicator to identify various market conditions.

Measures market activity from the waits between quotes. An ACD model with the daily rhythm removed gives one ratio per tick: 1 is normal, 2 twice as busy.

Extrapolator fits a sum of sinusoidal harmonics to the recent price history and extends the fitted curve to the right of the last bar as a forecast.The forecast is a mathematical extrapolation of past cyclical behaviour, not a guarantee of future price movement. The last part of the line is redrawn while the current model bar is forming, and the fitted curve changes with each refit.

A free, fully open JPN225 (Nikkei 225) EA for M15. Buys when price leans up, momentum isn't stretched and volume is quiet. Backtest 2022 to 2026: profit factor 1.68, +18.5% a year, passed 15 stress tests. Flat by 17:00.

Audits the tick history that 'Every tick based on real ticks' backtests replay. Five checks per symbol over the last N days: impossible and crossed quotes, timestamps that run backwards or repeat, one-tick price reversals sized in multiples of the symbol's own median spread, silences inside the broker's declared quote sessions, and minutes where the ticks and the M1 bars disagree. Every finding goes to CSV with its millisecond timestamp, and the tool prints its own arithmetic so the report can be recounted. Read only: no trade function, no DLL, no network.

A specified moment in time can be analyzed through multiple synced timeframes from 1 host chart for a symbol.

Opening Range Breakout EA template with built-in account protection. Marks the high and low of the first N minutes after the session open and places OCO stop orders above and below the range. Includes risk-based position sizing, daily loss limit, maximum drawdown limit, ATR range filter, trade direction filter, and protection against positions carried overnight. All session times are configurable inputs. Educational template, not a profit-guaranteed system. Test on demo before any live use.

Displays the symbol properties that cause the same EA to behave differently on a different broker: trading hours, contract size, tick value, spread statistics, swap cost and real-session coverage. Read-only; does not execute trades.

Exports closed trades to CSV with Maximum Adverse Excursion (MAE) and Maximum Favorable Excursion (MFE) in points and money, calculated from M1 history, plus the percentage of the available move each trade captured.

Opens charts for all Market Watch symbols or a custom symbol list in one click, on any timeframe, with an optional template applied to each chart. Skips charts that are already open and limits how many are opened at once.

Shades the chart background by volatility regime (Compression, Normal, Expansion) based on the percentile rank of the current ATR. Shows the current regime on the chart, alerts on regime changes and exposes buffers for Expert Advisors.

Shades the chart background by volatility regime (Compression, Normal, Expansion) based on the percentile rank of the current ATR. Shows the current regime on the chart, alerts on regime changes and exposes buffers for Expert Advisors.

Draws Asian, London and New York session range boxes and marks liquidity sweeps: a closed bar that wicks beyond a completed session's high or low and closes back inside. Non-repainting arrows, extended session levels, alerts and iCustom-ready buffers.

Writes a CSV journal of every trade with the exit reason, and a report that shows how far each trade ran, in R. It never trades.

ICT killzones for MetaTrader 5: Asia, London and New York sessions drawn in New York time with automatic daylight-saving conversion, session highs and lows carried forward until price takes them, previous day, week and month levels, opening prices and time markers. One file, no DLL.

Arixis Market Regime Map is a non-repainting MT5 indicator that classifies market conditions as Trend Up, Trend Down, Range or Transition using price efficiency, normalized slope, volatility, market structure and multi-horizon agreement.

Resamples your closed trades 10,000 times to show whether your average trade is an edge or could still be luck: the 95% range of the average and the chance it is below zero.

Shows the day's result against the daily and max loss limits of a prop firm account, with a warning alert, in a panel on the chart.

The Market Behavior Analyzer is a practical indicator designed to make market structure easier to read directly from the chart. It identifies significant swing points, classifies them as Higher Highs, Higher Lows, Lower Highs, and Lower Lows, and tracks the movement between them in pips. It also provides a Market Story panel and an interactive Swing Inspector for examining impulses, pullbacks, retracements, swing duration, and the developing market structure.

Audits the bar history your terminal actually holds, which is the history every backtest and every indicator reads. Six checks per symbol: impossible OHLC values, broken bar times, bars missing while the broker's own session table says it was quoting, empty and flat bars, bars that disagree with the broker's own M1 series, and spread sanity. The headline figure is session coverage, not a grid percentage that mostly measures how many weekends you audited. Every finding goes to CSV with its bar time, and the audited bars plus the session table can be dumped so the whole report can be recounted by something other than this tool.

Gold EA that trades both directions: when the stochastic signal line turns, it places a stop order at yesterday's high or low, filtered by a Bollinger band. Self-contained, no custom indicators. Backtest on XAUUSD H1, July 2021 to September 2026: +245% on a 1,000 USD deposit at a fixed 0.01 lot, 23.9% maximum equity drawdown.

Calculates position size and daily / max loss limits for prop firm accounts and shows them in a panel on the chart.

A port of the Olsen group's Alpha Engine: eight limit-order agents trade intrinsic-time directional changes on a hedging account. They add on overshoots and trim at a profit on reversals.

Mirrors trades opened, modified, and closed by another EA on the same hedging account, selected by magic number. By default it inverts direction (Buy↔Sell, SL↔TP), so you can forward-test the reverse of a strategy with real spreads, slippage, and execution.

A free open-source MT5 utility for analyzing historical trading performance beyond Profit Factor.

Shows where stops are likely resting and which ones were just taken. Liquidity pools = confirmed swing highs and lows that price has not traded through yet, equal highs/lows (a bigger pool) and yesterday's high and low. When a bar trades beyond a pool it is marked as swept, and as "grabbed & rejected" if the same bar closes back inside. Non-repainting: a swing is used only after N closed bars on each side. The panel is a neon city drawn on a CCanvas: the price is a flying car, sell stops are towers below it, buy stops floating platforms above it, yesterday's levels golden billboards, a searchlight sweeps the sky and a ticker runs today's catch. Two buffers give the nearest active pool above and below for use in an Expert Advisor. Indicator only: it never trades.

Measures whether an indicator repaints instead of trusting the claim. It re-reads the buffers of any custom indicator on bars that have already closed and counts every value that changes, appears or disappears, with the furthest shift back at which that still happens. Verdict per buffer on a chart panel, every event written to CSV.

Tests whether live closing deals still match the backtest of an Expert Advisor. A bootstrap-calibrated CUSUM detector raises an alarm and estimates when the drift began, a two-window check separates a short dip from a lasting decline, and an expectancy decomposition shows whether the win rate or the trade sizes changed. The script generates demonstration data on the first run and is written in pure MQL5.

A free, fully open EA: buy GBPJPY every Monday at 11:00 server time (04:00 New York), close at 23:00. Stays profitable in backtest with the entry anywhere from 09:00 to 13:00. Attach to GBPJPY M1.

Quickly view each and every individual market's open and close times. Very important for short term scalping. I own the copyright, if anyone modifies or uses this it must stay free. Comments and feedback welcome.

Shows the real spread for each server hour, measured from your broker's own tick history: median and 90th percentile per hour, optional cost as a share of your stop and per lot, and CSV export.

A chart panel that shows the contract specification details that decide position size and trading cost (point value, spread cost, margin, swap, execution rules) in the account currency, warns about broker settings that silently break lot-size code, and exports the audit of every Market Watch symbol to CSV.

H1 indicator that combines support/resistance confluence from H4, D1 and W1 with EMA trend alignment and candlestick confirmation. Shows non-repainting BUY/SELL arrows with ATR-based stop and reward/risk filtering.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208