Loading…

Trie Prefix Map

A symbol picker's search box, a watchlist filter, or any "narrow this list as the user types" feature over broker symbol names is usually built on a sorted array and StringFind() or a binary search per keystroke. That works, but every keystroke re-scans some slice of the whole symbol list, and collecting every match still needs a linear walk either side of wherever the search landed. A trie answers the same question by descending one node per typed character instead. Insert() builds the tree once from the symbol list; StartsWith() and Autocomplete() then walk straight to the node matching whatever has been typed and read every match directly out of the subtree below it - no scanning of unrelated symbols, no matter how long the underlying list is. Each node is a fixed-capacity struct (TRIE_MAX_CHILDREN children, sized for a realistic symbol-name alphabet) stored in one flat dynamic array and addressed by integer index rather than a real pointer - MQL4 has no object pointers into a class-typed array, so an index into a flat node array is the standard way to build a linked structure like this. Every node's children live in fixed-size arrays inside the struct, not a dynamic array per node, which avoids the struct-with-dynamic-array copy hazard this catalogue has run into elsewhere in MQL4. Notes and limitations - TRIE_MAX_CHILDREN (default 40) caps how many distinct next-characters any single node can branch into. Real symbol-name alphabets (A-Z, 0-9, and a handful of punctuation) fit well under this; Insert() returns false and prints a warning if a genuinely wider alphabet hits the cap at one node - raise the constant in the header if so. - Matching is case-sensitive by design, matching how MetaTrader itself treats symbol names. Normalise case (e.g. StringToUpper) before Insert()/Autocomplete() calls if case-insensitive matching is wanted. - There is no Remove(). A trie built once per session from the current symbol list and rebuilt (Clear() then re-Insert()) if the symbol list changes is the intended usage - this is not a general-purpose mutable set. - Autocomplete()'s recursion depth is bounded by the longest stored word, not by how many words are stored - realistic for symbol names (rarely more than 20 characters).

Script · MT4 · v1.0 · Free

About Trie Prefix Map

Trie Prefix Map is a script for MetaTrader 4. It shows several symbols in one panel and is set up for gold (XAUUSD). MQL source code included.

Files in the download: TriePrefixMap.mqh, TriePrefixMap.txt, TriePrefixMapDemo.mq4.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Binary Options · Dashboards & Scanners · Gold (XAUUSD) · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria