Monthly Archives: February 2020

How to Add Alerts to MetaTrader Indicators

Originally, I intended this post as a do-it-yourself guide on how to add alerts to MetaTrader indicators without knowing how to code at all. But writing it, I came to realization that even if a trader knows nothing about MQL language and coding he will have to learn some basics through this guide because adding alerts does require deep understanding of how MetaTrader code works.

One important thing to understand is that it is not possible to add alerts to indicator without at least some coding. The good thing is that what you will require is so simple that even a 5-year old could do it after reading this post. You have to do three things to add an alert to an indicator:

  1. Add input parameters for turning alerts on/off and adjusting some alert settings — all entirely optional but it is better to have some easy way of configuring things than to re-code everything each time your needs shift.
  2. Identify indicator buffers that are used by an indicator and contain the data you want to be alerted about.
  3. Formulate conditions for alerts to fire up. For example, a classic condition for MACD buy alert could be formulated as: current MACD Signal below current MACD Main and previous MACD Signal above previous MACD Main and both current MACD Signal and MACD Main are below zero. Conditions can be simpler or more complex, but you should already know what you want to be alerted about if you are looking to add alerts to an indicator.

Prerequisites

Before you proceed, make sure that the prerequisites listed below are met:

  • You will need an access to the indicator’s source code — .mq4 file for MetaTrader 4 and .mq5 file for MetaTrader 5. Sometimes indicators use more than one file for their source code. In such case, you would need .mqh files as well. You will not be able to add alerts to an indicator if you lack its source code. You can ask the indicator’s author for the source code if you only have a compiled file (.ex4 or .ex5).
  • Although you do not need to have prior coding experience to follow this tutorial, you still need to have some understanding of coding basics, for example: how to compile an indicator or what a variable is.
  • You need to pay attention to every step listed in this tutorial. Thoughtless copy/paste will not work here at all.

Input parameters

Theory

You are probably familiar with the different types alerts that exist in MetaTrader:

  • Native alert (popup)
  • Sound alert
  • Email alert
  • Push notifications (mobile)

Most of the time, traders want the plain native alerts but it is a good practice to implement all four at once and to give a choice (via input parameters) to enable and disable certain types of alert. You will learn to add four input parameters: EnableNativeAlerts, EnableSoundAlerts, EnableEmailAlerts, EnablePushAlerts. Read the rest of this entry