If you're looking to enhance your trading experience, adding sound alerts for connection status in MetaTrader 5 is a game-changer. This simple utility will notify you with sound cues whenever your connection status changes, ensuring you never miss a beat.
To get started, you’ll need to add your sound files to the MQL5\Files\Sounds directory. Once that’s done, you can copy the provided code into your EA Utility and compile it. Just a heads-up: the use of #resource can complicate uploads, so be mindful of that.
How to Implement the Sound Alert
Here's a quick rundown of the code you'll need:
//+------------------------------------------------------------------+
//| Connect_Disconnect_Sound_Alert.mq5 |
//| Copyright 2024, Rajesh Kumar Nait |
//| https://www.mql5.com/en/users/rajeshnait/seller |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, Rajesh Kumar Nait"
#property link "https://www.mql5.com/en/users/rajeshnait/seller"
#property version "1.00"
#include
bool first = true;
bool Now_IsConnected = false;
bool Pre_IsConnected = true;
datetime Connect_Start = 0, Connect_Stop = 0;
CTerminalInfo terminalInfo;
//--- Sound files
#resource "\Files\Sounds\CONNECTED.wav"
#resource "\Files\Sounds\DISCONNECTED.wav"
//+------------------------------------------------------------------+
int OnInit()
{
ResetLastError();
while (!IsStopped()) {
Pre_IsConnected = Now_IsConnected;
Now_IsConnected = terminalInfo.IsConnected();
if (first) {
Pre_IsConnected = !Now_IsConnected;
}
if (Now_IsConnected != Pre_IsConnected) {
if (Now_IsConnected) {
Connect_Start = TimeLocal();
if (!first) {
if (!PlaySound("::Files\Sounds\DISCONNECTED.wav"))
Print("Error: ", GetLastError());
}
if (IsStopped()) break;
if (!PlaySound("::Files\Sounds\CONNECTED.wav"))
Print("Error: ", GetLastError());
} else {
Connect_Stop = TimeLocal();
if (!first) {
if (!PlaySound("::Files\Sounds\CONNECTED.wav"))
Print("Error: ", GetLastError());
}
if (IsStopped()) break;
if (!PlaySound("::Files\Sounds\DISCONNECTED.wav"))
Print("Error: ", GetLastError());
}
}
first = false;
Sleep(1000);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+ If you want to see this in action, check out the video below:
Related Posts
- Unlock Trading Insights with the Support Vector Machine Learning Tool for MetaTrader 5
- Creating an Expert Advisor for Dark Cloud Cover and Piercing Line Patterns with CCI Confirmation
- Harnessing MQL5 Wizard for Trading Signals: 3 Black Crows & 3 White Soldiers with MFI
- Creating a Stochastic-Based EA for Hammer and Hanging Man Patterns in MetaTrader 5
- Leveraging MQL5 Wizard: Crafting Trade Signals with Meeting Lines and Stochastic