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…