MT4 Expert Advisor Template

I remember when I first started Studying Forex Trading and short after I decided that I wanted to automate my trading as much as possible.

The idea of being influenced by emotion, the stress of seeing a position in loss and the greed of not closing a profitable trade…

Also, the problem of constantly having to monitor the positions… No Thanks!

A Trading Robot is much better than me at trading, it follows the rules, day and night, loss or profit.

Entry Signal Found? Entry! Exit Signal Found? Exit! As Easy As That!

Initially it was very challenging, it is another way of thinking and you need to translate everything into mathematical formulas, comparisons and break down complex problems into a sequence of simple actions.

After years of coding I accumulated a good amount of functions and routines that help me daily in the development of EAs and Indicators.

The MT4 Expert Advisor Template is the basic template for the development of my trading bots.

It includes the basic workflow and functions of a trading expert advisor WITHOUT entry and exit signals.

You can add your own entry and exit signals and run it.

I can guarantee this source code will significantly reduce the time you spend developing an Expert Advisor.


What Is MT4 Expert Advisor Template

MT4 Expert Advisor Template is 700+ lines of commented source code that you can use to build your own EA.

The code is explained so you can understand it’s logic.

You can customise portions of the code to achieve your entry and exit signal and have an EA ready to use.

What Does MT4 Expert Advisor Template Include

  • Comments for each function, to understand the logic
  • Well Written Code
  • Modular Structure
  • Risk Management Through Automatic Position Size Calculation
  • Selection Of Fixed Or Automatic Stop Loss
  • Selection Of Fixed Or Automatic Take Profit
  • Mechanism To Perform Trailing Stop
  • Check Of Trading Hours
  • Error Management And Order Submission Retry

What MT4 Expert Advisor Template IS NOT


MT4 Expert Advisor Template IS NOT a fully automated strategy.

Although we include some automated bots to download with this template, these are only to show the potential of the code and as examples.

You will need to add to the template your own Entry and Exit signal code in order to have it fully operational.

Why Using MT4 Expert Advisor Template

Save Time

Save Many Hours Of Research And Coding Using Ready To Made Functions

Error Handling

Error Handling Is Embedded In All Of The Included Functions

Risk Management

Don't Fail Risk Management Rules Respecting Position Sizing And Stop Losses

Easy To Edit

With Only A Few Lines Of Code You Can Complete The Bot And Have A Fully Automated EA

What Is The Logic Of An Expert Advisor


All EA are divided in 3 main functions:

  1. OnInit is the initialization of the EA, the first function that runs when you load an EA
  2. OnTick runs every time MT4 receives a new quote for the current instrument
  3. OnDeinit runs just before closing the EA

Modules Included In MT4 Expert Advisor Template

MT4 Expert Advisor Template is written in a modular way so that all the functions are separate.

This allows to have a source code easier to read and to understand and also makes it easier to customise the code.

Here you see how the functions are separated in the execution.

OnInit Function

OnTick Function

OnDeinit Function

What Do You Need To Use MT4 Expert Advisor Template

Although most of the code is provided and commented, you need to be able to add your own code for the Entry and Exit signal and if you want to customise Trailing Stop and Dynamic Stop and Take Profit.

I provide some examples together with the code and in my blog articles.

The files included to download are for the MT4 platform and only work on the MT4 platform.

It is advisable to be familiar with compilation, which is understanding that this product is source code to be edited in the MetaEditor and compiled to a working EA through the platform.

I would like to remind that this is not a fully working trading strategy.

You will have to include your own entry and exit signals and strategy.

From The Source Code

These are some extracts from the code.

This is a good way to understand if the product is suitable for you.

If what you see makes sense then I am sure it will significantly help you.

If it doesn’t make sense but you are interested in see how the code for an Expert Advisor works then this can help you.

If you are not the coding type of person and all this doesn’t interest you, then probably this is not something for you.

If you are interested in a more basic course to start programming in MQL4 let me know and I will put together a beginner course.

How To Install MT4 Expert Advisor Template

  1. Download The Files
  2. Open the MQL4 Folder, from MT4 Client click File -> Open Data Folder
  3. Copy the .mqh file in the Include folder
  4. Copy the icon in the Files folder
  5. Copy the .mq4 files in the Experts folder
  6. Open the files with Metaeditor

How To Use It

Customise the following functions in order to complete the signals:

  • EvaluateEntry contains the code to trigger an entry signal, it is necessary to add something here
  • EvaluateExit contains the code to trigger the exit signal, you can leave this as is if you use fixed stop loss and take profit
  • ExecuteTrailingStop contains the code to trail the stop loss, necessary only if you want to add a trailing stop function
  • StopLossPriceCalculate contains the code to assign a dynamic value to the stop loss, not mandatory
  • TakeProfitPriceCalculate contains the code to assign a dynamic value to the take profit, not mandatory

Fully Working Examples Provided

Together with the template you can download two fully functional Expert Advisors so you can see how the code has been customised.

EXAMPLE 1 : Bollinger Bands Breakout

EXAMPLE 2 : 2 Moving Average Crossover


  • Excellent Template!

    Love it! saved me a heap of time learning and mashing other snippets of code together.
    Is there a way I can seek advice on how to tweak it slightly to handle multiple long/short strategies I’d like to run? the documentation is minimal and I find myself reverse engineering the thinking behind the script?

    happy to take this offline to discuss further.

    1 of 2 people found this review helpful.

    Help other customers find the most helpful reviews

    Did you find this review helpful? Yes No

  • LOVE LOVE LOVE not having to start at zero.

    Sometimes you just have to start off at square_1 in order to know all the steps you are taking.

    But I’ve had a couple of weeks with the EA template now to look at it. And compare. I’ve already started trying to write my first EA–its official. But i will come up on things/problems during my research and then look back at your template and see that you have already provided for most of them.

    This template is so great! I was actually doubtful at first that I needed to *buy* a template…..who does that?!?!! 😉 So glad i did…really!! Probably going to have to buy a few more of your widgets since you are saving me Sooooo much time.

    Thank you sir!!

    1 of 2 people found this review helpful.

    Help other customers find the most helpful reviews

    Did you find this review helpful? Yes No

    • Thank you James for the honest feedback, I am glad it is helping you and SAVE TIME is one of the main goals of the tools I create

      1 of 2 people found this review helpful.

      Help other customers find the most helpful reviews

      Did you find this review helpful? Yes No

  • Write a Review

    We use cookies to ensure that we give you the best experience on our website.