Master MetaTrader 4/5 Alerts: Sound, Email & Push

Learn to configure sound, email, and push notifications in MT4/5. Complete guide with MQL code examples, troubleshooting, and best practices for.

master-metatrader-4-5-alerts-sound-email-push

Why Mastering MetaTrader Alerts Matters

Alerts are the nervous system of your automated trading setup. Whether you're running an Expert Advisor overnight, monitoring multiple charts, or waiting for a specific price level, properly configured alerts keep you informed without staring at the screen. MetaTrader 4 and 5 offer three distinct alert channels: sound alerts (local PC), email alerts, and push notifications (mobile devices). Each serves a different purpose, and knowing how to combine them effectively separates a casual user from a power trader.

In this guide, you'll learn exactly how to configure all three notification types, write MQL code that triggers them, and avoid the common pitfalls that cause alerts to fail silently. We'll cover real-world scenarios including VPS setups, rate limiting, and multi-channel alert strategies that professional traders use daily.

Prerequisites

  • MetaTrader 4 (build 1090 or newer) or MetaTrader 5 (build 2000+). Both platforms handle alerts similarly, with minor menu differences noted.
  • A demo or live trading account logged into the terminal.
  • For email alerts: a valid email account (Gmail, Outlook, or your broker's SMTP).
  • For push notifications: the MetaTrader 4 or MetaTrader 5 mobile app installed on your phone, with the same trading account logged in.
  • Basic familiarity with the MetaEditor (F4) for MQL code examples.
  • Optional but recommended: A VPS (Virtual Private Server) running Windows for 24/7 uptime. Many brokers offer free VPS for accounts above a minimum balance.

Step-by-Step Alert Configuration

1. Sound Alerts (Built-in & Custom)

Sound alerts are the simplest. They work immediately without any account configuration. There are two types: the built-in Alert() function that plays the default system sound and shows a pop-up window, and PlaySound() for custom WAV files.

Configuring the EA for Sound Alerts

  1. Right-click on a chart → Expert AdvisorsProperties (or press F7 on the chart).
  2. Go to the Common tab. Ensure Allow live trading is checked if you want the EA to trade; for alerts only, you can leave it unchecked.
  3. Check Allow external experts import (required for custom DLLs, but not for basic alerts).
  4. Click OK.

To trigger a sound alert in MQL4/MQL5, use the Alert() function:

// MQL4/MQL5 - Plays default system sound and shows a pop-up
Alert("Price hit 1.2000 on EURUSD");

For a custom WAV file, use PlaySound():

// Place your .wav file in: \MQL4\Files\ or \MQL5\Files\
if (Bid >= 1.2000)
   PlaySound("alert.wav");

MT4 vs MT5 note: In MT4, PlaySound() looks in ...\MetaTrader 4\Sounds\ first, then ...\MQL4\Files\. In MT5, it only searches ...\MQL5\Files\. Always place your WAV file in both locations for cross-platform compatibility. Supported formats are PCM WAV files at 8-bit or 16-bit, any sample rate. Avoid compressed or stereo WAV files as they may not play.

Pro tip: You can combine both functions for maximum local awareness:

Alert("EURUSD breakout detected!");
PlaySound("siren.wav");

2. Email Alerts

Email alerts require SMTP server configuration. Here's the exact setup for Gmail (most common):

  1. In MT4/MT5, go to ToolsOptions (or Ctrl+O).
  2. Click the Email tab.
  3. Fill in these fields:
    • SMTP server: smtp.gmail.com
    • SMTP port: 587 (TLS) or 465 (SSL)
    • Enable authentication: Checked
    • Login: Your full Gmail address (e.g., [email protected])
    • Password: Your Gmail App Password (not your regular password). Generate one at Google Account → Security → App passwords.
    • From: Same as login
    • To: The email address where you want alerts delivered (can be the same)
  4. Click Test. You should receive a test email within 30 seconds.

Alternative SMTP settings for other providers:

Provider SMTP Server Port (TLS) Port (SSL) Notes
Gmail smtp.gmail.com 587 465 Requires App Password; enable 2FA first
Outlook/Hotmail smtp.office365.com 587 Use regular password; enable SMTP in account settings
Yahoo smtp.mail.yahoo.com 587 465 Generate App Password from Yahoo Account Security

In MQL, trigger email alerts with SendMail():

// MQL4/MQL5 - Subject limited to 64 characters, body to 1024
SendMail("EURUSD Alert", "Price reached 1.2000 at " + TimeToString(TimeCurrent()));

Important: The SendMail() function only works if the Email tab is properly configured. There is no error feedback if it fails — you must test manually. Also note that the subject line is truncated to 64 characters and the body to 1024 characters, so keep your messages concise.

3. Push Notifications (Mobile)

Push notifications are the most reliable for real-time alerts because they bypass email delays and don't require your PC to be on (if you're using a VPS). The MetaQuotes push notification system uses a proprietary protocol that delivers messages within seconds to your mobile device.

  1. On your mobile device, open the MetaTrader 4 or 5 app.
  2. Log in with the same trading account number and password you use on your desktop/VPS.
  3. On desktop/VPS, go to ToolsOptionsNotifications tab.
  4. Check Enable push notifications.
  5. Click Add and enter the MetaQuotes ID from your mobile app:
    • In the mobile app: SettingsChats and MessagesMetaQuotes ID.
    • Copy the 8-character alphanumeric ID (e.g., A1B2C3D4).
  6. Click Test. You should receive a push notification on your phone within 10 seconds.
  7. You can add up to 5 MetaQuotes IDs (e.g., your phone + your tablet).

