Trading Email Alert MT4
- Utilitaires
- Version: 1.0
- Activations: 5
1. Overview
Trading Email Alert monitors the trading account and automatically sends an email whenever a buy or sell
position is opened and/or closed on the symbol (instrument) it is attached to. The email subject line is fully
configurable, along with several filters that determine which events trigger a notification.
Key features:
• Separate email subject line for trade opening and trade closing.
• Filter to notify only openings, only closings, or both.
• Filter to notify only buy trades, only sell trades, or both.
• Optional filtering by chart symbol and by Magic Number (EA/robot identifier).
• On closing, the email includes profit/loss, swap, commission and net result.
• Option to include account details (balance, equity, broker) in the email body.
Important: pending orders (Buy Stop, Sell Stop, Buy Limit, Sell Limit) do not trigger an email when they are
created. The opening email is only sent once the pending order is triggered and becomes an actual open buy or
sell position.
2. Prerequisite: Configuring Email in the Terminal
Before using the EA, you must enable and configure email sending directly in the MetaTrader 4 (MQL4)
terminal:
•1. From the top menu, go to Tools ® Options.
•2. Open the Email tab.
•3. Check the Enable box.
•4. Fill in your email account's SMTP server details (server, login, password, port) — for example, for Gmail:
smtp.gmail.com:465, using an app password rather than your regular account password.
•5. Fill in the From (sender email) and To (recipient email) fields.
•6. Click Test to confirm that a test email is delivered correctly.
•7. Click OK to save.
In addition, when attaching the EA to a chart, you must check the "Allow Email" option in the Common tab of the
Expert Advisor's properties window. Without this permission, the email command is blocked even if the EA is
running normally.
Email sending (the SendMail function) does not work inside the Strategy Tester — it only works on a live or demo
account, with the terminal open and connected to the internet.
3. Installation and Compilation (MetaTrader 4 (MQL4))
•1. Copy the Trading email alert.mq4 file to the MQL4/Experts/ folder of your MetaTrader 4 installation.
•2. Open the MetaEditor (press F4 in MT4).
•3. Open the .mq4 file inside the MetaEditor.
•4. Press F7 to compile and generate the .ex4 file. Check the "Errors" tab to make sure there were no
failures.
•5. In MT4, open the Navigator (Ctrl+N), locate the EA under "Expert Advisors" and drag it onto the desired
chart.
•6. Adjust the settings under the "Inputs" tab and check "Allow Email" under the "Common" tab.
4. Settings Reference Table
Setting Default Description
InpEmailSubjectOpen "New Trade
Opened"
Email subject line sent when a position is OPENED.
InpEmailSubjectClose "Trade
Closed"
Email subject line sent when a position is CLOSED.
InpIncludeAccount true If enabled, adds account details to the email body: account
number, broker, balance and equity.
InpNotifyOnOpen true Controls whether the EA sends an email when a position is
OPENED.
InpNotifyOnClose true Controls whether the EA sends an email when a position is
CLOSED (includes profit/loss, swap and commission).
InpNotifyOnBuy true Controls whether BUY trades trigger a notification.
InpNotifyOnSell true Controls whether SELL trades trigger a notification.
InpOnlyThisSymbol false If enabled, only notifies trades on the same symbol as the
chart the EA is attached to.
InpOnlyThisEA false If enabled, only notifies trades carrying the Magic Number
set below (useful to ignore manual trades or trades from
other EAs).
InpMagicNumber 0 Magic Number used as a filter when InpOnlyThisEA = true.
InpNotifyExistingOnStart false MT4-exclusive setting. If enabled, the EA also sends an
opening email for orders that were already open before the
EA was attached to the chart. If disabled (default), those
pre-existing orders are silently registered without triggering
an email.
5. How Trade Events Are Detected
Unlike MT5, classic MQL4 has no native trade-transaction event. Because of this, the MT4 version checks
the list of open orders on every tick and compares it against the previous check: a new ticket is treated as an
opening; a ticket that was previously in the list and is no longer among the open orders is treated as a closing
(the final details are then retrieved from the account history).
Partial closes of an order are a special case in MT4: the original ticket remains open with the remaining lot size,
while the closed portion appears separately in the history. The EA handles this safely, but if you use partial closes
frequently and want a dedicated email for that case, the code can be adapted further.
6. How the Open/Close and Buy/Sell Filters Work
The EA combines two independent filter groups that work together (a logical AND). A trade only triggers an
email if it passes both groups at the same time:
Filter group What it controls
Notify on OPEN / Notify on CLOSE Controls WHEN the email should be sent: at the start of the
trade, at the end, both, or neither.
Notify BUY / Notify SELL Controls the DIRECTION of the trade that should trigger an
email: buys only, sells only, or both.
For example, if you set Notify on OPEN = true, Notify on CLOSE = false, Notify BUY = true and Notify
SELL = false, you will only receive an email when a BUY trade is opened — no sell trade triggers an email,
and no closing triggers an email, regardless of direction.
7. Ready-to-Use Configuration Scenarios
Get an email only when buying and selling (ignore closings)
You want to be notified as soon as a position is opened, whether buy or sell, but you don't want an email when it is
closed.
• Notify on OPEN = true
• Notify on CLOSE = false
• Notify BUY = true
• Notify SELL = true
Get an email only with the final result of each trade
You only want to know the outcome (profit/loss) of each trade, without being notified at entry time.
• Notify on OPEN = false
• Notify on CLOSE = true
• Notify BUY = true
• Notify SELL = true
Track sell trades only, from start to finish
You mostly trade short and want to follow the full life cycle of those trades only, ignoring buy trades entirely.
• Notify on OPEN = true
• Notify on CLOSE = true
• Notify BUY = false
• Notify SELL = true
Track the full life cycle of every trade (default)
Get an email on every opening and every closing, for both buy and sell trades.
• Notify on OPEN = true
• Notify on CLOSE = true
• Notify BUY = true
• Notify SELL = true
Temporarily disable all emails without removing the EA from the chart
Useful during testing, adjustments or maintenance, without having to delete the EA.
• Notify on OPEN = false
• Notify on CLOSE = false
8. Frequently Asked Questions
Q: Does the EA send an email when I simply place a pending order (Buy Stop, Sell Stop, Buy Limit,
Sell Limit)?
A: No. The email is only sent once the pending order is triggered and becomes an actual open position in the market.
Q: Why isn't the email arriving?
A: Check, in this order: (1) whether email sending is enabled and tested under Tools ® Options ® Email; (2) whether
"Allow Email" is checked in the EA's properties; (3) the "Experts" or "Journal" tab of the terminal, where the EA logs an
error message if sending fails; (4) the recipient's spam folder.
Q: Does the EA work inside the Strategy Tester?
A: No. Email sending (SendMail) is not supported inside the tester — it only works on a live or demo account with the
terminal running.
Q: Can I use the Magic Number filter to ignore manual trades?
A: Yes. Manual trades normally have Magic Number equal to 0. Enable "Notify only this EA's trades" and set your
automated strategy's Magic Number so that only its trades trigger emails.
Q: Do the MT4 and MT5 versions have the exact same settings?
A: Almost all of them are identical. The MT4 version has one extra setting not present in MT5: InpNotifyExistingOnStart,
which controls whether orders that were already open before the EA was attached to the chart should trigger a retroactive
opening email.
