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

Copy chart attached to all other charts open

EXCEPT CHART ATTACHED ON

Serialization and deserialization of the JSON format

Callback interface for timer

The T3 Indicator is an advanced moving average that combines six exponential moving averages to provide smoother price action with reduced lag compared to traditional moving averages.

Draw daily vertical lines plus the day of week labels on the chart.

BreakRevertPro EA merges breakout and mean reversion strategies with adaptive SL/TP and multi-timeframe ATR trailing stops for flexible trading in volatile markets.

Zig Zag indicator that relies only on a minimum % of retracement to each previous wave , and optionally , being bigger than a specific size measured in atr units.

A zigzag indicator that uses a single input to adjust the step size for detecting wave direction changes

The goal is to make the function readily available for any Telegram integration task in MQL5 development. By adding this file to your CodeBase, you can simply include it in your Expert Advisors and call the function directly from the included module. This eliminates the need to redevelop the code from scratch repeatedly, ensuring reusability across multiple projects.

Time to candle Close. Dynamic text colours. Optimised for back-testing.

Whether you’re running multiple trading robots simultaneously or just one sophisticated strategy, keeping track of each Expert Advisor’s performance can be surprisingly time-consuming. MetaTrader 5 (MT5) conveniently displays orders and positions in its “Toolbox,” but when numerous robots share the same account, it becomes harder to know which EA is generating your profits—or losses. A single account might have dozens or hundreds of trades, each opened by different EAs, making it difficult to separate the results of one robot from another.

Download all the ticks from your broker for all the symbols in the market watch. Download all history or until a specific date in the past if available.

These are some #define statements that are useful to perform operations in your EA. You only need to assign the name of your variables at the beginning of the file, and then let the other #define statements do the work. In order to use this file, add #include <DEFINE_statements.mqh> to the first line in your EA file.

The indicator plots two lines. The lower line is calculated based on the latest SMA period that caused a bounce up. The upper line is calculated based on the latest SMA period that caused a bounce down.

A simple starting-point script to collect data and send to a CSV in oldest-newest ordering. In this example only the close price data is collected.

PrintXYZ() library to print massive information from the terminal.

A script which when dragged onto the chart will print out in the experts window the number of bars that are on that chart - like magic.

An indicator which visualizes how volume changes over time within each bar. It shows tick volume in a rolling histogram format.

This Script & EA enables coders to backtest their news based strategies which use the MQL5 Calendar.

This EA is designed to automatically follow market trends using signals from the Moving Average and Stochastic Oscillator indicators. The EA detects buy and sell signals by utilizing MA crossovers and confirms the trend with Stochastic. Additionally, the EA includes automatic position management, such as setting Take Profit, Stop Loss, and lot size doubling to enhance trading effectiveness in trending markets.

Trade Assistant MetaTrader indicator — a multi-timeframe indicator that is based on three standard indicators: Stochastic oscillator, RSI (Relative Strength Index), and CCI (Commodity Channel Index). It displays current trend directions for M1, M5, M15, M30, H1, H4, D1, W1, and MN1 timeframes. When you follow such an indicator you have a clear picture of the trends across all important timeframes. It doesn't matter which timeframe you attach this indicator to. The indicator can be downloaded for MT4 and MT5.

Calculate a moving average in one function call. Code that can easily be transported between different projects.

Total Power Indicator (MetaTrader indicator) — is based on the two standard indicators — Bear Power and Bull Power. The indicator calculates how many bullish and bearish bars were there during a given look-back period and then calculates the proportional index for bears, bulls, and total (calculated as the absolute difference between bulls and bears) for the current bar. This way, we get continuous lines of the relative average bear and bull power over a period, removing the main disadvantage of the original Bear/Bull Power indicators — the lack of a long-term perspective. The original MetaTrader 4 version of Total Power Indicator was created by Daniel Fernandez of Asirikuy.com in 2011. The version for MT5 is now also available.

TD Sequential Ultimate MetaTrader indicator shows all parts of the TD Sequential method developed by the legendary technical analyst, Tom DeMark. TD Sequential Ultimate displays Buy and Sell Setups, including the Setup Perfection arrows, Buy and Sell Countdowns, including the failed count 13 attempts, and TDST Support and Resistance levels. Unlike many other implementations of the TD Sequential method, this indicator offers multiple improvements:

Coppock MetaTrader indicator — is an implementation of the famous Coppock curve indicator first created by Edward Coppock in 1962. The indicator shows long-term buy and sell opportunities (classically, it is used for only buying) by measuring the weighted moving average (with a period of 10) of the sum of two rates of change (with a period of 14 and 11). It is the classical version. In this MetaTrader version, you can modify the parameters of the basic indicators. You can use this Coppock indicator in MT4 and MT5.