In MQL, send push notifications with SendNotification():

// MQL4/MQL5 - Message limited to 255 characters
SendNotification("EURUSD: Price broke 1.2000 support");

Key difference: Unlike email, push notifications work even if your terminal is minimized or running in the background. They are the preferred channel for critical alerts. However, note that push notifications are sent through MetaQuotes servers, so if MetaQuotes has a server outage (rare but possible), push may be delayed.

Advanced Alert Strategies with MQL Code

Multi-Channel Alert Function

Professional traders rarely rely on a single channel. Here's a reusable function that sends alerts through all three channels simultaneously:

// Send alert through all channels
void SendMultiAlert(string message)
{
    // Local pop-up and sound
    Alert(message);
    
    // Email (if configured)
    SendMail("Trading Alert", message);
    
    // Push notification (if configured)
    SendNotification(message);
}

Rate-Limited Alert System

Without rate limiting, your EA could send hundreds of notifications per second during volatile markets. Implement a cooldown per symbol:

// Rate limiter - max one alert per symbol per 5 minutes
input int AlertCooldownSeconds = 300; // 5 minutes

void SendRateLimitedAlert(string symbol, string message)
{
    static string lastAlertSymbols[];
    static datetime lastAlertTimes[];
    
    // Find existing entry for this symbol
    int idx = -1;
    for (int i = 0; i < ArraySize(lastAlertSymbols); i++)
    {
        if (lastAlertSymbols[i] == symbol)
        {
            idx = i;
            break;
        }
    }
    
    // If symbol not found, add it
    if (idx == -1)
    {
        ArrayResize(lastAlertSymbols, ArraySize(lastAlertSymbols) + 1);
        ArrayResize(lastAlertTimes, ArraySize(lastAlertTimes) + 1);
        idx = ArraySize(lastAlertSymbols) - 1;
        lastAlertSymbols[idx] = symbol;
        lastAlertTimes[idx] = 0;
    }
    
    // Check cooldown
    if (TimeCurrent() - lastAlertTimes[idx] >= AlertCooldownSeconds)
    {
        SendMultiAlert(symbol + ": " + message);
        lastAlertTimes[idx] = TimeCurrent();
    }
}

Heartbeat Monitoring for EA Reliability

One of the most valuable alert patterns is a heartbeat notification that confirms your EA is still running. This catches VPS crashes, terminal disconnections, or EA errors early:

// Send heartbeat every 4 hours
input int HeartbeatInterval = 14400; // 4 hours in seconds

void CheckHeartbeat()
{
    static datetime lastHeartbeat = 0;
    
    if (TimeCurrent() - lastHeartbeat >= HeartbeatInterval)
    {
        string status = StringFormat("Heartbeat OK - Account: %d, Equity: %.2f, Open Trades: %d",
                                     AccountNumber(), AccountEquity(), OrdersTotal());
        SendNotification(status);
        lastHeartbeat = TimeCurrent();
    }
}

// Call this function in OnTick() or OnTimer()
void OnTick()
{
    CheckHeartbeat();
    // ... rest of your EA logic
}

Comparison of Alert Channels

Feature

Why does SendMail() work in the tester but not on live charts?

The Strategy Tester uses a simulated environment. SendMail() only works on live charts when the Email tab is properly configured. Test email separately using the Test button in Tools → Options → Email, then verify your EA is attached to a chart (not just compiled).

Community

Clap for the article and open comments only when you want to read them.

0 claps0 comments

Related articles