Originally, I intended this post as a
Contents
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:
- 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. - Identify indicator buffers that are used by an indicator and contain the data you want to be alerted about.
- 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
.
Another important input parameter is the candle to use for triggering the alert. Normally, you want the alert to be triggered on the close of the candle #1 when the latest candle (#0) has just started forming — that way you get a final and true alert (unless your indicator repaints itself). Sometimes, traders want to receive their alerts as fast as possible, then looking for alert conditions on candle #0 can be a better choice. Of course, the alert may turn out to be false as the indicator values on candle #0 a susceptible to changes with each new tick. The input parameter that controls the number of trigger candle will be called TriggerCandle
. It will be equal to 1
by default, but a trader will be able to change it to 0
.
If you plan using email alerts, adding an input parameter for an email subject is also a must. EmailAlertSubject
can be set to some fixed string or it can be modified by the alert code during
If you plan using push notifications to your phone or other mobile device, you need to enable and configure them in your platform via menu Tools->Options->Notifications.
All types of alerts need some text to display or send. AlertText
parameter can contain some preset text, which will also be modified according to the particular alert’s parameters.
One additional parameter is useful when using sound alerts — SoundAlertFile
. It can be used to set the name of the audio file for the platform to play during alert.
Practice
Find the last line starting with extern
(older MT4 indicators) or input
(MT5 and newer MT4 indicators) statement. Insert the following code after that line:
input int TriggerCandle = 1; input bool EnableNativeAlerts = true; input bool EnableSoundAlerts = true; input bool EnableEmailAlerts = true; input bool EnablePushAlerts = true; input string AlertEmailSubject = ""; input string AlertText = ""; input string SoundFileName = "alert.wav"; datetime LastAlertTime = D'01.01.1970'; int LastAlertDirection = 0; |
This code uses empty initial alert text and email subject. They will be filled during alert evaluation.
Identifying indicator buffers
Explanation
Indicator buffers are the vital part of almost any MetaTrader indicator. They contain the data, which is displayed on the chart or is used in calculations. Finding indicator buffers is very easy. Search for SetIndexBuffer
call. You will see one or more lines that look like this (in old MT4 indicators):
SetIndexBuffer(N, Buffer_Name); |
or like this (in newer MT4 or MT5 indicators):
SetIndexBuffer(N, Buffer_Name, INDICATOR_*); |
Where N
is the buffer’s number (you do not need it for alerts) and Buffer_Name
is the buffer’s name, which you need to formulate the alert conditions.
Now, the tricky part is to find the right buffers if there are more than one. In MT5 and newer MT4 indicators, you will see this INDICATOR_*
parameter in SetIndexBuffer
call, which can help determining the right buffers for alert – you will want those with INDICATOR_DATA
(they produce the actual display on the chart).
In some cases, determining the right buffer is easy – there might be only one, or it is called appropriately, or you know how the indicator works. In other cases, I would recommend some trial and error work if you do not want to study the code.
Examples
Looking at some real life examples of SetIndexBuffer
calls might help you finding the buffer names in the indicators you work on.
Lines 40-41 of the default MACD indicator in MetaTrader 4 show two buffers:
SetIndexBuffer(0,ExtMacdBuffer); SetIndexBuffer(1,ExtSignalBuffer); |
Obviously, ExtMacdBuffer
is the main line buffer and ExtSignalBuffer
is the signal line buffer.
If you look at the lines 29-31 of the .mq4 source of the CCI Arrows indicator, you will see three buffers there:
SetIndexBuffer(0,dUpCCIBuffer); SetIndexBuffer(1,dDownCCIBuffer); SetIndexBuffer(2,dSellBuffer); |
Naturally, you would think that dUpCCIBuffer
is for Up-arrows and dDownCCIBuffer
is for Down-arrows. But what is dSellBuffer
? The thing is that if you search the code for it, you will find that it is not used anywhere at all. It means that you can safely ignore it and base all your alerts on the former two buffers.
The MT5 version of the Aroon Up & Down indicator contains the following lines:
SetIndexBuffer(0, AroonUpBuffer, INDICATOR_DATA); SetIndexBuffer(1, AroonDnBuffer, INDICATOR_DATA); |
Both SetIndexBuffer
function calls have INDICATOR_DATA
parameters, which means that both buffers (AroonUpBuffer
and AroonDnBuffer
) contain values plotted on the chart. Clearly, AroonUpBuffer
is used for calculation of the Up-line and AroonDnBuffer
is used for the Down-line.
Lines 46-47 of the MT5 Coppock indicator also show two buffers:
SetIndexBuffer(0, Coppock, INDICATOR_DATA); SetIndexBuffer(1, ROCSum, INDICATOR_CALCULATIONS); |
The INDICATOR_CALCULATIONS
parameter tells us that ROCSum
is not an indicator buffer used for display but rather a buffer used for intermediate calculations. Coppock
is the only buffer that can be used for alerts here – unsurprisingly so because Coppock indicator is represented by a single histogram.
Alert conditions
Where
Now after you have successfully identified the names of the indicator buffers that you plan using in your alerts, it is time to add the actual alert conditions.
All alerts are appended to the end of the indicator’s main calculation function. In older MetaTrader 4 indicators, it is called int start()
. The alert conditions code should be inserted just above the last return(0);
statement inside that function. In newer MT4 and in MT5 indicators, the function is called OnCalculate
and its declaration can vary from one indicator to another. You have to insert the alert conditions code just above the last return(rates_total);
statement inside that function.
What
The actual conditions will differ depending on the alert type you wish to add to the given indicator. This guide will cover the three most popular cases: signal, level, and cross.
Signal
Signal is a type of alert that is triggered when some indicator buffer assumes some non-zero level. Arrow indicators would use this kind of alert normally. Adding alert to the aforementioned MT4 CCI Arrows indicator would look like this:
if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0)) { string Text; // Up Arrow Alert if ((dUpCCIBuffer[TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1)))) { Text = AlertText + "CCI Arrows: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Up."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "CCI Arrows Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = Time[0]; LastAlertDirection = 1; } // Down Arrow Alert if ((dUpCCIBuffer[TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1)))) { Text = AlertText + "CCI Arrows: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Down."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "CCI Arrows Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = Time[0]; LastAlertDirection = -1; } } |
The code should be added just before the latest return(0);
statement inside the start()
function.
Adding the same alerts to MT5 version of CCI Arrows is only marginally different:
if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0)) { string Text; // Up Arrow Alert if ((dUpCCIBuffer[rates_total - 1 - TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1)))) { Text = AlertText + "CCI Arrows: " + Symbol() + " - " + EnumToString(Period()) + " - Up."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "CCI Arrows Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = time[rates_total - 1]; LastAlertDirection = 1; } // Down Arrow Alert if ((dUpCCIBuffer[rates_total - 1 - TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1)))) { Text = AlertText + "CCI Arrows: " + Symbol() + " - " + EnumToString(Period()) + " - Down."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "CCI Arrows Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = time[rates_total - 1]; LastAlertDirection = -1; } } |
That code should be inserted just above the latest return(rates_total);
statement inside the OnCalculate
function. It assumes that the time and buffer arrays are not set as series. If they are, you would need to substitute TriggerCandle
for rates_total - 1 - TriggerCandle
and time[0]
for time[rates_total - 1]
.
Level
Level alerts are also very simple. If an indicator reaches a certain value (from above or from below), the alert is triggered. Single-line indicators shown in separate window use this kind of alert normally. Here is how the alert conditions for crossing of zero level would look in the MT4 version of Coppock indicator:
if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0)) { string Text; // Above Zero Alert if (((Coppock[TriggerCandle] > 0) && (Coppock[TriggerCandle + 1] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1)))) { Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Above Zero."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = Time[0]; LastAlertDirection = 1; } // Below Zero Alert if (((Coppock[TriggerCandle] < 0) && (Coppock[TriggerCandle + 1] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1)))) { Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Below Zero."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = Time[0]; LastAlertDirection = -1; } } |
The same for the MT5 version would look like this:
if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0)) { string Text; // Above Zero Alert if (((Coppock[rates_total - 1 - TriggerCandle] > 0) && (Coppock[rates_total - 2 - TriggerCandle] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1)))) { Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Above Zero."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = time[rates_total - 1]; LastAlertDirection = 1; } // Below Zero Alert if (((Coppock[rates_total - 1 - TriggerCandle] < 0) && (Coppock[rates_total - 2 - TriggerCandle] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1)))) { Text = AlertText + "Coppock: " + Symbol() + " - " + EnumToString(Period()) + " - Below Zero."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Coppock Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = time[rates_total - 1]; LastAlertDirection = -1; } } |
As is the case with the previously discussed signal alert for MT5, you would need to substitute TriggerCandle
for rates_total - 1 - TriggerCandle
and time[0]
for time[rates_total - 1]
if the indicator sets its buffers as series. Also, rates_total - 2 - TriggerCandle
would have to be changed to TriggerCandle + 1
.
Cross
Cross alerts are more complex than the previous two types. They are triggered when some indicator buffer crosses the price line or when two lines of an indicator cross each other, or when several lines cross each other. Let’s look at the cross alert implementation for MT4 Aroon Up & Down indicator. We will look for the Up-line crossing the Down-line from below and from above as two distinct alerts:
if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0)) { string Text; // Up-Line Crosses Down-Line from Below if (((AroonUpBuffer[TriggerCandle] > AroonDnBuffer[TriggerCandle]) && (AroonUpBuffer[TriggerCandle + 1] <= AroonDnBuffer[TriggerCandle + 1])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1)))) { Text = AlertText + "Aroon Up & Down: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Up-Line Crosses Down-Line from Below."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Aroon Up & Down Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = Time[0]; LastAlertDirection = 1; } // Up-Line Crosses Down-Line from Above if (((AroonUpBuffer[TriggerCandle] < AroonDnBuffer[TriggerCandle]) && (AroonUpBuffer[TriggerCandle + 1] >= AroonDnBuffer[TriggerCandle + 1])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1)))) { Text = AlertText + "Aroon Up & Down: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Up-Line Crosses Down-Line from Above."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Aroon Up & Down Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = Time[0]; LastAlertDirection = -1; } } |
The same code for MT5 Aroon Up & Down looks like this:
if (((TriggerCandle > 0) && (time[rates_total - 1] > LastAlertTime)) || (TriggerCandle == 0)) { string Text; // Up-Line Crosses Down-Line from Below if (((AroonUpBuffer[rates_total - 1 - TriggerCandle] > AroonDnBuffer[rates_total - 1 - TriggerCandle]) && (AroonUpBuffer[rates_total - 2 - TriggerCandle] <= AroonDnBuffer[rates_total - 2 - TriggerCandle])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1)))) { Text = AlertText + "Aroon Up & Down: " + Symbol() + " - " + EnumToString(Period()) + " - Up-Line Crosses Down-Line from Below."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Aroon Up & Down Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = time[rates_total - 1]; LastAlertDirection = 1; } // Up-Line Crosses Down-Line from Above if (((AroonUpBuffer[rates_total - 1 - TriggerCandle] < AroonDnBuffer[rates_total - 1 - TriggerCandle]) && (AroonUpBuffer[rates_total - 2 - TriggerCandle] >= AroonDnBuffer[rates_total - 2 - TriggerCandle])) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1)))) { Text = AlertText + "Aroon Up & Down: " + Symbol() + " - " + EnumToString(Period()) + " - Up-Line Crosses Down-Line from Above."; if (EnableNativeAlerts) Alert(Text); if (EnableEmailAlerts) SendMail(AlertEmailSubject + "Aroon Up & Down Alert", Text); if (EnableSoundAlerts) PlaySound(SoundFileName); if (EnablePushAlerts) SendNotification(Text); LastAlertTime = time[rates_total - 1]; LastAlertDirection = -1; } } |
Same as before, substitute TriggerCandle
for rates_total — 1 — TriggerCandle
and time[0]
for time[rates_total — 1]
if the indicator uses buffers that are set as series. Again, rates_total — 2 — TriggerCandle
would have to be changed to TriggerCandle + 1
in that case too.
Let’s illustrate the alert generated with these conditions with this screenshot:
Complex
Of course, the variety of alerts is not limited by the three types described above. Some alerts can have multiple dependencies (e.g. one line crossing the price while two other lines cross each other), other alerts might depend on time, volume, additional calculations, or a combination of various factors. It is even possible to add alerts to indicators that do not use buffers or plot anything on chart.
Such cases are not covered by this DIY guide. Some basic cases can be easily derived from the code snippets offered above while difficult cases are nontrivial ones and demand special approach and extra attention. However, you will certainly learn to add such complex alerts after some practice with the elementary ones.
Summary
In the end, I would like to summarize the
- Add the predefined input parameters just below the latest
extern
orinput
statement in the indicator’s source code. - Identify the buffer names that represent the indicator’s plot on chart.
- Insert the appropriate alert conditions code just above the latest
return(0);
insidestart()
function orreturn(rates_total);
insideOnCalculate
function. - Replace the buffer names with those that you identified in the second step.
Update 2016-12-21: I have updated the code snippets with correct examples. Previous versions would produce unlimited number of alerts if TriggerCandle was set to 0 (alert on the most current candle).
Update 2018-02-20: Listed the requirements for adding alerts to an indicator and provided instructions for adding push notification alerts to mobile devices.
NOTE: If you are trying to add alerts to an MT5 indicator and it doesn’t seem to be working, please check whether the source code uses ArrayAsSeries
function on the indicator or time buffers. If it does, see the paragraph below MQL5 example snippets for instructions on how to modify the alert code.
If you still have some general question about adding alerts to custom MetaTrader indicators or if you want to share your own tips for doing it, please use the commentary form below. If you want help with adding alerts to a specific indicator, please post about it in the forum. All requests for help posted via commentaries to this post will be ignored.
Muchas Gracias, lo entendi todo.
▼Reply
Fran Reply:
June 22nd, 2020 at 4:35 pm
Hola Maria!! como hago para que salga el TIME FRAME en la alerta , copie todo tal como aparece en el codigo , pero no sale el time frame en la alert de email!!
gracias
▼Reply
Andriy Moraru Reply:
June 22nd, 2020 at 5:53 pm
Make sure you have
EnumToString(Period())
in your Alert text.▼Reply
ANDREW NJOGU Reply:
June 28th, 2020 at 3:25 am
How do you put alerts to a coloured MA
▼Reply
Andriy Moraru Reply:
June 28th, 2020 at 9:09 am
If it is an MT5 indicator, then most likely the indicator plot is of DRAW_COLOR_LINE type and there is a separate buffer for the color index of the plot (marked with INDICATOR_COLOR_INDEX). You can check that buffer in conditions for alerts. It contains color numbers, so you can issue alerts, for example, if the value was 0 at previous candle and is 1 at the current candle or something like that.
If it is an MT4 indicator, then there is a separate indicator buffer for each color of the MA and you just check if the given buffer is non-zero.
▼Reply
Reinaldo Reply:
September 24th, 2020 at 12:53 pm
hi there, can you please help me, I´m trying to add an alert to the adx indicator, I just want to add an alarm at any adx level, that level must be variable, I want to be able chose that level, I´ve seen that indicator before but right now I couldn´t find it.
▼Reply
Andriy Moraru Reply:
September 24th, 2020 at 1:28 pm
For that, you can use the example of alerts for Levels provided in the post above. You would need to replace the Coppock buffer with ADX buffer and the zero level with some variable name. That variable name would have to be declared as an input parameter at the top of the code.
▼Reply
dear sir ,
i have one problem my indicator shows repaint…..
i want to add extra source code file like … source code file of refresh in every minute …is that possible…
plz kindly reply me.
i am waiting u r reply.
thanks
▼Reply
Andriy Moraru Reply:
October 1st, 2016 at 9:59 am
Sorry, but I don’t understand your request. Why would you want to add some extra code files to your repainting indicator?
▼Reply
Hi I have a question,
I’m trying to get an alert to my ADX, everytime DI+ and DI- hitting a value, say 20, I wish to get notified. However the alert is acting strangely it is reapeating the alert over and over again when it does cross the value, it would be realy awesome if you could explain to me what exactly I have to do to fix the problem.
Thanks in regards
▼Reply
Andriy Moraru Reply:
December 21st, 2016 at 8:29 am
Could you please share your indicator source code file and post a link here? So I could look at the problem?
▼Reply
Thank you for your fast response, I’m using the casual Average Directional Movement Index, you can find the whole script in your mt5 Indicators>Examples, I don’t know how to link it but I linked all the critical parts you mentioned in the blog
inputs & buffers
https://postimg.org/image/o9wx7vwml/
alert condition
https://postimg.org/image/a2i9sesx9/
▼Reply
Andriy Moraru Reply:
December 21st, 2016 at 5:32 pm
You can share your whole code via http://pastebin.com/ or a similar website.
▼Reply
ah great, there we go
http://pastebin.com/hRpeCwRc
▼Reply
Andriy Moraru Reply:
December 21st, 2016 at 9:18 pm
Thanks! I have found an error in the code (mine). Fixed version is here:
http://pastebin.com/qYnZQ7Ep
I have also updated the post to prevent such problems with alerts for other users.
Thanks for reporting the problem!
▼Reply
zen Reply:
December 21st, 2016 at 11:45 pm
Thank you for your fast response. I hope I set all the parameters correctly, your code is a lifesaver!
▼Reply
HELO
AS u have shown how to add alert for aroon UP and DOWN
I want to create MACD cross over alert what shoild I do..?
▼Reply
Andriy Moraru Reply:
January 1st, 2017 at 12:02 am
Look at the AroonUpDown example and replace the AroonUpDown buffers with the MACD’s signal and main line buffers.
▼Reply
Thank you very much for your comprehensive post regarding how to code alerts for MT4/MT5 custom indicators.
Unfortunately, I am currently stuck trying to add an alert to a channel indicator. What I want to do is fairly straight-forward. The alert should be triggered by price on the current candle equaling a certain channel level (in some instances only when price approaches from above, in others only from below).
To illustrate, please see: http://pastebin.com/McTZw0F6
I would be grateful, if you could give me advise on how to manipulate the code in order to create said alert.
▼Reply
Andriy Moraru Reply:
February 14th, 2017 at 11:13 am
You need to change “==” to “>=” when you want an alert of a price crossing a level from above. And you need to change “==” to “<=" when you want an alert of a price crossing a level from below. Also, you need to check whether the price was above/below the level a period before. For example, the first alert condition in your code should be changed like this:
▼Reply
That did the trick! A great many thanks to you.
Despite the risk of coming across as impertinent, could I ask you to give me an idea on how to add a function that pauses the alert for a certain time period (say five minutes, or until the current bar has finished) after it has been triggered?
Merci beaucoup.
▼Reply
Andriy Moraru Reply:
February 15th, 2017 at 10:34 am
Just add LastAlertTime != Time[0] to the conditions. Like this:
It will make it trigger only once on the current bar.
▼Reply
Again, vielen Dank.
Really, having at least some basic understanding of computer code seems to be indispensable.
▼Reply
Great article, thanks for sharing.
What I would like to know is, is it possible to add the option so you can select custom alert sounds instead of the default alert.wav?
▼Reply
Andriy Moraru Reply:
February 21st, 2017 at 4:28 pm
Yes, just replace alert.wav with the filename of your choice.
▼Reply
Enigma Misterio Reply:
October 31st, 2018 at 7:45 pm
so is it possible to add different alert sounds to different indicators?
▼Reply
Andriy Moraru Reply:
October 31st, 2018 at 8:01 pm
Yes, it is possible.
PlaySound()
functions takes a sound filename as an argument. Most indicators with alerts (and also the code examples in this post) use an input parameter for the sound filename, which is usually “alert.wav”. You can set a different sound file name for different indicators and have them alert you with different sounds.▼Reply
I am a complete technophobe, but I would like to set up an alert when 10ema crosses 20ema. I would appreciate your help
▼Reply
Andriy Moraru Reply:
March 3rd, 2017 at 9:47 pm
You would probably need a custom indicator coded for that.
▼Reply
I have a channel indicator that works well, but I would like to add alerts to it when the candle enters the retracement zone of the channel. I understand your steps, but how do I access the code on the indicator so as to add the alerts? Hope you understand my question.
▼Reply
Andriy Moraru Reply:
March 25th, 2017 at 10:06 pm
Right-click on the indicator in the Navigator window of your platform and select Modify:

If you there is the source code file for the indicator in your platform, it will open it. Otherwise, you have only an executable (.ex4) and you have to ask the author of the indicator for the source code file (.mq4).
▼Reply
Thank you sir! But I have a problem: the alert repeats on every new bar:(
https://pastebin.com/9c84G2YF
▼Reply
Andriy Moraru Reply:
March 29th, 2017 at 9:27 am
The problem is because the indicator is written incorrectly – the alert code you’ve added is fine. To fix the issue, just add these two lines to between the current lines 117 and 118:
Also, in case you do not know, this indicator is repainting the arrows – it only draws them 3 bars into the future. E.g., if there is a turn in line, it waits 3 bars to confirm it and then draws an arrow like it appeared 3 bars ago. This also means that you will never get an alert for such an arrow if you set TriggerCandle to 1. If you want to get arrow alerts here, your TriggerCandle should be equal to SignalHP.
▼Reply
Wow, thanks a lot!
▼Reply
I can get the alert to sound in my own chosen wav file, can you look through it? The wav i want to be played when the pop up box also comes is “Bicycle-Bell-Ringing.wav”
heres the whole code, it for when stochastics above/below 80/20 and cross back below
https://pastebin.com/NSbDriRS
▼Reply
Andriy Moraru Reply:
April 5th, 2017 at 6:08 pm
Please do not submit such huge pieces of code in comments. Either upload your indicator somewhere and share a link or use pastebin.
As for your questions:
For PlaySound() to work with your custom .wav file, the file has to be located in /Sounds/ subfolder of your platform’s data folder.
To change what sound is used when Alert() function is called, go to Toos->OptionsE->Events and change the sound file near Alert:

▼Reply
Andriy.. first of all thanks for sharing your knowledge!
i use an indicator that have alert code but did not work
tried to fix as you wrote here, but couldn’t compile then
Would you mind to help me with it?
here’s the link
https://www.mql5.com/pt/code/1910?utm_campaign=codebase.list&utm_medium=special&utm_source=mt5terminal&utm_link=c23d219487dcc91964731d98bd1cdd42&utm_codepage=1046&utm_gid=8881070706134349491&utm_uniq=66D6D7AD-0E29-T-170507
thank you!!!
▼Reply
Andriy Moraru Reply:
May 20th, 2017 at 5:34 am
I do not code on request. As far as I can see, that indicator already has alerts added.
▼Reply
Daniel Demian Reply:
May 20th, 2017 at 1:46 pm
I did not want to be disrespectful, I do not know anyone who program mql5, the way you explained with this post just thought that at a quick glance you could see what is wrong in the code that does not work the alert and give me a tip How to fix it! Forgive me if I was pretentious, here was the only place I found some good material for this problem !!! thank you
▼Reply
Andriy Moraru Reply:
May 20th, 2017 at 6:59 pm
You can start a thread about it in our forum about MetaTrader indicators – perhaps, someone will be able to help you out there.
▼Reply
Daniel Demian Reply:
May 20th, 2017 at 7:31 pm
thank so much
▼Reply
Thanks for taking the time and patience to write this out. I’ve been trying to understand it for quite awhile. It takes someone like you to completely explain it and that’s not easy to find. I appreciate it.
▼Reply
Thanks for the post, unfortunately I think I may have made an erro, as I cannot seem to get the script to work. I have pasted it at and would love if you could let me know where I have gone wrong. Apologies for the most likely silly error!
https://pastebin.com/70UG9t3B
▼Reply
Andriy Moraru Reply:
June 26th, 2017 at 2:06 pm
Why do you do this?
It will not work if arrays are not set as series. If you want to use such arrays, then you have to modify the alert conditions accordingly. For example, the number of the latest bar is no longer 0, it is rates_total-1, and the number of the pre-last bar is no longer 1, it is rates_total-2.
▼Reply
Hey buddy,
Great article. I would like to attach a file with this message. How do I do that?
▼Reply
Nick Reply:
July 6th, 2017 at 4:20 pm
I keep getting errors. How do you add alerts for red or blue dot signals?
▼Reply
Andriy Moraru Reply:
July 6th, 2017 at 8:46 pm
I don’t see any code here that would add alerts.
▼Reply
Andriy Moraru Reply:
July 6th, 2017 at 8:12 pm
Please use pastebin.com to share large pieces of code.
▼Reply
Great article !!!! I successfully added alerts to my Keltner indie :)
▼Reply
Hi,
Thanks for the article, it’s great! I would like to add a sound alert to the force index (mt5), but I’m having difficulty understanding step 3, alert conditions, where exactly to add it and how to change the code to get a sound alert when price crosses levels at 6000 and -6000, please could you help me?
Thanks…
▼Reply
Andriy Moraru Reply:
July 26th, 2017 at 5:30 pm
In case of Forex Index, ExtForceBuffer is the buffer name. You should be placing your alert conditions after this line:
And repeat them after this line:
▼Reply
Nigel Reply:
July 26th, 2017 at 6:45 pm
I tried to add the code you gave for levels into the force index code in the positions you advised with the intension of editing where nessecary to get the desired results but when i hit compile it brings up number of errors and warnings, errors are all ‘undeclared identifier’ and warnings are all ‘implicit conversion of ‘number’ to ‘string”.
▼Reply
Andriy Moraru Reply:
July 26th, 2017 at 7:11 pm
You need to make sure you follow the instructions provided in the tutorial.
▼Reply
Nigel Reply:
July 27th, 2017 at 2:28 pm
I’ve gone over the instructions again and copied the code verbatim, but I’m still getting 2 errors, both ”Coppock’ – undeclared identifier’. I’m not any good with coding so I have no idea how to fix these errors…
▼Reply
Andriy Moraru Reply:
July 27th, 2017 at 2:30 pm
Unfortunately, I cannot read people’s minds. If you share your code via pastebin.com, I would be able to look at it and help you.
▼Reply
Nigel Reply:
July 27th, 2017 at 10:01 pm
https://pastebin.com/8UWdWxgn Here is the code in pastebin.com. Hope you can help. Thanks…
Andriy Moraru Reply:
July 28th, 2017 at 5:10 am
What is that Coppock buffer you are trying to use in your alert conditions?
Nigel Reply:
July 27th, 2017 at 4:16 pm
Sorry, I have been trying to embed the code from pastebin.com but it doesn’t seem to be working. I copied the code from metaeditor, pasted into pastebin, copied the embed code, pasted it here but nothing is happening. I tried both the embed options, but I don’t know what’s going on. I’m sorry for taking up your time with my lack of knowledge but I am honestly stuck right now…
▼Reply
Andriy Moraru Reply:
July 27th, 2017 at 5:39 pm
You don’t need to embed anything here. Just copy and paste the link to the pastebin share you created.
I copied the section of code in the tutorial and added the conditions to the force index indicator. I didn’t add or remove anything just applied the example code in the appropriate places.
▼Reply
Andriy Moraru Reply:
July 28th, 2017 at 9:26 am
You need to follow the steps 2 and 3 of the tutorial. I have already replied to you with the buffer name you need to check, so you can skip step 2. Copying example code into a different indicator will not work.
▼Reply
Hi Andriy,
You taught me ‘how to fish’. Now I just created alert for two indicators with your instructions here and it’s working fine. Thank you very much for your great post.
▼Reply
Andriy Moraru Reply:
August 18th, 2017 at 6:44 am
I am glad it helped you!
▼Reply
Hi Andriy,
i have added successfully email and sound alert into indicator, but why it is not attached on chart.my mt4 version is 4 and build 1090.
i have also attached code here. plz fix it
CODE REMOVED
▼Reply
Andriy Moraru Reply:
August 27th, 2017 at 5:58 am
I have removed the indicator’s code as it looks like a decompiled one. I am not going to discuss decompiled code here.
As for your question, check if there are any compilation errors in MetaEditor when you compile it. It looks like it did not compile. If it does compile without errors, check the Expert tab output in the platform when you try to attach the indicator to the chart.
▼Reply
Dear Andriy Moraru,
Appreciations for this great post.
I just added alert for “stepma color” indicator. Everything works well except it gives alert on each new candle. Could you please guide me to correct the issue.
here is the code: https://pastebin.com/ka4r2J04
▼Reply
Andriy Moraru Reply:
September 21st, 2017 at 10:41 am
Nice work! But you should have used the Level type of alert from the post instead of Signal. Your indicator’s buffer changes to Up or Down and stays there. Try changing the alert conditions so that they are similar to those in the Level alert example in my post.
▼Reply
Ravi Reply:
September 22nd, 2017 at 4:13 am
Dear Andriy Moraru,
Thanks for your kind reply. I used only the first example CCI arrow signal alert code. Please see in the line no: 119 it is “// Up Arrow Alert”. In the CCI arrow example there is only one signal for trend change. But in my indicator signal dots displays on every candle and only changes color when trend change. I do not know how to get alert only at color change and to stop alert on next candle(trigger candle+2).
▼Reply
Andriy Moraru Reply:
September 22nd, 2017 at 10:14 am
As I have said, you need to use Level example, not Signal.
▼Reply
Dear Andriy,
oops, i misunderstood. Now i am clear on that point now, but still have doubts in logic.
Coppock has separate window indicator and had used zero cross. Here, step ma is on-chart indicator and have no cross value except price. In the code there are only two buffers blue and red dots and not crossing anything.
If you have spare time please clarify.
It will be very useful for all on-chart color change trend indicators like HMA, Non-lag ma etc.
▼Reply
Andriy Moraru Reply:
September 22nd, 2017 at 4:29 pm
You need to use the Coppock (Level) example because you want alerts on indicator’s level change – from no signal (-1.0 value) to some price level. The colors and chart/separate window don’t matter at all here. Just make sure that your alert condition checks that the current value is above zero (it already does that in your pastebin) AND that the previous value was below zero.
▼Reply
Dear Andriy,
Thank you very much. I successfully added alert. I think this page is very precious for non-programmers.
https://pastebin.com/VQqnWfNa
▼Reply
Andriy Moraru Reply:
September 25th, 2017 at 9:54 am
I am glad it worked for you!
▼Reply
Great info but I’m still experiencing some challenges after trying for a few days now to adds alerts to these particular indicators:
1. WATR
2. Extreme RSI
▼Reply
Andriy Moraru Reply:
October 13th, 2017 at 2:01 pm
It does not look like you tried to add the alerts here.
Also, the second indicator is clearly a decompiled source code, which is against the MetaQuotes EULA, – I will not discuss adding alerts to the decompiled indicator.
▼Reply
Hello, Can somebody help me add an alert with my indicator? thank you so much
▼Reply
Andriy Moraru Reply:
December 1st, 2017 at 9:23 am
Have you tried following the tutorial provided in this post? Also linking to your indicator (via Pastebin for example) would be helpful.
▼Reply
Kenni Siu Reply:
December 1st, 2017 at 4:20 pm
▼Reply
can you add in the code for the alert? thank you..
▼Reply
Andriy Moraru Reply:
December 5th, 2017 at 10:55 am
First, please do not post such big pieces of code as comments. Publish them via pastebin.com or similar websites. Second, it is a decompiled indicator. I do not discuss decompiled indicators as it is against the MetaTrader’s EULA to decompile the .ex4 files. You need to contact the author of the original indicator and ask him or her to add the alerts to the indicator.
▼Reply
I got a custom indicator on the MQL5 Community and will like to add alarm to it. can that be possible?
▼Reply
Andriy Moraru Reply:
December 30th, 2017 at 7:29 am
Probably, yes. Did you try following this tutorial?
▼Reply
Good Day, as a newbie i am keen to learn, i have an indicator that i fished off the net and see potential for it, in that i am looking for low time frame entry opportunities in conjunction with higher time frame technical analysis, i have a career in electronics and currently have a vague idea about coding, it is a histogram that needs an audible alert at condition
change, there are two buffers, i currently have to visually monitor entry points .
Are you interested in helping?
▼Reply
Oh yes i gave your tutorial a go but stumble after the first step
▼Reply
Andriy Moraru Reply:
January 2nd, 2018 at 10:26 pm
So, you failed to identify the names of the buffers used in the indicator? You can recognize them by finding the calls to SetIndexBuffer() function and looking at the variables it refers to.
▼Reply
Don Munro Reply:
January 3rd, 2018 at 7:20 am
Thanks Andriy, i’ll give it a go
▼Reply
Don Munro Reply:
January 3rd, 2018 at 8:51 am
i am pulling my few hairs out here.. can i send you the MQL4 Source File?
▼Reply
Andriy Moraru Reply:
January 3rd, 2018 at 8:57 am
You can upload it to pastebin.com and post the link here.
▼Reply
Don Munro Reply:
January 3rd, 2018 at 11:45 am
Here we go, thanks Andriy https://pastebin.com/ph0j9Dg6
▼Reply
Andriy Moraru Reply:
January 3rd, 2018 at 6:37 pm
The names of the indicator buffers are upBuffer and dnBuffer.
▼Reply
Don Munro Reply:
January 18th, 2018 at 11:51 am
Hi Andriy, i have identified (rates_total-counted_bars,rates_total-1);
and i must add code just above, man now i am cofused, please help..
Andriy Moraru Reply:
January 18th, 2018 at 12:05 pm
What do you mean?
Don Munro Reply:
January 3rd, 2018 at 2:50 pm
The alert must be on the 2nd “barlock”/”signal lock” when the histogram changes from red to green
▼Reply
Hi Andriy,
Thank you for creating this post, this was the only really helpful article I found online on this subject. Keep it up.
I added the alerts to a indicator. It works. Yeayy. That is 1 step to the right direction.
However, I have 2 challenges with it.
1) It gives for one alert both arrow’s texts, making it confusing.
2) When I attach the same indicator to more charts at the same time, if one chart gives a alert, the app gives me alerts for all charts the indicator is attached to (with the same confusion as challenge 1).
Can you share with me some pointers of how to fix it?
The code you can find here https://pastebin.com/3QstgTR0
▼Reply
Andriy Moraru Reply:
January 2nd, 2018 at 10:57 pm
Adding these two lines after the line #75 will probably help with your first issue:
As for your second issue, what do you mean by “the app”? There is no way, this indicator can give alerts based on data from the other charts. Unless there is some serious bug in MetaTrader 4 itself, which I highly doubt.
▼Reply
Hey Andriy
I followed you instructions to add an alert to a pinbar indicator. Problem is, it keeps poping the alert even when the arrow has not appeared on the chart. Could you kindly help fix it and only give a pop up alert when the indicator makes an arrow in the chart?
HEre is the link to the code: https://pastebin.com/jyFZ7k2C
▼Reply
Andriy Moraru Reply:
January 10th, 2018 at 3:01 pm
The problem is that the Up[] and Dn[] buffers are not assigned zero values by default (the actual default values used are 2147483647), which means that they will always be greater than 0. To fix this, you can do the following. Add this on line 106:
and this on line 101:
▼Reply
Thanks Adriy
I have added the two lines you suggested and it works perfectly now. However, i still have one more problem. I have another Pinbar indicator which is slightly more sensitive than the one i sent you but the code is almost similar. I added the codes just like i did in the first one including the two lines you suggested later. However it is not popping an alert but its putting an arrow on the chart. I have attached the original code(the one without an alert) and the modified code(the one i tried adding an alert) in the modified code, you will notice i added these two lines:
datetime LastAlertTime = D’01.01.1970′;
int LastAlertDirection = 0;
on line 20 and 21 after it gave me an error. Could you help me identify why its not poping an alert?
Original code: https://pastebin.com/5EFRSUDt
Modified code: https://pastebin.com/C1HdjZTq
Also, my compiler is giving me two warnings:
variable “highest” not used – line 62
Variable “lowest” not used -line62
Kindly help me resolve that as well. Looking forward to hearing from you.
Thanks alot
▼Reply
Andriy Moraru Reply:
January 11th, 2018 at 8:25 pm
Remove return(0); on line 112. This line prevents anything below it from ever executing by telling the program to return from the current function.
You can get rid of the warnings by removing the declaration of those variables. However, these warnings are harmless and will not affect the execution of your indicator.
▼Reply
Nje Reply:
January 12th, 2018 at 4:20 am
Thanks, Man. This has helped a lot
▼Reply
please i have tried the process but i only get alert when i change timeframe it does not show alert when chart is running
▼Reply
Andriy Moraru Reply:
February 6th, 2018 at 9:02 pm
That probably means that you have done something wrong. It is difficult to say what without seeing the code.
▼Reply
Hello, i’m new in this things, i use mt4 and an indicator for binary option. But i need to put an alert when the arrow appear on grafic. I’m from romania and also i don’t speak very good english so i dont’ know hot to write all the code. Need some help please.
https://pastebin.com/QUyLJpmp
▼Reply
Andriy Moraru Reply:
February 19th, 2018 at 7:19 pm
It should not be difficult to add the alerts to this indicator if you follow my tutorial. You can learn how to do it if you study the examples for the signal type alerts.
▼Reply
Predescu Florin Reply:
February 20th, 2018 at 12:20 pm
https://pastebin.com/AYtqX10y
can you tell me what it’s wrong here to try to change this?
▼Reply
Andriy Moraru Reply:
February 20th, 2018 at 1:58 pm
The tutorial is pretty straightforward:
1. Add input parameters.
2. Identify indicator buffers.
3. Formulate alert conditions.
It does look like you’ve made it through these steps. You just copied the code from the example.
▼Reply
Predescu Florin Reply:
February 21st, 2018 at 1:52 pm
Hello, I just try to follow your steps..first one it’s done, second one i find the indicator buffer:
SetIndexBuffer(0,b1);
SetIndexBuffer(1,b2);
But after the step nr 3, i don’t know what to change in your example from arrows. i put the example jut before the last return..please, if you have some time, tell me what to change at the step nr 3, and if the step 1 and 2 are good. Thx
https://pastebin.com/ggFJsBbK
▼Reply
Andriy Moraru Reply:
March 2nd, 2018 at 5:56 pm
I think that you would get better results if you were using the names of the indicator buffers that you have found instead of the names you copied from the example in the alert checking conditions code.
▼Reply
https://pastebin.com/AYtqX10y
i tried just like you said in examples for arrows..but it’s not working
▼Reply
Andriy Moraru Reply:
February 20th, 2018 at 11:13 am
Sorry, but you have to follow the whole tutorial rather than just copy and paste a piece of the example code.
▼Reply
Please i need help in getting an alert to EMA indicator arrow. Please help me https://pastebin.com/KxPACBy3
▼Reply
Andriy Moraru Reply:
March 2nd, 2018 at 5:52 pm
You can try following the tutorial. Actually, it is posted here to help you add the alerts.
▼Reply
Hi guys, anyone knows how to code an alert in mq4 please..I need to have an alert for when there is a color change signalling a reversal. Please have a look at the pic attached. At point 1 we can see that as the candle reversed into an uptrend there was a color change in the 2FMA’s (from red to blue and at the same time from pink to cyan colour)..the change occured SIMULTANEOUSLY, THAT IS CYAN AND BLUE COLORS APPEARED SIMULTANEOUSLY ON BOTH FMA’S. In point 2 you can see that the opposite happened (PINK COLOUR APPEARED FIRST BEFORE THE RED). I need an alert for ONLY WHEN THE COLORS APPEAR SIMULTANEOUSLY, ONLY SIMULTANEOUSLY (CYAN AND BLUE SIMULTANEOUSLY AND PINK AND RED SIMULTANEOUSLY). I need urgent assistance.
▼Reply
Hello
I tried the alert indicator but I am getting errors as I tried to compile.
here is my code
https://pastebin.com/8KVc2cWf
▼Reply
Andriy Moraru Reply:
March 2nd, 2018 at 5:51 pm
Sorry, your pastebin page is not opening.
▼Reply
Hi Adriy,
Here is the coding in term of my last comment. Id be appreciative if i can get the correct coding, that is, WHEN THE CYAN (AQUA) CHANGES COLOR EXACTLY AT THE SAME TIME AS THE BLUE COLOR IN AN UPWARD AND THE FUCHSIA (MAGENTA) COLOR CHANGES COLOR EXACTLY AT THE SAME TIME AS THE RED COLOR IN A DOWNWARD TREND. These are 2 moving averages (one with cyan and aqua color and the second with blue and red colors).
(Code removed.)
▼Reply
Andriy Moraru Reply:
March 2nd, 2018 at 11:59 am
Yanga, please do not insert large pieces of code into comments. You can use pastebin.com to share the source code and imgur.com to share images.
However, your code is a decompiled indicator. I will not help with any modifications to decompiled indicators and will not allow discussing decompiled code here. Please contact the author of the original indicator and ask him or her to modify it.
▼Reply
Hi,
Sort of new to this , I got the RSIoMA cross Ok, but having trouble with editing a level 50 alert
https://pastebin.com/eBYv4qwS
any advise would be appreciated
▼Reply
Andriy Moraru Reply:
March 2nd, 2018 at 5:50 pm
You should not compare TriggerCandle to ’50’. You only need to compare the indicator’s buffer with the alert level. TriggerCandle is number of the candle, which should be checked for the alert condition. Usually, it is either 0 or 1.
Also, your code is checking RSI values, not RSIoMA – not sure if that is what you want to achieve.
▼Reply
hello, i tried yout method of adding alert to this indicator but it stopped working the moment i add the alert code, i mean it does not display again untill i removed the alert code. The name is Beginner indicator.
https://pastebin.com/LnRRFVe6
▼Reply
Andriy Moraru Reply:
March 16th, 2018 at 2:39 pm
It does not look like anyone have tried adding any alerts to this indicator.
PS: By the way, there is little point in adding alerts to Beginner as the indicator repaints itself.
▼Reply
Alabi Christopher Reply:
March 17th, 2018 at 1:02 pm
does that mean alert will not work with it? or adding alert is not an option
▼Reply
Andriy Moraru Reply:
March 17th, 2018 at 2:56 pm
That means that the alerts would be useless because they would appear either too late (alerting about the dots which the indicator draws in the past – beyond the period of repainting), or on the dots that would soon disappear as the indicator repaints them. Just launch the Beginner indicator in the Strategy Tester fast forward to see what I mean.
▼Reply
can you help me please pray with a good signal indicator? which one do you use? he attached one here, so there is no one who does what. Thanks and I’m awaiting a reply by mail .. a good day
▼Reply
Thanks a lot. This post is very helpful.
▼Reply
Hi Andriy
After reading your great article on adding alerts on MT4 and MT5 indicators, i tried a few for myself successfully ie ADX and Stochastic which are my favorite indicators, however i am still learning without success how to combiine these two indicators into one.
What brings me here today is this https://pastebin.com/bj5H5LiC a free stochastic x8 indicator i got from MQL5 community and added two alert conditions to it, however my intention is to have one alert when all the lines are above the 80 level and on a different alert when all the lines are below the 20 level.
as of now it seems to send an alert for every different line which is not how i need it to work.
i have identified: Ind[numb].IndBuffer as this indicators buffer but that didnt work until i substituted “[numb] for [0].
▼Reply
Andriy Moraru Reply:
May 24th, 2018 at 9:37 am
Nice job on adding alerts here! There were three problems with the code:
1. There are several lines check (the default number is 5 and it is defined using
LINES_TOTAL
macro). So a simple condition would not work. You have to cycle through all 5 lines each time and check whether all are above 80 or all are below 20.2. The indicator buffers are set as timeseries using this line in the
OnInit()
function:This means that to access the latest bar you write
Ind[numb].IndBuffer[0]
instead ofInd[numb].IndBuffer[rates_totale - 1]
.3.
LastAlertDirection
should be compared to-1
on line 171 of your code:should be:
This condition is needed to avoid alert popping up each tick when working with the latest bar –
LastAlertDirection
remembers the previous alert direction (-1
for “below 20” alert) and checks all further alerts if they are of the same direction.You can download the fixed indicator here:
https://www.earnforex.com/blog/files/multistoch_alert.mq5
I have added code commentaries to explain the cycles.
▼Reply
Aphelele Reply:
May 24th, 2018 at 10:08 pm
Thank you very much Andriy
Indicator works well especially on higher time frame.
your assistance is highly appreciated.
▼Reply
Hello Andriy,
I was so happy to find your article…I read it carefully and tried to add the alerts several time(adding input parameters, identify indicator buffers, set alert conditions) but did not get to work them. The other problem, after modified the original mq4 file, it could not be added to the chart.
Dear Andriy…this indicator (Symphonie SentimentEmotion Combi Indikator v1.0) is my most favorite one. Please help me and add the alerts, specially the E-MAIL ALERT by changing the colors. I do not get ahead of that.
Here is the link of the original mq4 file:
https://www.forexfactory.com/attachment.php/2098330?attachmentid=2098330&d=1481300362
Thank you very much for your assistance
best
VV
▼Reply
Andriy Moraru Reply:
May 26th, 2018 at 1:57 pm
I don’t quite get it. There is currently a normal popup alert coded in this indicator. Do you want email alert to trigger at the same time as the current popup alert? Or do you want it under different conditions?
▼Reply
vadvid Reply:
May 27th, 2018 at 12:11 pm
Dear Andriy. As you see the indi produce three different colors. I’d like to have an e-mail alert only in case the color becomes BLUE or RED. (the color yellow is uninteresting).
Thanks
VV
▼Reply
Andriy Moraru Reply:
May 27th, 2018 at 1:09 pm
You can replace this condition:
with something like this:
▼Reply
Thanks a lot Andriy,
I’ll try to use is it incl. your instructions.
Thanks again
VV
▼Reply
I understand your explanation but according to my indicator I want the alert only once after the condition meet. I use 3 exponential moving Average and the parabolic SAR all in mq5. Please can you help me how to deal with this.
▼Reply
Andriy Moraru Reply:
June 7th, 2018 at 7:03 am
By “only once” you mean that the alert is triggered only once in the indicator’s lifetime (after you attach it and before you detach or close the platform)? Or once for each instance of conditions met (e.g. 3 EMAs cross – alert; after a few bars, the EMAs cross again – new alert)? If you are talking about the latter, then the tutorial explains just that case. If you check and update
LastAlertTime
variable, the indicator will not issue more than one alert per bar.▼Reply
hELP ME INSERT A SOUND ALERT WHEN THE IN INCATOR CHANGES COLOUR
▼Reply
Andriy Moraru Reply:
June 17th, 2018 at 10:18 am
Before you add alerts to an indicator, you should first fix the errors, which prevent its compilation.
▼Reply
You can help me put the alert on the gauge, I’m doing as in the tutorial but it’s not working.
▼Reply
Andriy Moraru Reply:
June 30th, 2018 at 1:15 pm
The code seems to have gotten corrupted when you inserted it in a comment. Please share it via pastebin.com or some file-sharing website.
By the way, why don’t you ask the indicator’s author – perhaps, he already has a version with the alerts.
▼Reply
Renan Reply:
July 2nd, 2018 at 4:38 am
https://pastebin.com/HXX5Psv8
I already sent a message to the creator he told me that incador counted the number of candles followed and he sent me saying that he could change to count alternating candles and he does not support.
If you could help me, I would appreciate it.
▼Reply
Andriy Moraru Reply:
July 2nd, 2018 at 9:19 am
OK. Now I see the problem. In your alert condition, you have to compare
BuyBuffer[rates_total - 1 - TriggerCandle]
againstAccount
, not justBuyBuffer
. The latter is just the name of the buffer, whereas the former is the particular value in that buffer (the last finished candle ifTriggerCandle
is set to 1).▼Reply
Renan Reply:
July 2nd, 2018 at 1:20 pm
https://pastebin.com/X8Xs7mPa
I did as you said and the alert does not work, you can look at what’s wrong please.
▼Reply
Andriy Moraru Reply:
July 2nd, 2018 at 1:24 pm
No idea, you can try asking in the forums.
▼Reply
Great Post. I Followed the instructions and created some signal alerts for my Arrow Chart. However they keep repeating and when i open a new chart both signals show on the chart. Can you help me adjust it to where the alert only happens when one arrow shows on the chart.
https://pastebin.com/g42D0aCY
thanks
▼Reply
Andriy Moraru Reply:
July 9th, 2018 at 5:18 am
No, but you can post your question in the indicators forum.
▼Reply
Please can you help add an arrow pop up alert to Bears and Bulls MT4 indicator? It’ll apply to close of candle to avoid repainting. The arrow and alert show up only for the bear indicator when and only if the histogram crosses from positive to negative value and also show up only for the bear indicator when and only if the histogram crosses from negativeto positive value.
Thanks
▼Reply
Andriy Moraru Reply:
July 16th, 2018 at 10:55 am
No, but you can post your question in the indicators forum.
▼Reply
Hi there! Can you please help me out with adding alerts for RSI indicator? I actually did copy and pasted one of the codes above, and I still dont recieve alerts even if the code does not show any problems after compiling. Im just starting to learn how to do this. I hope you guys can help me out. Thanks in advance! :-))
▼Reply
Andriy Moraru Reply:
August 15th, 2018 at 8:00 pm
Copy and pasting wnon’t work. You will have to follow the tutorial.
▼Reply
Thanks for responding… Actually, I did make it send alerts but it crashes my mt4 due to it sending too much alerts since i coded this…
▼Reply
Andriy Moraru Reply:
August 16th, 2018 at 6:06 am
You should follow the tutorial to make that work correctly. If you need help, you should ask at the for it in the forum.
▼Reply
Hi, thankyou very much for taking the time to share this. : ) Its great to be able to add the push notifications!
▼Reply
can you help me put alert to my indicator
▼Reply
Andriy Moraru Reply:
October 4th, 2018 at 7:52 am
No, but you can ask here if you find following the tutorial difficult:
https://www.earnforex.com/forum/forums/metatrader-indicators.12/
▼Reply
Please help me in provide a code for the following specification.
If i have 3 EMA’s. for example; fast Ma- 2, medium MA – 4 and Slow MA-25. i want indicator to alert me with the signal in the chart.
it should alert as:
1) if fast Ma and medium MA cross above 50 MA then it should alert as Buy.2) vice versa of 1
Can any one of you help me in writing mt4 code
▼Reply
Andriy Moraru Reply:
October 22nd, 2018 at 2:56 pm
Do you have the code for the indicator that shows the three EMAs on the chart? If not, then this tutorial won’t help you. You have to code an indicator somehow first.
▼Reply
Hello , I would like to thank you for putting out this vitally important information to help get the most out of our trading indicators. I was looking for this sort of info for a long time. Its not easy what you do..Im just glad i found you when I did. So, I have this indicator I tried applying the instructions for making it an alert indicator. It compiled but wouldn’t open in my charts. I try and get this notification “cannot open file ‘C:\Users\Brian\AppData\Roaming\MetaQuotes\Terminal\8395B50B21A2D108FA5AA50E09F37B3F\MQL4\indicators\ADXcrossesNon-repainting + Alert.ex4’ [2]” . So i put the mql code in paste bin for you to take a look and see if I did something wrong. I would really appreciate if I could get this working. Thank you so much for all your help.
Paste Bin link: https://pastebin.com/taGJwg4i
▼Reply
Andriy Moraru Reply:
December 28th, 2018 at 7:25 am
If it compiled without errors, then there is no problem with the code. Please make sure that the ex4 file is generated in the folder mentioned in the MT4 error and that MT4 process has privilege to read that file.
▼Reply
how to add a trend line break out alert on an indicator? for example I have a macd indicator, and I draw a line on macd , how to set a alert when the macd line break out the trend line? thanks
▼Reply
Andriy Moraru Reply:
January 21st, 2019 at 8:38 pm
You would have to code a custom indicator for that and not a trivial one too.
▼Reply
george88 ma Reply:
January 27th, 2019 at 1:11 am
would you tell me where to start codding trend line breakout alert on indicator? I already find the trend line break out alert on price, but not sure how to change that into alert on indicator.
▼Reply
Andriy Moraru Reply:
January 27th, 2019 at 5:57 pm
So, you have an indicator that alerts you when the price breaks a trendline? Then, changing it to use an indicator’s value instead of the price when checking alerts should be trivial. You just read the included indicator values in your own indicator and compare them with the trendline in place of the price.
▼Reply
kindly help me add the pop up Alert showing the pair + Push Notification on this one, i cant seem to identify the buffer to trigger the action. Thanks
[CODE REMOVED]
▼Reply
Andriy Moraru Reply:
March 2nd, 2019 at 3:08 pm
Please do not paste such huge pieces of code into comments. Use pastebin.com or similar resources to host the code.
From what I’ve seen, you have correctly identified the buffer, but you’ve placed the alert checking code into the initialization function, which runs only once on indicator attachment. The alert checking routines should be in the start() function.
Also, it seems like the indicator already had alerts implemented in the first place.
▼Reply
Hi Andriy, thank you so much for helping so many people understanding how to code, is really difficult to find someone like you, once again Thank you!
If it’s not to much trouble, I would like to ask you how can I add a pop up alert with sound in my arrow indicator, he only has an an option to change sound on or off and I tried to follow your tutorial but I don’t have enough knowledge to do it.
The indicator doesn’t repaint, here is the link: https://pastebin.com/imY41R86
TY
▼Reply
Andriy Moraru Reply:
March 12th, 2019 at 6:57 pm
Sorry, but that’s a decompiled indicator. I do not provide help with decompiled code.
▼Reply
Hello Andriy,
I have a RSI Monitor Indicator in multi time frame. Indicator codes as below
I wanted to add push alert to that indicator. I couldn’t do it. And also when indicator is opened in M1 time frames, it repeats itself with the each candle close. For example, if the RSI is over 7- and as long as it stays over 70 in M1 timeframe, it repeats it with every candle close.
Could you help me to solve this problem?
Here is the link of the indicator https://pastebin.com/TDb2ZSEY
Many regards
▼Reply
Andriy Moraru Reply:
April 13th, 2019 at 4:36 pm
It looks like you need to add Level type of alerts, but you are adding a Signal type of alerts. You can look up the Level example in the post.
▼Reply
Please, how do I get alert written on two different indicator crossing and when the current candle close above or below another candle?……example is when Moving average(10) crosses RSI(13) and later the current candle now crosses alligator(closes up or down). Thanks
▼Reply
Andriy Moraru Reply:
April 17th, 2019 at 7:51 pm
You should code a custom indicator that would check those conditions and issue alerts.
▼Reply
Please, any suggestion on how to go about writing the custom indicator? Thanks
▼Reply
Andriy Moraru Reply:
April 18th, 2019 at 5:52 pm
You can either learn to code yourself or hire an MQL coder on one of the many freelance websites available online.
▼Reply
I Just have to say this to you, you are awesome and blessed for doing this tutorial.
Thank you
▼Reply
hello Andriy Thanks for posting this tutorial, i was adding alert to 2 line cross indicator and i works really well. Currently i try to add level alert at cci indicator, but i can’t make it works. if possible, please take a look at this indicator and tell me where i do wrong. Thank you
https://pastebin.com/K9xsbzfu
▼Reply
gie Reply:
June 3rd, 2019 at 8:49 pm
sorry for my bad English, i mean that indicator that i use working well after adding alert based on your tutorial
▼Reply
Andriy Moraru Reply:
June 4th, 2019 at 10:50 am
When do you expect it to issue the alerts and what happens instead? Your code looks OK to me.
▼Reply
gie Reply:
June 4th, 2019 at 8:18 pm
I tried it both at live market and strategy tester, unfortunately nothing happen . At first i tought that something wrong with my mt4 program but another indicators give alert like ussual
▼Reply
Hello. Can You please, please help me, i do understand that problem is Buffer becouse i have arrays. I need BufferHL alert on crossing zero. but instead the other two Buffers are alerting, can you tell me pretty pleasewhere is mistake. Thank you very much in advance. https://pastebin.com/LdLdpzV5
▼Reply
Andriy Moraru Reply:
July 13th, 2019 at 7:34 pm
First, you need to set time[] array in the OnCalculate() function as series – like you do with high[] and low[] on lines 88-89. Second, because BufferHL[] is set as series, you do not have to use rates_total to access its values – look how it is done in MT4 examples.
▼Reply
Viktoria Reply:
July 14th, 2019 at 12:53 pm
Oh… unfortunately I couldn’t understand about how – to set time[] array in the OnCalculate() function as series, because I don’t have any knowledge about coding, so for me, it’s like looking for a needle on the ground. I was trying to find it online, but no successes. Anyway, thank you very much for answering.
▼Reply
I am trying to set up alert on this indicator, but i don’t know anything about coding and so am afraid of ‘spoiling’ the code of the indicator. I want the indicator to alert when the blue MA crosses the red MA and vice versa. I will really appreciate your help. Here is the link of the indicator.
https://pastebin.com/W18qTcDM
▼Reply
Andriy Moraru Reply:
September 9th, 2019 at 3:59 pm
If you don’t want to change the code yourself, you can hire some coder to add the alerts for you.
▼Reply
Gbenga Adebsi Reply:
September 9th, 2019 at 4:59 pm
Can you do that for me as a coder. we can agree on the cost.
▼Reply
Andriy Moraru Reply:
September 9th, 2019 at 5:06 pm
No, sorry we are not available for hire. You can find coders on Upwork or MQL5.com.
▼Reply
Hi
Thanks for this great article. I managed to include the code in an indicator but I am not getting the desired results. The Alert pops up but not triggered by an arrow but by the beginning of a new candle. Not sure how to correct this.
https://pastebin.com/qaGWzP3B
willie
▼Reply
Andriy Moraru Reply:
September 27th, 2019 at 8:37 am
Sorry, but I don’t provide any help with decompiled indicators.
▼Reply
Bitric Reply:
October 18th, 2019 at 12:32 pm
hello , i have a problem same as willie ? is there any way to fixs that problem ?
▼Reply
Andriy Moraru Reply:
October 18th, 2019 at 12:44 pm
With the same decompiled indicator? You can contact the indicator’s original author if you want to change something in it.
▼Reply
Bitric Reply:
October 20th, 2019 at 2:52 pm
no is not ,the indicator it open source to edit ,mq4
▼Reply
Andriy Moraru Reply:
October 20th, 2019 at 4:07 pm
Then why don’t you share it here, so we could have a look at the issue?
▼Reply
Hi Andryi. Thank you for this useful tutorial.
I’ve succesfull added the alert to my indicator, but I have one issue with push notifications on my mobile.
When I have a valid signal, it only trigger the Alert from the original indicator and not the Push notification.
Can you give me a hand with this?
https://pastebin.com/2udTax46
Thank you.
▼Reply
Andriy Moraru Reply:
November 13th, 2019 at 11:28 am
Your alert code is skipped because the indicator uses ArrayAsSeries() to make all buffers work like MT4 timeseries, so you need to modify MT5 alert codes to resemble the MT4 ones, i.e., change all occurrences of
time[rates_total - 1]
totime[0]
and all occurrences of[rates_total - 1 - TriggerCandle]
to[TriggerCandle]
.▼Reply
Ionut Reply:
November 14th, 2019 at 9:49 pm
Hi Andriy. First of all, thanks for your reply.
Unfortunately it’s not working. I think the problem is that I’m getting 2 Alerts: one from the original and the 2nd one from the push notification. Could you help me to delete the first notification, from original indicator? I don’t know what should be deleted exactly.
Line 216 and down
//— Alert after the last Close of a candle
if(i==0 && InpShowAlerts && time[0]>last_time)
{
Alert(Symbol()+” “+TimeframeToString(Period())+”: Bollinger Bands Outside Candle SHORT Signal”);
last_time=TimeCurrent();
}
}
▼Reply
Andriy Moraru Reply:
November 15th, 2019 at 10:52 am
If you don’t want old alerts, you can remove or comment out the lines 202-207, 215-220, 231-236, and 245-249. However, that will not help the new alerts to appear.
▼Reply
Good day, I hope this finds you well. Firstly thank you so much for this article, it was really helpful for a coding beginner like me. Could I clarify what do you mean by pasting the statement inside the oncalculate function?
https://pastebin.com/r4cZjJW5
This is my attempt at trying to add signals…when i run it on the tester, only 1 signal appears and no more future signals come out and its also sometimes inaccurate.
Would greatly appreciate help regarding this!
▼Reply
Andriy Moraru Reply:
November 17th, 2019 at 5:16 pm
Your indicator’s buffer is set as series, so you are right to use MT4-style access to the buffer values. However, your
time[]
array isn’t set as series, so you either have to access it MT5-style or you have to set it as series usingArraySetAsSeries
function.▼Reply
Ryan Reply:
November 24th, 2019 at 2:20 pm
Hi Andriy, I think that did the trick! Thanks alot again for your help!
▼Reply
Hi can you have a look at this for me please.I tried to add alert at 0.0015 and 0.0008 levels but the alerts don’t pop up at those levels but randomly.Thank you very much
▼Reply
https://pastebin.com/ZefrnV6w
▼Reply
Andriy Moraru Reply:
November 18th, 2019 at 10:38 am
The alert code should be inside start() function, not init().
▼Reply
Sebastian Reply:
November 18th, 2019 at 11:42 am
Right I fixed that but the alerts still don’t correspond the levels all the time.Is there anything else wrong?
https://pastebin.com/2V3am9Ne
▼Reply
Sebastian Reply:
November 18th, 2019 at 11:44 am
It actually only works well on 1 minute timeframe
▼Reply
Is much better now only sometimes still sounds at other levels as well
https://pastebin.com/P6rCmuPm
▼Reply
Sebastian Reply:
November 19th, 2019 at 11:32 pm
Can you have a look at the mt5 version please
https://pastebin.com/nrLBZwR9
▼Reply
Sebastian Reply:
November 21st, 2019 at 11:39 pm
Andriy can you please tell me mate what I’m doing wrong at the mt5 version?
▼Reply
Andriy Moraru Reply:
November 22nd, 2019 at 6:29 am
Did you read the bottom of the post? Specifically this?
▼Reply
Sebastian Reply:
November 23rd, 2019 at 11:52 pm
I didn’t I am sorry mate and thank very much indeed
▼Reply
Please do you have any youtube channel or mql5 coding course on udemy?
I will appreciate that . Thanks
▼Reply
Andriy Moraru Reply:
November 25th, 2019 at 11:03 am
No, sorry. But the best way to learn MQL4 or MQL5 coding is to look at the example codes, read online reference, and try adding your own modifications to the existing indicators or expert advisors.
▼Reply
hi there,
i tried adding alert to my indicator, tested it and no errors but no alerts :-(
can you see what is wrong with it?
https://pastebin.com/DzBHR3CA
▼Reply
Roadrunner Reply:
December 4th, 2019 at 8:34 pm
nevermind it just decided to start working :-)) thanks for the tutorial
▼Reply
I followed the instrucions. I’m using MT5. However i got the error “‘TriggerCandle’ – undeclared identifier” how do i declare It?
▼Reply
Andriy Moraru Reply:
January 4th, 2020 at 7:48 pm
TriggerCandle is one of the input parameters that should be declared in your indicator. Please see the code snippet here.
▼Reply
Hello,
I try to add notification for this correl8 indicator so when the pairs crosses will give notification to your device.
For example I try to add push notification for pair crosses EUR USD,
Something wrong that the file not working and can not attach to the chart.
Can you please look for the code that I add :
https://pastebin.com/zNHfNgLM
Thank you in advance.
▼Reply
Andriy Moraru Reply:
February 9th, 2020 at 9:26 am
If you want help with adding alerts to a specific indicator, please post about it in the forum. All requests for help posted via commentaries to this post will be ignored.
▼Reply
pls add alert POP UP to this indicator rsi_ac_stochastic signal MT5
my email id ; binaryot@yahoo.com
http://www.mql5.com › code › mt5 › indicators › page114
▼Reply
Andriy Moraru Reply:
February 13th, 2020 at 10:04 am
If you want help with adding alerts to a specific indicator, please post about it in the forum. All requests for help posted via commentaries to this post will be ignored.
▼Reply
Thanks for the wonderful tutorial Andriy, I was able to work on the push notificaations and alerts on this indicator. but my problem now is I want the arrows to appear 90s before the event happens. i have tried the little i know but its not working. i even used the alertDelay() function but no success. Can you check it out for me so i can know what i am doing wrong. Thanks
https://pastebin.com/XSHR9ZvH
▼Reply
Andriy Moraru Reply:
February 25th, 2020 at 4:27 pm
I hope you mean that you want the alerts to appear 90 seconds ‘after’, not ‘before’, because otherwise it would be impossible to achieve. Your condition won’t delay anything for the first case of alert checking, because last_time is most likely 0 at the time of declaration. It will also work rather unpredictable after that – if the next alert triggers 60 seconds after the previous one, last_time will also be at least 60 seconds older than TimeCurrent(). You need to update time_current to current time only when the next new alert condition is met (but do not sound the alert at time yet).
▼Reply
Hello, I am a newbe, and I need help with an push/mail alert in the volatility indicator MT5
I have read the instructions (https://www.earnforex.com/blog/how-to-add-alerts-to-metatrader-indicators/)
and edit the volattility indicator as described in the tutorial.
But when I compile the alert indicator I receive
—> ‘if’ – expressions are not allowed on a global scope Row 72 col 2 if (((TriggerCandle > 0) && (time[rates_total – 1] > LastAlertTime)) || (TriggerCandle == 0))
—> ‘}’ – not all control paths return a value Row 65 col 7
can anyone help me tho solve that failure?
▼Reply
Gerd Steinbach Reply:
March 18th, 2020 at 8:07 pm
https://pastebin.com/fXbe6YeC
▼Reply
Andriy Moraru Reply:
March 18th, 2020 at 8:14 pm
It looks like an extra curled bracket (‘}’) on the line 65 is to blame.
▼Reply
Andriy Moraru Reply:
March 18th, 2020 at 8:50 pm
Hello Andriy, negative! when I remove bracket (‘}’) on the line 65 i got ‘{‘ unbalanced parentheses @row 43, and OnCalculate function not found in custom indicator.
Could it be that there is a timeframe problem, because the time is not listed in the OnCalculate?
▼Reply
Andriy Moraru Reply:
March 19th, 2020 at 10:51 am
That curled bracket should be moved to just above return(rates_total);.
Also you need to use OnCalculate() with time parameter.
▼Reply
Pls help me on below script;
POP UP FOR DESKTOP & NOTIFICATION ON MOBILE.
1. ALERT FOR BUY:
->On 15 minute chart
* When RSI goes below 25 & then back above 25 again
*When Stoch goes below 20 then above 20 again
And ->On 1 minute chart
* If RSI is above 25 & Stoch is above 20
2. ALERT FOR SELL:
->On 15 minute chart
*When RSI goes above 75 & then back below 75 again
* When Stoch goes above 80 then below 80 again
And -> On 1 minute chart
* if RSI is below 75 & Stoch is below 80
Thank you.
▼Reply
Andriy Moraru Reply:
April 10th, 2020 at 2:35 pm
Hello Lina,
Sorry, but I am not taking indicator coding orders. In the commentary section of this blog post, I only answer specific questions about the implementation of the steps outlined in the tutorial on adding alerts.
If you want to hire someone to create a custom indicator for you, you can publish a detailed offer in the Jobs section of our forum:
https://www.earnforex.com/forum/forums/forex-jobs.29/
Thank you!
▼Reply
Hi there. Thanks for the article. I’m using an SMA and EMA strategy on MT4 for major currency pairs and commodities. I would appreciate your guidance on how to set up alerts whenever one of the trend line crosses over the other within the chart. Would this be possible?
For example the 60 hour SMA crosses the 10 hour SMA, I’d like an alert on my phone. Reason being I’m trading 11 pairs in total and it’s becoming tough keeping track of all charts at once!
Any help would be appreciated.
Regards
▼Reply
Andriy Moraru Reply:
April 12th, 2020 at 10:07 am
You need to use a custom indicator for that. There are a lot of MA cross indicators out there. I am quite sure there are ones with alerts too. If you search for them, you will definitely find something.
▼Reply
Hello sir,
Would you please guide me regarding how can I alert to the indicator and I will be humbled if you do it for me.
Here is the indicator: https://pastebin.com/j2xN69jr
▼Reply
Andriy Moraru Reply:
April 16th, 2020 at 8:29 am
I won’t do it for you, but you can follow the tutorial and add the alerts on your own.
▼Reply
amazing article
thank you for your simple and straightforward explanation
worked a treat
youre awesome
thanks again
▼Reply
Wow. Nice article. And you are still replying to comments after so many years. Very rare to see. Well done.
I will be trying to follow this guide to try to add a simple alert for mt5 RSI that alerts to oversold/overbought condition. It is odd, but I cannot seem to find one anywhere. Nonetheless, I am curious if I would need to follow the ‘level’ or ‘cross’ example in your guide? Since it should alert on ‘crossing’ the oversold/overbought ‘levels’? Thanks!
▼Reply
Andriy Moraru Reply:
May 7th, 2020 at 2:23 pm
Thank you for your kind words, Dwight!
As for the different alert types, level is good if you want to get alert when RSI becomes equal or greater than 70 or when it becomes equal or less than 30. Whereas cross is good if you want alerts when RSI crosses 70 from above or when it crosses 30 from below.
PS: This RSI indicator has alerts (and lots of other stuff).
▼Reply
Dwight Reply:
May 7th, 2020 at 4:39 pm
Um…I have used this indicator before! I don’t understand. Either I am losing my mind, or maybe the one that I used was for MT4. Nonetheless…thank you! This will work totally fine and will save me time from trying to learn how to code it haha. Thanks so much. Cheers.
▼Reply
Hi everyone,
Can you help me, how to add alert on bar after limit, for example : alert will show up 3 bar after limit of reversal.
Thank you
▼Reply
Andriy Moraru Reply:
May 17th, 2020 at 7:18 pm
What exactly do you mean? If you want to check a candle that is 3rd from the right against some condition, you just set the TriggerCandle input parameter to 2.
▼Reply
allmoon Reply:
May 20th, 2020 at 3:07 pm
Thank you for your respon,
I mean : I want : after reversal reach to the limit then after 3 bar alert show up with text and sound.
for example ( just example case ) , this alert did not work, can you fix this :
▼Reply
Andriy Moraru Reply:
May 20th, 2020 at 6:50 pm
First, please don’t paste big chunks of code into to the commentaries – use pastebin or similar websites and then paste the link. It gets corrupted if you paste it as plain text.
Second, I do not add alerts to the indicators posted here. At best, I can make a suggestion on what can be done to make it work. You are free to post it on the forum – perhaps someone will be willing to code it for you there.
▼Reply
allmoon Reply:
May 23rd, 2020 at 4:01 pm
if your answer like that,
so you make this forum for what ?
it doesn’t useful at all
▼Reply
Andriy Moraru Reply:
May 23rd, 2020 at 5:22 pm
These commentaries are for questions regarding adding alerts to MetaTrader indicators. If it isn’t useful to you, you are free not to use it. Thank you!
▼Reply
Hi everyone,
I want to ask you : is it possible to make 1 arrow alert for 4 indicator such as CCI, RSi, Stochastic, MACD. if possible how to make it.
Thank you
▼Reply
Andriy Moraru Reply:
May 17th, 2020 at 7:15 pm
For that, you need to create a separate custom indicator that would get values (and draw them if you need this) of those four and issue the appropriate alerts.
▼Reply
Hi.
I try modify volume indicator from mt5 by add sendnotification but end up with receiving endless notification to my phone.
[REDACTED]
Help please
▼Reply
Andriy Moraru Reply:
May 20th, 2020 at 8:43 am
First, please don’t paste big chunks of code into to the commentaries – use pastebin or similar websites and then paste the link.
Second, your alert check is executed on every tick. So, each tick the volume is greater than the previous volume (and it’s probably true on every tick), an alert is sent. You need to add some check for the last alert time and reissue the alert only if the candle’s time has changed. See the examples above in this post.
▼Reply
Sorry for the chunk comment.
I dont know coding, i just paste any code so it will fit my needs. Hope you can help me to correct the script code.
Try add lastalerttime myself, alot of error occur. Sorry. Need help
▼Reply
Hello, I followed your instruction and added an alert to an indicator and it compiled without errors. I saved it under a different name in the same folder (Expert Advisors) as the original. I restarted MT4. The modified indicator shows in the Navigator, but when I click on “indicators” on the toolbar and choose “Custom”, the original is there but not the new one. I tried dragging from the navigator to the chart but nothing happens. What am I missing?
▼Reply
Andriy Moraru Reply:
June 1st, 2020 at 8:56 am
Hello Ronald,
If you are creating an indicator, the .mq4 file should be located in the /MQL4/Indicators/ subfolder of your MetaTrader data folder. If you place it in /MQL4/Experts/ it won’t work properly.
▼Reply
Hi, I was wondering if you could guide me in setting up an alert for the MT5 MFI indicator. Basically just a simple alert that will notify me when it gets to a certain level.
TIA
▼Reply
Andriy Moraru Reply:
June 30th, 2020 at 7:39 am
For MFI, you would still need to modify its source code (normally, available in /MQL5/Indicators/Examples/) by following the Level alert example for MT5.
▼Reply
John Reply:
June 30th, 2020 at 10:24 am
Thank you. I’m still a bit confused though. Could you tell me how the level values would change if I want it above 85 and below 15. Also how do I identify whether or not the buffer is set to series? Please excuses the questions… I’m a noob
▼Reply
Andriy Moraru Reply:
June 30th, 2020 at 12:30 pm
If you are talking about the MFI.mq5 supplied with MT5, then indicator buffers there are not set as series. You can verify that by checking that there are no ArraySetAsSeries(, true) calls for them.
As for the levels, you can just use 85 where ‘above zero’ condition is defined (considering you want an alert when the value goes above 85) and 15 where ‘below zero’ condition is defined.
▼Reply
Hi, i bought an heiken ashi looks like indicator but the coder didn’t gave it alerter, also refuse to give it alert function. But i kinda remember once upon a time in a telegram group, someone made an alert and scanner indicator out of EX4 format of non alert indicator. the owner of the indicator ask him in the group, how could u do that when u don’t even have the source code?? he replied that he didn’t change anything in the original indicator, instead he made parasite indicator that read the indicator. is that possible?
▼Reply
Andriy Moraru Reply:
July 22nd, 2020 at 2:39 pm
Yes, it should be possible (in most cases). Another indicator could load the closed-code .ex4 via
iCustom()
function to access its data buffers. You can verify whether this is possible by loading your .ex4 indicator on any chart and then click Ctrl+D. A Data Window will open and will list all data buffer values for all indicators present. If there are listed buffers for your .ex4 indicator, then other indicators can access them.▼Reply
HI Everyone! first i would like to thanks for this tread i did one alert for ZigZag reallt easy x)
BUT.. i was trying to do another for NRTR indicator and it dosen’t work verywell it keep triggerind the alert on every candle
(code cut out)
▼Reply
Jow Reply:
July 30th, 2020 at 4:30 pm
does someone know what i’m missing? i want it to trigger alert only when arrow appears
▼Reply
Andriy Moraru Reply:
July 30th, 2020 at 4:36 pm
Please don’t insert enormous chunks of code into the post.
PS: Your buffers are set as series, don’t use
rates_total - 1
for the current bar, use0
instead.▼Reply
ohh i’m so sorry for that i didn’t know ^^”.
i just tried to change it but now the arrows dessapear and it is not giving alert
▼Reply
Andriy Moraru Reply:
July 31st, 2020 at 8:57 am
You should have replaced
rates-total - 1
with0
, notrates_total - 1
withrates_total - 0
.▼Reply
jow Reply:
July 31st, 2020 at 1:19 pm
hmmm just did it now but still alert all candles .. maybe coz NRTR is always changing but not always it change the arrow?
this are the buffer os arrows
(Cut out.)
▼Reply
Andriy Moraru Reply:
July 31st, 2020 at 1:25 pm
Please create a thread in the forum if you want someone to help you code your alerts. The comment section here is not intended for this.
▼Reply
Faheem Reply:
August 5th, 2020 at 9:47 am
Hello admin first i would like to thanks for this tutorial i have use your instruction for adding alert on my indicator but its showing some errors i don’t know that why its happening does you know what i’m missing here is my code
https://pastebin.com/GdYzpCWv
▼Reply
Andriy Moraru Reply:
August 5th, 2020 at 7:03 pm
You should put your alert checks inside
OnCalculate()
funciton, notdeinit()
.▼Reply
Hello. Thank you so much for the tutorial, found it very useful today. Just a question, I’m trying to use this to generate a level alert for ADX going above 25 in MT5, using your code, would I need to replace all the zeros with 25?
(((ExtADXBuffer[rates_total – 1 – TriggerCandle] > 25) && (ExtADXBuffer[rates_total – 2 – TriggerCandle] 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
▼Reply
Andriy Moraru Reply:
August 8th, 2020 at 9:42 am
Yes, where ExtADXBuffer is compared to 0 it has to be compared with 25 instead.
▼Reply
Sowole Jesse Reply:
August 8th, 2020 at 10:57 am
Sorry to trouble you.
What of the latter part of the code where it’s just TriggerCandle being compared to 0, would I also need to change that zero to 25?
((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
▼Reply
Andriy Moraru Reply:
August 8th, 2020 at 11:18 am
No, you don’t need to change this part. TriggerCandle is the number of the candle where you check the conditions.
▼Reply
Sowole Jesse Reply:
August 9th, 2020 at 11:33 pm
It works! Thank you so much. This really, really helped.
▼Reply
Hello sir, I tried setting up alert, had done it step by step but was not able to successfully complete the task . Please help me with adding the alert.
▼Reply
Andriy Moraru Reply:
August 24th, 2020 at 9:24 am
If you need help adding alerts to an indicator, you can post your indicator in our forum here:
https://www.earnforex.com/forum/forums/metatrader-indicators.12/
Perhaps, someone will be able to help you.
▼Reply
Hi Andriy. Thanks for the post…very informative. I have a candlestick size indicator with native alerts. I want to enable push notifications and have tried adding the enablePushAlert and the sendNotification function but its not working. I posted my issue in the forum but no reply yet. Was hoping you could assist me. Kind regards.
▼Reply
I really want to commend this Admin so much for his selfless assistance to us all this while, especially even to newbies who do not know anything about coding. You re a rare gem. million kudos to you and you team (If any).
▼Reply
Hola Andriy Moraru espero te ecuentres bien.
Queria agradecerte por compartir esta información, realmente me fue de gran ayuda, esta información es la única que realmente funciona en ingles y en español.
Te deseo lo mejor para ti y tu familia muchas gracias nuevamente.
▼Reply
Hi, I am no coder. I want to add an alert to an MT5 indicator. Based on your example, I tried but could not go further than the (input) line. If I send you the source code of the indicator, can you help me, please. (Indicator is from codebase in MT5)
▼Reply
Andriy Moraru Reply:
December 4th, 2020 at 12:34 pm
No, but if you have some specific question – like how to find some piece of code or how to avoid some compilation error – I will gladly answer that.
▼Reply
Hi, please can send you an indicator to help me include alert on it?
▼Reply
Andriy Moraru Reply:
January 2nd, 2021 at 2:58 pm
No, sorry. If you cannot follow the tutorial, you can hire some MQL4/5 coder to do the job for you.
▼Reply
Hi. Andriy Moraru
A big Thank you for this great work you’ve done here, this Post is about 7 or 6 years old, yet you still find time to respond to questions, i’ve never seen this before.
you are a good person. Thank you.
please sir, with due regards, i encountered an error while adding alert to the RSI indicator,
i use the Cross Alert example, after i compile it, it displays “OnCalculate function not found in custom indicator”
please how do i fix this ?
thanks.
▼Reply
Andriy Moraru Reply:
January 25th, 2021 at 10:35 am
Hi Daniel,
It looks like you either deleted or broke the OnCalculate() declaration.
▼Reply