Loading…

Fuzzy String Matching

"EURUSD", "EURUSDm" and "EUR/USD.a" are the same instrument under three different broker naming conventions, and two news headlines about the same release are rarely worded the same way twice. Exact string comparison fails all of these, so this header provides three different notions of "close enough" and lets the caller pick the one that fits the problem: edit distance for near-typo differences in short strings, Jaro-Winkler for identifiers where a shared prefix should count for more than a shared tail, and token-set overlap for comparing whole phrases by their words rather than character by character. Levenshtein's textbook implementation needs a full edit-distance matrix, but a true two-dimensional dynamic array is awkward on this platform too, and here both dimensions depend on input length anyway. The algorithm only ever reads the row directly above the one it is filling, so this implementation keeps two 1D rows and swaps them after each character instead of a full matrix - O(shorter string's length) memory rather than O(n times m). The cost is that only the distance/similarity number comes out, not the character-by-character alignment - every use case in this catalogue needs the score, not the alignment. Notes and limitations - All comparisons operate on ushort character codes on both platforms, which covers ASCII and the Basic Multilingual Plane correctly but does not do full Unicode grapheme-aware comparison - fine for symbol codes and English headlines, not guaranteed for combined/accented characters. - TokenSetSimilarity splits only on single spaces after lowercasing; a headline with tabs, multiple consecutive spaces or punctuation stuck to a word (e.g. "cuts." vs "cuts") is not further cleaned - normalise the input yourself first if that matters for a specific feed. - FuzzyFindBestMatch is a linear scan over the haystack, O(n) comparisons each doing O(length) work - fine for a broker's few hundred symbols or a short list of recent headlines, not intended for matching against a large corpus on every tick.

Script · MT4 · v1.0 · Free

About Fuzzy String Matching

Fuzzy String Matching 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: FuzzyStringMatch.mqh, FuzzyStringMatch.txt, FuzzyStringMatchDemo.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: News Trading · EURUSD · Dashboards & Scanners · Gold (XAUUSD) · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria