Watch how to download trading robots for free
Find us on Twitter!
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

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"). Draw the body of the candle: Draw a rectangle from the opening price to the closing price, using a different colour if the candle is bullish or bearish. Colour customisation: You can easily change the colours used for bullish and bearish candles and their wicks. In the code you use, for example: The bearish candles have a maroon body (clrMaroon). The wicks of the bearish candles are light violet (clrOrchid). What is it useful for? This indicator is useful if you want to: Have a unique and clear visual style on your charts. Differentiate bullish candles more easily from bearish ones. Analyse the price behaviour in a more visual way.

This is a custom indicator for MetaTrader 5 whose sole purpose is to display a BMP image on the chart, centred on the screen. What is it for? It is used to display a static image (such as a logo, personal branding, chart message or reminder) directly on the trading chart, without affecting the analysis and market data. How does it work? It creates an OBJ_BITMAP_LABEL object to display an image (2.bmp) from the MQL5Images folder. It automatically calculates the centre of the chart and places the image there. It updates the position of the image on each new tick so that it is always centred, even if the window is resized.

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.

Custom MACD for MetaTrader 5 enhances the classic MACD with real-time signal alerts sent to your phone. Detect trends and reversals with customizable parameters, intuitive visuals, and automated buy/sell notifications.

All indicators required by BBMA Strategy in a single indicator.

This indicator for Breakout Strategy. It doesn't print objects on the chart.

Dynamic VWAP level which can be averaged over multiple days

Trading XAUUSD (Gold) is often influenced by major economic news events like USD, GBP, or EUR releases. To mitigate risks during these volatile periods, using a News Filter in your Expert Advisor (EA) is essential. In this article, I’ll share how to create a simple News Filter on MT5 and apply it to XAUUSD trading.

This Expert Advisor (EA) helps traders manage risk by automatically adjusting position sizes and stop-loss levels based on market volatility, using the Average True Range (ATR) indicator. The EA calculates the optimal position size for each trade according to a user-defined risk percentage and the current ATR value, ensuring consistent risk exposure across all market conditions. It also offers an ATR-based stop-loss option to adapt to volatility, while employing a simple moving average crossover strategy to open buy trades. Ideal for traders seeking to automate risk management without complex trading logic, this EA prioritizes account protection and simplifies the trading process.

A simple and effective Expert Advisor based on Stochastic Oscillator reversal signals on the H1 timeframe. Buy signals are triggered when %K crosses above %D below the 20 level. Sell signals are triggered when %K crosses below %D above the 80 level. Risk is calculated based on the account balance, with the lot size set to 0.1 (adjustable as needed). Take Profit (TP) is set to 300 points for all positions. Stop Loss (SL) is dynamically calculated based on the opposite crossover signal. The position is closed when a crossover in the opposite direction occurs, as well as when TP or SL is reached

This indicator calls 3 other subwindow indicators. All files go in your Indicators folder.

The EA opens positions randomly (50/50 chance for Buy or Sell) when no position is open.

This Indicator shows Buy or Sell Signal

The Custom MA Cross with RSI Indicator for MT5 is a versatile trading tool designed to help traders identify trend changes and filter entries using momentum. This indicator combines two moving averages (MA) with the Relative Strength Index (RSI), offering clear buy and sell signals.

This indicator will shows the time remaining until the end of the candle. You can choose colour and the font size.

A moving average of pure tick volume with histogram bars tracking bullish/bearish candle color

Takes trades based on ICT silverbullet and 2022 model with trailing stops and partials, also keeps entry according to OTE, and risk minimal. It works in a small time window of silver bullet especially NY session, and if no trade found, 2022 model and fibonacci OTE jumps in to get a trade. But entry is so only after confirmation with these models being there, hence trades will be less for minimal drawdown and high winrate. To know more about these strategies, you may visit Inner Circle Trader YouTube channel.

Countdown is an advanced indicator designed for traders who want to track the time remaining until the next candlestick or the next market open clearly and efficiently. With three flexible display modes (commentary, chart borders or next to price), this indicator offers a customisable solution to suit your trading needs.

MACD Divergence indicator

Two Symbol Spread Indicator

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189