Download MetaTrader 5

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

MQL5 Source Code Library for MetaTrader 5 - 2

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.


A further development of code "Dealers Trade v 7.74 MACD" ( "Zero-lag MACD" ( is used. When the number of positions increases, the following is also increased: step between positions, lot size, take profit (martingale).

A quick way to draw an arc-shaped channel using four mouse clicks.

The Expert Advisor is based on Puria method with a few changes. It uses two iMA (Moving Average, MA) indicators and one iMACD (Moving Average Convergence/Divergence, MACD).

The Expert Advisor trades based on the signals of iMA (Moving Average, MA) and iMACD (Moving Average Convergence/Divergence, MACD). The minimum distance between the price and the MA indicator is taken into account.

An Expert Advisor based on the iIchimoku (Ichimoku Kinko Hyo) indicator. Fixed lot.

The Expert Advisor uses the signals of "crossover of two iMAs (Moving Average, MA)". The EA uses Trailing Stop and Take Profit.

An example of creating synthetic instruments for calculating the strength of RTS, USD, RUB based on futures contracts of the FORTS market.

MetaTrader 5 allows creating synthetic instruments. The price of such instruments can depend on the current values of a number of financial instruments. In trading, such symbols allow spotting the beginning and end of global market movements at an early stage. In this example we create synthetic instruments to analyze the strength of Forex currencies EUR, USD, GBP, JPY and CHF.

Simultaneous opening of opposing positions. Lot management

The EA uses three iMAs (Moving Average, MA), one iStochastic (Stochastic Oscillator) and one iRSI (RSI, Relative Strength Index). Positions are opened by market, as well as Buy Stop and Sell Stop pending orders are placed.

Information about profit, points, percent, spread and time remaining until the close the bar on the current currency pair and timeframe in a compact and convenient form.

The EA trades using signals of the iMACD (Moving Average Convergence/Divergence, MACD) indicator. Lot is increased when the number of position grows (Martingale)

An Expert Advisor based on indicators "MA Cross 3MACross Alert WarnSig" ( and "Price Channel" (

Crossover of three iMAs (Moving Average, MA). Alert, sound notification and email notification of the first crossover. Arrows mark the crossover.

A trading strategy using the Martingale system.

The Expert Advisor uses signals of the iMA (Moving Average, MA) indicator with a delay from the bar opening time.

The Expert Advisor searches for N identical candlesticks in a row. It buys on bullish candlesticks and sells on bearish ones.

The Dtm indicator with the possibility to change the indicator timeframe from input parameters.

Two identical trading systems based on the crossover of the CMO indicator and the zero line, for long and short trades, which can be configured in different ways in one Expert Advisor.

A trading system based on the signals of the Daniella semaphore signal indicator.

Trading against the trend direction as of N hours ago.

The indicator implements a breakout system using the Fractal_Levels indicator channel.

A daily bar breakout strategy.

An Expert Advisor based on "KDJ Indicator"

KDJ Indicator Oscillator

The Expert Advisor trades based on iMA and iRSI signals. Values of iMA on four bars are compared. Indices of these bars can be optimized.

A trading strategy "three bars down, Stochastic up".

A trading system based on the Martingale technique.

A trading system based on the Vortex Oscillator signals.

This version of the Vortex indicator shows the difference between the VI+ and VI- lines as a histogram oscillating around the zero line.

The Expert Advisor is based on the signals of indicators iBands (Bollinger Bands, BB) and iRSI (Relative Strength Index, RSI).

Martingale and anti-martingale.

The channel is drawn based on fractals.

The indicator shows a text block with the values ​​of the user defined Stochastic Oscillator period for each timeframe.

Maximum lot calculated based on free margin.

A semaphore signal indicator using Average True Range.

The Expert Advisor is based on the signals of the Stopreversal indicator and is provided with the possibility to set a strict trading time interval.

A real-time indicator showing the lag of quotes inside the terminal.

The indicator sets indexes for candlesticks in the price movement direction.

The Expert Advisor is based on the iRSI (Relative Strength Index, RSI) indicator signals.