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

Advanced Stochastic EA A Smart Trend-Following Expert Advisor with Stochastic Confirmation

Candle Replay Magnifier visually replays historical candles over the current chart area for comparative analysis. This indicator overlays past price bars from a selected date onto the live chart, allowing traders to study candle patterns, volatility, and structure in real time. Includes dynamic range highlighting and detailed tooltips showing open, high, low, close, range, direction, time, and volume for each replay candle.

The Pending_tread EA is a versatile and easy-to-use trading robot designed to automate the placement and management of multiple pending orders arranged in a grid pattern above and below the current market price. This EA is well-suited for scalping strategies and can operate on any timeframe or currency pair, making it highly flexible for various trading styles.

Volatility indicator with a threshold line based on the Generalized AutoRegressive Conditional Heteroskedasticiticy (GARCH) statistical model used for time series analysis and forecasting.

The AutoTrendLines indicator automatically draws support and resistance trend lines on your MetaTrader 5 chart. It identifies key price levels using two methods: Two Extremums (Type 1) or Extremum and Delta (Type 2). The lines are recalculated only when a new bar forms, ensuring efficient performance.

Set Auto TP and SL: The “Set Auto TP and SL” (Take Profit and Stop Loss) feature is a crucial tool in any trading strategy, designed to automate risk and reward management. It allows traders to define fixed price levels where a trade should be automatically closed to either secure profits (TP) or limit losses (SL), removing the need for constant manual monitoring. When this feature is enabled, each position you open will automatically include a predefined Take Profit and Stop Loss level based on your custom parameters, such as a specific number of pips, percentage of balance, or technical levels. This not only saves time but also ensures that your trades are protected from sudden market movements and emotional decision-making.

Monthly VWAP (Volume Weighted Average Price) is an essential MQL5 indicator that calculates and displays the Volume Weighted Average Price for each trading month. It's a powerful tool for understanding long-term market sentiment, identifying key monthly fair value, and informing strategic decisions.

Weekly VWAP (Volume Weighted Average Price) is a powerful MQL5 indicator that calculates and displays the Volume Weighted Average Price for each trading week. It's a crucial tool for identifying weekly fair value and understanding the underlying sentiment over a longer timeframe.

Daily VWAP (Volume Weighted Average Price) is a simple yet powerful indicator that calculates and displays the Volume Weighted Average Price for each trading day. Ideal for identifying intraday fair value and supporting your daily trading decisions.

The Watermark indicator is lightweight and efficient, designed to display an informative watermark over the main MetaTrader 5 chart. It automatically shows the current symbol, chart time and asset description, allowing traders to customise their interface with style and convenience.

Trend Equilibrium Indicator TrendEQ dynamically analyses market trends by combining momentum and volatility. By measuring momentum against market trends, TrendEQ provides a reliable measure of trend strength and direction.

The RiskManagement library in MQL5 provides efficient and dynamic risk management, optimised to minimise resources. It allows setting maximum profit and loss limits with customisable modifiers. It includes OCO order control and tools for candlestick management and price conversions.

A compound interest calculator for the trader. Calculates, based on your parameters, your risk of ruin, and the optimal risk per trade. Gives a forecast of your capital size in a year, month, and at the end of the term.

CryptoTrend 1.00 Expert Advisor is an automated trading system designed for trading cryptocurrency (in particular, BTC). Main features: Bollinger indicator: Used to identify market extremes and generate buy and sell signals. Order Block filtering: Allows to find support and resistance levels, which helps to reduce the number of false signals. Self-learning: The entry threshold is adapted depending on the statistics of winning and losing trades, which allows the Expert Advisor to adapt to changing market conditions. Risk management: Calculates stop loss (SL) and take profit (TP) levels based on risk analysis and correlation

Custom time and price scale.

A Simple RSI and Moving Average-Based Expert Advisor for MQL5

The "Candle_size.mq5" indicator was developed to display the size of candles on the chart, providing a clear and detailed visual analysis of price movements. It calculates the difference between the high and low prices of each candle and displays the formatted value as text next to the corresponding candle. This feature is especially useful for traders who want to assess volatility or identify specific patterns of price behaviour.

The MACD Coloured Histogram is an enhanced version of the classic MACD (Moving Average Convergence Divergence) indicator, designed to provide a clearer and more intuitive visual analysis of market momentum. This indicator combines traditional MACD functionalities with a dynamic histogram that changes colour based on the relationship between the MACD Line and the Signal Line, allowing traders to quickly identify trends, reversal points and moments of indecision in the market.

Candle counter is a powerful and versatile tool designed to help traders visualise and analyse the sequence of bars on their charts. This indicator automatically numbers each candle on the chart based on user-defined preferences, making it easy to follow specific candles, identify patterns and implement precise trading strategies.

This is a Moving Average indicator based on Heiken-Ashi candles instead of raw market price.

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190