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

The TradeReportExporter script is designed to export the history of trades (trades) into a convenient CSV file. It automatically collects data on all trades for the last year for the instrument it is installed on. The file includes such data as date and time, transaction type (buy/sell), price, volume, commission and profit/loss. The result is saved in a file that can be opened in Excel or any other spreadsheet editor.

EXSR.mq5: A counter‑trend MT5 EA that catches reversals by combining RSI(14) extremes with Bollinger Band breakouts and a reversal candlestick, placing one trade per symbol with fixed SL/TP.

Unpack GZIP archives from *.gz files or responses from sites compressed with this format.

This is the exact conversion from pine script source code Supertrend by KivancOzbilgic

Trading Gap Weekend, is it profitable?

This MQL5 custom indicator detects divergences between price action and the Awesome Oscillator (AO), signalling potential market reversals or continuations. It plots buy/sell arrows on the chart, displays the AO as a histogram, and draws trendlines to highlight divergences.

Partially close active sell orders

Script for partially close active buy orders

Indicator that displays the day's trend at any chart time. You can customise the colours and position of the text on the screen.

TelegramToMT5 is a MetaTrader 5 Expert Advisor that bridges Telegram and MT5 by displaying messages from your Telegram channels, groups, and private chats directly on your trading charts. Simply create a Telegram bot, add it to your desired channels/groups, and let the EA show all messages as comments on your chart in real-time.

The indicator displaying multi level of ATR Channel.

It is an indicator used to determine the trend, support and resistance level of the market. When volume data is available, it calculates using MFI, if not, it calculates using RSI. Momentum: RSI and MFI Volatility: ATR

The "False Breakouts.mq5" indicator is a tool for MetaTrader 5 that visually identifies and marks buy and sell points based on false breakouts of support and resistance. It uses buffers to display buy (blue) and sell (red) arrows, as well as lines for support (blue) and resistance (red), and additional arrows for market tops and bottoms. The indicator's main logic consists of detecting tops and bottoms based on the high and low prices of the candles, dynamically updating support and resistance levels. When the price breaks through support or resistance and then returns, the indicator generates buy or sell signals respectively. It is a useful tool for traders who operate strategies based on false breakouts.

Combines a Moving Average with ATR-based upper and lower bands to act as a trend filter and volatility channel.

This indicator is a utility that shows labelled trade levels on any chart. If you want to replace your native trade levels on a native chart, then turn off "Show trade levels" in your F8 Chart Properties and attach this indicator. If you want to show trade levels on a Custom Chart (where native trade levels cannot be shown), then simply attach this indicator. BaseSymbol - specify the Symbol from which the trade level data will be pulled--handy for unique Custom Symbols. TextBarsBack - specify the number of bars back in history from the current bar where the level labels will be drawn. Note: Although magic number is referenced in the code, it is not presently included in the trade lines. If you're running multiple EA's on the same Symbol, you can edit the code to show magic numbers and then run multiple instances of the indicator on one chart. You can also edit the font sizes and text spacing in the object properties as needed for different display resolutions.

Good afternoon everyone) First time posting my code!!!

This indicator picks up the divergence points of the DeMarker indicator

Draw the wicks (thin lines): Draw a vertical line from the lowest price to the highest price of each candle (this is called a "wick")

This is a custom indicator for MetaTrader 5 whose sole purpose is to display a BMP image on the chart, centred on the screen

This Expert Advisor (EA) implements a triangular arbitrage strategy between three currency pairs: EURUSD, USDJPY and EURJPY

Population-based optimisation algorithms are collected here. The archive contains all necessary files to run the algorithms on test functions.

MQL5-Like Trade Classes in Python for MetaTrader 5 Python

This indicator detects bullish and bearish engulfing candlestick patterns with an optional volume filter to highlight stronger signals.

A dynamic trendline-based evolution of the Donchian Channel

This indicator reads the trade history and plots the Cumulative P & L over time, helping visual traders to see how much money they are making or losing over time. This current version has a difference of 0.02% marginal error, due to rounding floats, and calculation methods. It can be considered extremely precise with this marginal error.

The function can be useful to not overload the server with trade requests at times when the market is closed for trading

The Candle Filter indicator is a customisable tool designed to filter and highlight candles on the chart based on specific criteria. It allows the trader to visualise only the candles of interest, such as bullish candles, bearish candles, Doji candles or all candles simultaneously. In addition, the indicator offers full control over the colours of the candles and the chart background, providing a clear and adaptable visual experience.

This EA is meant to impose a few rules to manage baskets.

This indicator takes RSI divergences and plots them in buffers to automate EAs

The Auto SL TP by Risk Reward Ratio script is a simple yet powerful tool designed for MetaTrader 5 traders who want to streamline their risk management process. This script automates the process of setting Stop Loss (SL) and Take Profit (TP) levels for open positions based on a user-defined Risk:Reward ratio and Stop Loss in pips. Whether you're a beginner or an experienced trader, this script saves time and ensures consistent risk management.

Butterfly Strategy Expert Advisor This Expert Advisor (EA) implements the Butterfly harmonic trading pattern across multiple timeframes (M2 to D1) for automated forex trading. It detects bullish and bearish Butterfly patterns using pivot points and executes trades with customizable risk management and multiple take-profit levels.

Logger with the ability to log individual modules or code sections

EquiPeak Drawdown Tracker is an indicator designed to monitor and record the maximum drawdown of your trading account in real time. It is not just an alerter of current drawdown; it is especially useful for visually comparing your current drawdown with the maximum historical drawdown you expect or have previously recorded.

The DailyHighLow indicator is a versatile tool designed for MetaTrader 5 (MQL5) to display high and low price levels on a chart based on a specified timeframe. This indicator is particularly useful for traders who rely on key price levels for decision-making, offering flexibility through customizable timeframes and price calculation methods.

Simple Expert Advisor with custom R-squared optimisation function

The AutoCloseOnProfitLoss Expert Advisor (EA) is a powerful automation tool for MetaTrader 5, designed to close all open positions when predefined profit or loss targets are reached

A simple utility for monitoring long and short swaps of a single symbol. If your broker-dealer's swaps are specified in points instead of account currency, this utility automatically converts points into account currency. Swaps are tripled on Wednesday. Horizontal and vertical alignment can be adjusted in the inputs.

It is taken into account that there are 30 days in a month, 365 days in a year The script demonstrates the counter of time until the beginning of the new year

The ADX (Average Directional Index) Smoothed indicator enhances the standard ADX by applying dual exponential smoothing filters to reduce noise and provide clearer trend signals. It plots three lines: smoothed +DI (blue), -DI (red), and the main ADX line (green). This refined version helps traders identify trend strength and potential direction changes with reduced false signals. The indicator excels at confirming established trends and warning of weakening momentum before actual price reversals occur, making it valuable for both trend following strategies and determining optimal entry/exit points.

The RSI Expert Advisor (EA) is an automated trading tool developed for the MetaTrader 5 (MT5) platform. This EA leverages the Relative Strength Index (RSI) to identify buy and sell signals, incorporating risk management, partial position closing, and trading hour restrictions to optimize trading performance.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189