MQL By Request #4 – Moving Average Cross EA

How to write a Moving Average Cross EA using the EA framework.

This is in answer to a subscriber question on how to write a moving average cross EA for MT5. It is also a good example for first use of the EA framework developed in parts 1-3 of this series.

To write the EA I have created 2 new child classes, CIndicatorMA inheriting from CIndicatorBase and CSignalCrossover inheriting from CSignalBase. The EA template can then be easily used to combine these to form a moving average crossover expert.

I have also introduced a small modification to the CSignalBase class to add a function that will be commonly used to retrieve technical indicator data and there are updates to the include files to introduce the new indicator and signal classes.

If you have not seen the earlier parts where the framework is developed the links below will take you to those articles.

Part 1 built the EA template and the expert class which take care of managing the expert.

Part 2 added trade signals.

Part 3 completes the framework ready for use.

The latest version framework including base classes is available for download.

The framework only includes the base classes and folder structure. It is intended as a basis to follow the tutorial video. To use the framework and folow the video you will need to:

  • Create the SignalCrossover file
  • Create the IndicatorMA file
  • Modify the AllIndicators file to include IndicatorMA
  • Modify the AllSignals file to include SignalCrossover
  • Use the EA template to create the MA Crossover EA

This is the Expert Advisor framework used in the MQL By Request series. The framework includes base classes and include files but does not include specific child classes created as working examples. This is the latest update including version 2.02 of the framework




  1. Hi i need an EA technic for hedging both which u covered from part 1 hedging strategy to part 3.plz I really need them especially the one with variations

  2. Hi
    I managed to download the entire framework till 2.03 but I encountered a problem when running the back test of the history data on my Crash 500 or Volatility 75 index symbol: the problem is that the MA crosses over but the trades are not executed. Can you please help by informing me were I might have gone wrong.

    1. I can’t say where the error might be but add some Print statements so you can see where the program is going and get the values of variables. Start with near the trade opening statements to make sure the code is getting there and work backward through the conditions. Did you check the log for errors like invalid lot size or prices etc.

    1. The downloadable framework only includes the base classes. For specific implementations, the child classes that inherit from these like CIndicatorMA and CSignalCrossover follow the video. Remember to add include statements for these files in the AllIndicators and AllSignals files. I will update the framework package to include instructions.

Leave a Reply