Support and Resistance MetaTrader indicator — as the name of this indicator suggests, it displays the support and resistance levels. It shows them directly on the chart, providing an easy help when you want to set stop-loss or take-profit level, or when you want to see the next market target. This indicator uses the standard MetaTrader Fractals indicator (by Bill Williams' method) and has no changeable input parameters. This indicator is available for MetaTrader version 4 and 5.

Spread MetaTrader indicator — displays current spread in the main window of the chart. You can modify the font parameters, indicator's position and the normalization of the spread value. The spread is redrawn after each tick, ensuring the most current and active spread value. This can be useful for brokers with variable spreads or with spreads that are widened often. You can also enable a spread label to be shown near the current Bid line. The indicator is available for both MT4 and MT5.

Schaff Trend Cycle (MetaTrader indicator) — is a cyclical oscillator created by calculating the stochastic over stochastic over a MACD line using cycles. The result is the improved version of the oscillator that is not choppy during the trends and reacts to the changes very fast. It was developed by Doug Schaff, who assumed that the currency trends accelerate and decelerate in cycles. Its algorithm was made public in 2008. Schaff Trend Cycle tries to combine two different methods of determining the trend direction changes — MACD and smoothed stochastic oscillator. The value of the indicator fluctuates between 0 and 100. Two trigger levels are used — 25 and 75. Optional alerts are available. You can download this indicator for MT4, MT5

RSIOMA MetaTrader indicator — this indicator takes two moving averages, calculates their RSI (Relative Strength Index) and then also adds a moving average of the calculated RSI. These two lines now can accurately signal the trend changes. They are shown in the separate window where they change from 0 to 100. The auxiliary histogram is shown for a quick-glance view of the current trend. The indicator is available for both MT4 and MT5 versions of the MetaTrader platform.

Round Levels MetaTrader indicator — an MT4/MT5 indicator that can display round levels and zones near them based on your configuration. It can be useful to trade off the natural psychological support and resistance zones. It can also issue alerts when the price is in either support or resistance zone.

Recent High/Low Alert MetaTrader indicator — displays two bands of maximum and minimum levels across recent N candles. By default, the maximum band is displayed with a blue line; the minimum band is displayed with a yellow line. Additionally, it can invoke a popup alert, send an email alert, or issue a notification alert when the current price (Bid) breaks recent High or Low level. All alerts can be turned off. If you use the email alert feature, do not forget to set the email settings in your MetaTrader platform's options window. Same with push-notifications. The indicator is available for both MT4 and MT5.

Range Expansion Index (MetaTrader indicator) — is a relative oscillator indicator that measures the pace of the price changes and signals overbought/oversold states if the price demonstrates weakness or strength. It was developed by Tom DeMark and explained in his book The New Science of Technical Analysis. The value of the indicator changes from -100 to +100. The REI is an enhanced oscillator because it tries to remain calm during the range trading and indicates signals only when the significant peaks or bottoms are spotted. You can download this indicator both for MT4 and MT5.

Rainbow Multiple Moving Average (RMMA) MetaTrader indicator — is a very simple but visually informative indicator based on the standard moving average. It draws 66 rainbow-colored moving average lines of your preferred type and price directly in the main window of the chart. This indicator is available for both MT4 and MT5 versions of the trading platform.

QQE MetaTrader indicator — or Quantitative Qualitative Estimation, is based on a rather complex calculation of the smoothed RSI indicators. As a result, you get two lines in a separate indicator window — the fast one and the slow one. There is also an important indicator level (50), which is used in signals. You can enable text, sound, and e-mail alerts for this indicator. This QQE implementation supports multi-timeframe analysis with upper timeframe display. The indicator is available for MT4, MT5

Price Alert MetaTrader indicator — can issue any type of alert when the price reaches certain levels set by a trader. There are three types of price levels: the first one is used when the price rises above certain level (displayed with the green line on the chart), the second one is used when the price falls below certain level (displayed with the red line on the chart), and the third one is used when the price reaches the certain level exactly (displayed with the yellow line). Three alert types include: native (popup), email, and push-notification. For email and push-notification alert features to work, you need to set up the email or MetaQuotes ID settings in your MetaTrader platform options window. The indicator is available for both MT4 and MT5.

Point-and-Figure MetaTrader 5 indicator is an indicator that can plot a point-and-figure chart directly in the main window of your normal MT5 chart. You can set up all the point-and-figure method parameters, such as the box size and the reversal distance, according to your preference. In addition, you can control all the display parameters of the PnF chart. This point-and-figure indicator supports all sorts of alerts. It is based on real ticks data, and thus is available only for MT5.

Pinbar Detector is a MetaTrader indicator that tries to detect Pinbars (also known as "Pin-bar" or "Pin bar") and marks them by placing a "smiling face" symbol below the bullish Pinbars and above the bearish Pinbars. It is a pure price action indicator, which is not using any standard technical indicators in its code. The configuration of Pinbar detection can be done via the indicator's input parameters. Pinbar Detector can issue platform alerts and email alerts on detection. The indicator is available both for MT4 and MT5 versions of the trading platform.

Pinbar Detector is a MetaTrader indicator that tries to detect Pinbars (also known as "Pin-bar" or "Pin bar") and marks them by placing a "smiling face" symbol below the bullish Pinbars and above the bearish Pinbars. It is a pure price action indicator, which is not using any standard technical indicators in its code. The configuration of Pinbar detection can be done via the indicator's input parameters. Pinbar Detector can issue platform alerts and email alerts on detection. The indicator is available both for MT4 and MT5 versions of the trading platform.

Keltner Channel (MetaTrader indicator) — is a classical technical analysis indicator developed by Chester W. Keltner in 1960. The indicator is somewhat similar to the Bollinger Bands and Envelopes. It uses three plot lines: the middle line is the 10-day simple moving average applied to the typical price ((high + low + close) / 3), the upper and the lower bands are produced by adding and subtracting the moving average of the daily price range (High and Low difference) from the middle line. This way, a volatility-based channel is built. In this version of the indicator you can modify all the parameters of the MA. The indicator is available both for MT4 and MT5 versions of the platform.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187