Unselected Symbol Trap Demo
MarketInfo() on a symbol that is not currently selected in Market Watch does not fail, throw an error, or warn - it returns 0.0 for every field, which looks exactly like "the market is at zero right now" to any code that does not know the difference. A multi-symbol scanner that filters out zero-priced symbols will silently skip a perfectly tradeable instrument for an entire session because of a Market Watch membership problem, and report nothing wrong - the zero looks like normal data, not an error condition. This script demonstrates the trap on a real symbol rather than describing it. It scans the broker's full symbol list for one not currently selected, prints what MarketInfo() reports for it (bid, ask, point, digits - all zero), calls SymbolSelect(symbol, true), and prints the same fields again. A freshly selected symbol is not instantly populated - the terminal has to start synchronising a live quote stream for it - so the script polls with a short bounded wait rather than trusting the very next call, the same readiness gap a freshly created indicator handle has. It then deselects the symbol again so Market Watch is left exactly as it was found, since a diagnostic script should not have a permanent side effect on the user's chart list. Notes and limitations If every symbol the broker offers is already in Market Watch, there is no real unselected symbol to demonstrate on - the script explains this in the log and falls back to a name that cannot exist, which shows the same zero-return shape for a related but distinct reason (no such symbol, rather than an unselected one) and cannot be fixed with SymbolSelect(). The "after" wait is capped at two seconds; on an unusually slow terminal or a thin, rarely-quoted symbol, a real quote may legitimately take longer to arrive than that, and the script will report the wait as still-zero rather than wait indefinitely.
Script · MT4 · v1.0 · Free
About Unselected Symbol Trap Demo
Unselected Symbol Trap Demo is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 1 setting, such as Symbol. MQL source code included.
Files in the download: UnselectedSymbolTrapDemo.mq4, UnselectedSymbolTrapDemo.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol | Symbol to demonstrate on (blank = auto-pick an unselected one) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Moving Average · Dashboards & Scanners · Trading Sessions · Multi-Currency · Alerts · MT4 Script · MQL4 Source Code