Loading…

Build Market Watch From File

A Market Watch list is local to one terminal profile. Move to a new computer, switch brokers, or set up a demo alongside a live account, and the watchlist has to be rebuilt symbol by symbol from memory. This script rebuilds it from a text file instead - one symbol per line, or a comma separated line, dropped into the terminal's MQL4\Files\ folder. The part that makes this worth using rather than a five-line loop is the name mismatch every broker introduces. A list written as "EURUSD,GBPUSD" on one broker rarely matches the next broker's names exactly - suffixes like .m, .raw, -ecn or a trailing "m" get appended to the same underlying instrument, and MarketInfo simply returns nothing for a name that does not exist verbatim. A script that only tries the exact string leaves half the list unselected with no explanation, which is worse than doing nothing, because a silently incomplete watchlist looks complete until a symbol you expected to see is missing when you need it. This script tries the exact name first, and only when that fails does it fall back to a prefix search across every symbol the broker actually offers, case insensitive. "EURUSD" then matches "EURUSD.m" or "eurusdecn" automatically. When more than one broker symbol shares that prefix, the shortest match is taken by default - the closest thing to "the same name plus a suffix" rather than an unrelated longer symbol that happens to share the same leading letters - and every ambiguous case is reported by name, or refused outright when InpFailOnAmbiguous is turned on for a stricter build. Notes and limitations - Prefix matching assumes the broker's real name starts with the requested name. A broker that prepends rather than appends its suffix (rare, but it happens) will not be found this way. - The shortest-match rule for ambiguous prefixes is a heuristic, not a guarantee. Turn on InpFailOnAmbiguous for a broker with several closely named symbols where a wrong pick would matter. - Custom or synthetic symbols that are not registered with the broker at all cannot be selected regardless of spelling - MarketInfo has nothing to select. - The file is read once per run. Editing the file does not update Market Watch until the script is run again.

Script · MT5 · v1.0 · Free

About Build Market Watch From File

Build Market Watch From File is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as File name, Remove unlisted and Fail on ambiguous. MQL source code included.

Files in the download: BuildMarketWatchFromFile.ex5, BuildMarketWatchFromFile.mq5, BuildMarketWatchFromFile.txt.

Settings

SettingDefaultWhat it does
File namewatchlist.txtFile in MQL5\Files\ - one symbol per line
Remove unlistedfalseAlso hide currently watched symbols not on the list
Fail on ambiguousfalseRefuse a name with more than one prefix match instead of picking the first

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria