I've been running EAs and custom indicators on MT4 for years, and one problem that never seems to go away is missing alerts. The built-in
Alert() function pops up a window that disappears if you're not looking. The PlaySound() function is better, but if you're in another room, or watching a movie, or God forbid sleeping, you're going to miss it. And with forex moving 24/5, missing an entry signal can cost you a week's work.I ran into a discussion a while back where someone mentioned using a physical USB warning light – the kind you see on servers or in offices to indicate system status. They plugged it into their computer, and when their indicator gave a signal, the light would flash a specific color. No sound, no pop-up, just a visual cue that you can see from across the room .
Initially, I dismissed it as a gimmick. I thought, "Why bother with a physical light when I can just use push notifications?" But then I started thinking about it differently. Sound alerts get drowned out by background noise. Push notifications are great, but if you're not checking your phone, you still miss them. A physical light that stays lit until you acknowledge it solves both problems. It's also great for overnight trading when you don't want to be woken by a loud alert but want to see if something happened when you wake up.
The Equipment and the DLL
The light I ended up using was a simple USB RGB LED lamp. It came with a DLL that allowed software to control it. The manufacturer provided APIs for Python, Java, and C++. But I needed it to work directly with MT4, which meant using the MQL4 DLL import functionality.
The MQL4 documentation covers DLL imports clearly: you declare the function from the DLL using
#import and then call it like any other function . The basic structure looks like this:``
cpp
#import "usb_light.dll"
void SetLightColor(int red, int green, int blue);
void TurnOffLight();
bool IsLightConnected();
#import
`
Writing the Custom Indicator
I didn't want to modify my existing EAs. I wanted something standalone that could monitor my trading conditions and trigger the light independently. So I wrote a custom indicator that did two things: calculate a simple moving average crossover, and call the DLL functions when a crossover occurred.
Here's the core logic:
`cpp
// Inside the indicator's OnCalculate() function
if (currentMA > previousMA && previousMA < previousPreviousMA) {
// Bullish crossover - set light to green
SetLightColor(0, 255, 0);
}
else if (currentMA < previousMA && previousMA > previousPreviousMA) {
// Bearish crossover - set light to red
SetLightColor(255, 0, 0);
}
`
The SetLightColor function is imported from the USB light's DLL. I also added a "reset" mechanism, so the light turns off after 60 seconds or when you click a custom button on the chart. This prevents the light from staying on forever and cluttering your visual awareness.
The Real Test: Night Trading
I set this up for a client who trades the London session but lives in a completely different timezone. He needed to know if his breakout strategy triggered during his sleep, but he didn't want to be woken by a loud alarm. The physical light was the perfect solution.
I placed the USB light on his desk, pointed toward his bed so he could see it when he woke up. The indicator ran on his VPS, so even if his computer went to sleep, the VPS was still running the code. However, the light only works if the MT4 terminal is actually running on a local machine with the USB device plugged in. This means you need to run the indicator on a local computer, not a headless VPS. The VPS handles the trading, while the local machine handles the visual alert.
We ran into a problem during testing: the indicator was calling SetLightColor every tick when the condition was true, causing the light to flicker. The fix was to add a flag to track the previous signal state. If the condition was already true and the light was already set, skip the DLL call. This reduced CPU usage and stopped the flickering.
Why This is Better Than Sound Alerts
The main advantage is persistence. A sound plays once and it's gone. A physical light stays on until you turn it off or acknowledge it. This is especially useful if you're in the middle of something when an alert fires. You can glance at the light five minutes later and still know that a signal triggered. In a forum discussion on the topic, users pointed out that this is more effective than Alert() because it's noticeable without being disruptive .
Another advantage is color coding. You can set different colors for different conditions. For instance:
Green for a buy signal
Red for a sell signal
Yellow for a pending order triggered
Blue for a trailing stop moved
This gives you a quick visual summary of your system's state without looking at a chart.
Caveats and Considerations
<strong>DLL Permission</strong>: You need to enable DLL imports in both the global settings ( Tools > Options > Expert Advisors`) and in the indicator's properties. The MQL4 documentation explicitly states that both must be enabled for DLL calls to work .The Final Setup
I ended up writing a simple wrapper indicator that I could reuse across different strategies. It monitors a set of conditions and calls the DLL functions based on the results. The indicator itself doesn't do any trading, so it's safe to run on any account without risking unwanted orders.
The light now sits on my desk, and it's become an indispensable part of my workflow. I can be working on something else entirely, and a quick glance at the light tells me if my system is signaling a trade. It's a niche solution, but for anyone who's ever missed an alert because of a noisy environment or a sleeping family, it's a game-changer.
Reference: MQL4 Documentation – Common Functions (docs.mql4.com) , Forum Discussion on Physical Alerts (talkfx.com) .
This article is originally published on FXEAR.com, original content, reproduction without authorization is prohibited.