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

MQL5 Source Code Library for MetaTrader 5

icon

This is the largest free source code library for MetaTrader 5 platform programs. Here you can find ready-made Expert Advisors, technical indicators, scripts and libraries. Use the code library when learning MQL5 language and develop your own automated trading applications based on the provided codes.

You can freely download and test published codes, as well as launch them in MetaTrader 5. The library is also available directly from MetaTrader 5 platform and MetaEditor development environment.

Submit your code

This function performs the main logic of opening a trade. It calculates the opening price, take profit levels and stop loss based on the symbol information and parameters provided by the user. Prepare a trade request (MqlTradeRequest) with the necessary information such as symbol, volume, order type, slippage, comment, magic number, etc. Call the OrderSend function to send the trade request and get the result. SetTypeFillingBySymbol function: determines the order fulfilment type (Fill or Cancel, Immediate or Cancel or Return) according to the symbol's fulfilment policy. GetMinTradeLevel function: calculates the minimum trade level based on the freeze level and stop level of the symbol. Adjusts the minimum level to ensure that it is within certain limits and returns the result.

combination of many familiar indicators for beginner traders

The EA only trades buy positions and does not use Sl and TP.

The indicator implements one of the non-linear smoothing algorithms

A professional visual indicator for the popular "One Candle" Daily Breakout strategy (0.9 SL / 1.25 TP). Automates the vector analysis for Gold (XAUUSD).

CDateTime milliseconds extension + datetime supervisory variable extension

Set three crosses and monitor the daily percentage performance starting from a given time (that can also be set).

Idea by Andrey F. Zelinsky, based on an indicator by William Blau

Records ticks in real ticks mode and reads them in maths mode calling your strategy with each tick.

Professional panel for closing positions with 6 smart filters. Close all, by type, by symbol, or by profit/loss. Real-time P&L display. Perfect for emergency exits and risk management. Includes safety confirmations.

The function calculates the lot size of an open position. The opening price of a deal, the price of stop loss level and the risk per deal in per cent of the deposit are passed as parameters

This indicator implements the "Quarters Theory" - a technical analysis concept that divides price movement into four quarters around a central base level. It's designed to work with multiple asset types (Forex, stocks, commodities, etc.) and provides visual quarter levels on the chart.

An example of adding buttons for your advisors. In this example, a button has been implemented to close all active positions for all instruments. In addition to the button event processing functionality, methods for closing positions relative to the symbol name and counting the number of positions relative to the symbol name are also implemented.

DeltaFusion Lite is the simplified version of the DeltaFusionPro indicator for MT4. It calculates and displays Cumulative Delta and Net Delta, giving traders a clear view of buying and selling pressure within each candle. By analyzing the distribution of volume between bid and ask, it helps identify market sentiment shifts, potential reversals, and various types of divergences between price and volume.

Functions for use instead of ChartXYToTimePrice and ChartTimePriceToXY, working correctly and quickly over the entire range of input parameters

Source codes written in the process of developing a library for creating multi-currency Expert Advisors combining multiple instances of different trading strategies.

The indicator allows you to estimate the probability that the price has reached its maximum or minimum.

Working with keyboard data

This library is an updated version of the ErrorDescription.mqh library published by MetaQuotes, with some features included.

An example of a bot with an embedded machine learning model that is trained in python and saved in ONNX format.

The script calculates the autocorrelation and partial autocorrelation functions and displays them on a graph

Tillson T3 with EMA calculations done without auxiliary indicator buffers.

Script for displaying updating data on open positions.

This indicator builds a dynamic price channel using Gaussian smoothing to determine support and resistance lines. It calculates smoothed high and low price values for a given period, finds their extrema and displays three lines: upper resistance (maximum of smoothed high), lower support (minimum of smoothed low) and the middle line between them, forming an adaptive trading channel.

A simple signal indicator based on RSI and Moving Average. Draws Buy/Sell arrows when RSI is above/below 50 and Price is above/below MA.

A simple comment.

MT5 version of the indicator https://www.mql5.com/ru/code/25465

The script provides a set of functions for creating all standard graphical objects for use in your own developments. The functions presented in the script can be used "as is" or modified to your requirements.

The simplest indicator showing on the current symbol the price change in % since the opening of the trading session.

The two moving averages crossover strategy is one of the most common trading strategies in the financial market. It is based on the use of two moving averages (usually long and short term) and signals an entry into a position based on their crossover.

MULTI TF Confluence Index Stoch+RSI+MACD

Average Daily Range Indicator.

Closing martingale trades

Modern indicator that displays your daily trading statistics directly on your MT5 chart. Track your trading performance with a beautiful flat design panel showing lots traded, number of orders, and profit/loss for each day.

This script helps traders understand the distribution and breadth of candlesticks over a specific period, which can be useful in making trading decisions such as which Take Profit or Stop Loss to use based on historical values.

The Clean Market Watch script is a simple utility tool designed to quickly remove all symbols from your MetaTrader 5 Market Watch window with a single click. This is particularly useful when you want to start fresh with a clean workspace or when your Market Watch has become cluttered with too many symbols. Purpose Over time, traders often accumulate numerous symbols in their Market Watch window, making it difficult to focus on the instruments they actively trade. Manually removing symbols one by one can be tedious and time-consuming. This script automates the entire process, clearing all symbols in seconds.

EA Tools tính toán Margin theo lotsize, có thể tùy chỉnh đòn bẩy

The Open Range Breakout (ORB) indicator is a powerful technical analysis tool that identifies and tracks price breakouts from the opening range of trading sessions. This indicator is based on the concept that the high and low prices established during the first minutes of a trading session often serve as significant support and resistance levels throughout the remainder of the day. The indicator automatically calculates the opening range based on user-defined time periods, plots multiple price targets, and provides visual and audio alerts for potential trading opportunities. It is designed to help traders identify high-probability breakout trades and retest scenarios.

A simple Expert Advisor that trades when the price forms the "Three From Within" pattern.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193