Menu

Handling broker symbol suffixes in an MQL5 EA so one build works everywhere
📰

Handling broker symbol suffixes in an MQL5 EA so one build works everywhere

DEV Community: cpp·Omais Ali·about 11 hours ago
#ywGcNZ01
#devtocpp#devto#dev#symbol#base
Long article (617 words) — no AI summary yet.
Reading 0:00
15s threshold

An Expert Advisor that trades EURUSD on one broker often finds nothing to trade on the next one, because that broker calls it EURUSD.m, EURUSDpro, EURUSD.r or eurusd_i. If the symbol list is hard coded, the EA silently does nothing, or worse, a multi symbol EA trades some pairs and skips others without anyone noticing.

Here is a small, reusable way to resolve the broker's real symbol names at startup.

Resolve once in OnInit

The idea: take the base names you care about, scan every symbol the broker offers, and pick the one that starts with the base name and has the shortest leftover suffix.

string ResolveSymbol ( const string base ) { if ( SymbolInfoInteger ( base , SYMBOL_EXIST ) ) return base ;

string best = "" ; int total = SymbolsTotal ( false ) ; for ( int i = 0 ; i < total ; i ++ ) { string name = SymbolName ( i , false ) ; if ( StringFind ( name , base ) != 0 ) continue ; if ( best == "" || StringLen ( name ) < StringLen ( best ) ) best = name ; } return best ; }

Enter fullscreen mode

Exit…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.