Working with Telegram in MetaTrader. Telegram channels and bot
My Autolot Secrets. Dynamic Lot or Autolot.
Description
Alert: The most frequent queries in search engines and popular topics on forums often include the following phrases.
An alert on such topics can help you stay updated with the latest trends.
- “Alert indicator“
- “How do you add a sound signal to the indicator?“
- “Help me insert a sound signal into the indicator“
- “How to insert Alerts and Arrows“
- “How to send a message to email or phone when the signal comes from an indicator?“
In this article, I will describe in detail an easy way to add Alert, Mail, Push, and Arrow notifications to any indicator using additional code available at Expforex.
Foreword
To correctly install Alerts in your indicator, you must have the open-source code of your indicator.
The decompiled code is undesirable because, for beginners, the decompiled code provides minimal information. It’s hard to understand.
You may also encounter problems with compilation after editing.
xCustomEA
If you’re searching for an easier way to automate your trading strategy without diving into complex custom programming, consider xCustomEA.
This expert advisor from Expforex is designed to work seamlessly with indicators that generate arrow signals. With xCustomEA, you can easily automate any indicator that shows buy or sell arrows, allowing you to create a powerful automated strategy without the hassle of developing custom code.
xCustomEA makes automating strategies based on indicator signals incredibly accessible. It allows traders to focus on optimizing their trading instead of spending time and resources on custom programming. This expert advisor serves as an excellent alternative to hiring a programmer, providing a straightforward solution to turn indicator signals into trades.
For more information, visit the xCustomEA page or explore Expforex’s other expert advisors.
Beginning of Work to insert Alert
First, you need to determine which indicator buffers provide specific signals, the purpose of creating an alert, and the conditions for determining the signal on the indicator.
Important: Only external buffers defined at the beginning of the variable code can be displayed in indicators:
#property indicator_buffers 1
However, the indicator can also contain hidden buffers, which are set in the init() function and declared as variables:
IndicatorBuffers(7): We only need the first buffers.
If, for example, you have 1 external buffer, then look at the variable:
SetIndexBuffer(0, SarBuffer);
- 0 is the first buffer
- 1 is the second buffer
These buffers or their names can be identified by hovering over a specific line of the indicator on the chart.
Value1 – This is the first buffer or 0 in the code’s indexing system.
SetIndexBuffer(0, SarBuffer); // The name of the buffer we need
If this is SarBuffer, then we will use it.
Furthermore, it’s a technical matter to determine how the signal will be triggered;
For example, if this is the intersection of the 0 line from the top (bottom) moving down (up), it will look like this:
SarBuffer[shift+1] >= 0 && SarBuffer[shift] < 0
Indicator crossing the current price or a bar, a bar breakout by the indicator, and so on:
SarBuffer[shift+1] >= Close[shift] && SarBuffer[shift] < Close[shift]
If this is the intersection of unique levels, indicators such as stochastics:
SarBuffer[shift+1] <= 75 && SarBuffer[shift] > 75; SarBuffer[shift+1] >= 25 && SarBuffer[shift] < 25;
If there are already arrows in your indicator, then the following type of signal is also possible:
DnTrend[1] != EMPTY_VALUE && DnTrend[1] != 0 && UpTrend[2] != EMPTY_VALUE
In any case, you need to apply logic and creativity to record the signal correctly. If you encounter any difficulties, write to this thread, attach the indicator, show the lines on the chart, and describe in detail what you can’t do. Sending a message like “you need to insert an alert into the indicator” without explaining where and what to do, and without providing the indicator itself, is not helpful.
Code “Alerts and arrows from www.expforex.com“
The next step of adding our alert to your indicator consists of several points:
STEP 1
Insert the following code at the beginning of the Expert Advisor before the OnCalculate () (start) function:
//+==+//+ www.expforex.com edit AlertArrow +//+==+ extern string Alerts="Alerts and arrows from www.expforex.com"; extern bool AlerT=true; // Issue an alert to the screen extern bool Mail=true; // Send message extern bool Push=true; // Send PUSH to phone extern bool Arrow=true; // Put arrows on signals extern int shift=1; // On which bar to count the signal 0 - on the current one, 1 - on the closed int timeee; // Internal variable string nameInd; void SetArrow(int cd, color cl, string nm="", datetime t1=0, double p1=0, int sz=3) { if(nm=="") nm=DoubleToStr(Time[0], 0); if(t1 <= 0) t1=Time[0]; if(p1 <= 0) p1=Bid; nameInd=WindowExpertName(); int wind=WindowFind(nameInd); wind=0; if(ObjectFind(nm) < 0) ObjectCreate(nm, OBJ_ARROW, wind, 0, 0); ObjectSet(nm, OBJPROP_TIME1, t1); ObjectSet(nm, OBJPROP_PRICE1, p1); ObjectSet(nm, OBJPROP_ARROWCODE, cd); ObjectSet(nm, OBJPROP_COLOR, cl); ObjectSet(nm, OBJPROP_WIDTH, sz); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Expforex_AlertArrow(string text="", int arrowdir=0, bool history=false, int i=0) { nameInd=WindowExpertName(); int wind=WindowFind(nameInd); if(wind==-1) wind=0; ObjectCreate("Originalalert", OBJ_LABEL, wind, 0, 0); ObjectSetText("Originalalert", "Modification AlertArrow www.expforex.com", 10, "Arial Bold", Red); ObjectSet("Originalalert", OBJPROP_CORNER, 2); ObjectSet("Originalalert", OBJPROP_XDISTANCE, 200); ObjectSet("Originalalert", OBJPROP_YDISTANCE, 10); if(!history) { if(AlerT) Alert(text); if(Arrow) if(arrowdir==1) SetArrow(241, Blue, nameInd + DoubleToStr(Time[shift], 0), Time[shift], Low[shift]); if(Arrow) if(arrowdir==2) SetArrow(242, Red, nameInd + DoubleToStr(Time[shift], 0), Time[shift], High[shift]); if(!IsTesting()) if(Mail) SendMail(text, text); if(!IsTesting()) if(Push) SendNotification(text); } if(history) { if(Arrow) if(arrowdir==1) SetArrow(241, Blue, nameInd + DoubleToStr(Time[shift + i2], 0), Time[shift + i2], Low[shift + i2]); if(Arrow) if(arrowdir==2) SetArrow(242, Red, nameInd + DoubleToStr(Time[shift + i2], 0), Time[shift + i2], High[shift + i2]); } }//+==+//+ www.expforex.com edit AlertArrow +//+==+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { for(int i=ObjectsTotal(); i>=0; i--) { if(StringFind(ObjectName(i), nameInd)!=-1) ObjectDelete(ObjectName(i)); } } //+------------------------------------------------------------------+
STEP 2
Before closing the OnCalculate () function, insert the following code:
return(rates_total); }
Paste the following code:
//+==+//+ www.expforex.com edit AlertArrow +//+==+ nameInd=WindowExpertName(); if(timeee != Time[0] && SarBuffer[shift+1] <= 75 && SarBuffer[shift] > 75) { Expforex_AlertArrow(Symbol() + " " + Period() + nameInd + " UP", 1); timeee=Time[0]; } if(timeee != Time[0] && SarBuffer[shift+1] >= 25 && SarBuffer[shift] < 25) { Expforex_AlertArrow(Symbol() + " " + Period() + nameInd + " DN", 2); timeee=Time[0]; }//+==+//+ www.expforex.com edit AlertArrow +//+==+
STEP 3
This code will serve as our signal.
Naturally, you need to replace some code with your own.
The following code serves as a signal for an alert:
1. Intersection of the 0 line from the top (bottom) moving down (up), it will look like this:
SarBuffer[shift+1] >= 0 && SarBuffer[shift] < 0
2. Indicator crossing the current price or a bar, a bar breakout by the indicator, and so on:
SarBuffer[shift+1] >= Close[shift] && SarBuffer[shift] < Close[shift]
3. If this is the intersection of unique levels, indicators such as stochastics:
SarBuffer[shift+1] <= 75 && SarBuffer[shift] > 75; SarBuffer[shift+1] >= 25 && SarBuffer[shift] < 25;
After Use
To add a sound signal to the indicator, follow these steps:
- 1. Open the indicator’s settings.
- 2. Look for the “Alert” or “Arrows” section.
- 3. Select the option to add a sound alert.
- 4. Choose the sound file you want to use as the alert.
- 5. Save the changes.
By inserting a sound signal into the indicator, you can receive an audible notification when certain conditions are met, which can help you make better trading decisions.
If You Need Arrows on History, Then You Need to Do This:
After the above code, add the following:
//+==+//+ www.expforex.com edit AlertArrow +//+==+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ if(counted_bars > 0) counted_bars--; int limit2 = Bars - counted_bars; for(int i2 = 0; i2 < limit2; i2++) { nameInd = WindowExpertName(); if(SarBuffer[shift+1+i2] <= 75 && SarBuffer[shift+i2] > 75) { Expforex_AlertArrow(Symbol() + " " + Period() + nameInd + " UP" + i2, 1, true, i2); } if(SarBuffer[shift+1+i2] >= 25 && SarBuffer[shift+i2] < 25) { Expforex_AlertArrow(Symbol() + " " + Period() + nameInd + " DN" + i2, 2, true, i2); } } //+==+//+ www.expforex.com edit AlertArrow +//+==+
Examples
These examples are taken from the corresponding section of our forum. I modified the indicators according to the principles described above.
Conclusions
In this article, I explained the process of creating signals for the indicator in the most detailed and understandable way.
The above code can be used without restrictions on any indicator. It is important not to change the author’s name when adding code to the indicator.
If you liked this article and found this method of inserting signals useful, please leave your comments and rate the topics.
- Freelance: Custom Programming on MetaTrader and MQL!
- Signal bar indicator. Which bar should you take a signal from? Drawing indicators.
- CrossObjectALert Alert indicator when crossing with objects for mt4 and mt5 terminals
- Working with email and push in MetaTrader
Signal Bar: This Is Important to Know
Questions?
If you have any questions, please ask them. We do not sell a pig in a poke.
Additionally, each of our products can be tested before purchase.
We appreciate your interest and support for our products and strive to maintain high-quality standards.
Thank you for being with us!
Do you have a question?
This post is also available in: English Українська Portuguese Español Deutsch Chinese Русский Français Italiano Türkçe 日本語 한국어
Leave a Reply