SymbolList
Download scriptThis script is designed for users of the MetaTrader trading platform who need to automatically discover and export a comprehensive list of available financial instruments (symbols) from their broker's market. Instead of manually scrolling through hundreds of options, this tool systematically "scans" the market based on specific naming rules you provide.
How the Logic Works
1. Configuration and Filtering The process begins by letting you define what kind of symbols you are looking for. You can set the minimum and maximum number of characters a symbol name should have. Additionally, you can toggle specific characters to include in the search, such as:
- Numbers (0-9)
- Uppercase letters (A-Z)
- Lowercase letters (a-z)
- Special characters like hashtags (#) or underscores (_)
2. The Brute-Force Search Engine Once the criteria are set, the script performs a comprehensive "brute-force" search. It systematically combines every allowed character into different combinations to build potential symbol names. For example, if you allow letters and numbers, it will try every possible 1-letter combination, then every 2-letter combination, and so on, up to your specified limit.
3. Real-Time Verification For every single name the script "builds" during this process, it instantly queries the live market to see if that specific symbol actually exists. If the broker confirms the symbol is active, the script adds it to a master list.
4. Time Estimation Because generating thousands of combinations can take some time depending on your settings, the script calculates an estimated time for completion before it starts. It displays this progress on your screen so you know how long the scan will take.
5. Data Export Once the search is finished, the script performs two final actions:
- On-Screen Summary: It displays a list of all found symbols and the total count directly on your trading chart.
- CSV File Creation: It automatically creates a professional spreadsheet file (CSV) on your computer. This file contains not just the names of the symbols, but also vital technical data for each one—such as point size, digits, spreads, swap rates, lot sizes, and expiration details.
Summary of Use
This tool is essentially an automated "scout." You tell it which letters or numbers to look for, and it scans the entire market to find every matching instrument, gathering all their technical specifications into a organized file for your later use.
//+------------------------------------------------------------------+
//| SymbolList.mq4 |
//| Copyright © 2006, komposter |
//| mailto:komposterius@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, komposter"
#property link "mailto:komposterius@mail.ru"
#property show_inputs
extern int Min_CharsInSymbolName = 0;
extern int Max_CharsInSymbolName = 6;
extern bool Use_Reshetka = false;
extern bool Use_Podcherkivanie = false;
extern bool Use_09 = false;
extern bool Use_AZ = true;
extern bool Use_az = false;
int start()
{
string Symbols[1000], tmpSymbol = "";
int CharsCount = 0, SymbolsCount = 0, CurChar, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, StartTickCount = GetTickCount();
string Chars[1000];
if ( Max_CharsInSymbolName < 1 ) { Comment( "Max_CharsInSymbolName < 1 !!!" ); return(0); }
if ( Min_CharsInSymbolName > 10 ) { Comment( "Min_CharsInSymbolName > 10 !!!" ); return(0); }
if ( Use_Reshetka ) // "#"
{
Chars[CharsCount] = "#";
CharsCount ++;
}
if ( Use_Podcherkivanie ) // "_"
{
Chars[CharsCount] = "_";
CharsCount ++;
}
if ( Use_09 ) // "0" - "9"
{
for ( CurChar = 48; CurChar < 58; CurChar ++ )
{
Chars[CharsCount] = CharToStr(CurChar);
CharsCount ++;
}
}
if ( Use_AZ ) // "A" - "Z"
{
for ( CurChar = 65; CurChar < 91; CurChar ++ )
{
Chars[CharsCount] = CharToStr(CurChar);
CharsCount ++;
}
}
if ( Use_az ) // "a" - "z"
{
for ( CurChar = 97; CurChar < 123; CurChar ++ )
{
Chars[CharsCount] = CharToStr(CurChar);
CharsCount ++;
}
}
if ( CharsCount < 1 ) { Comment( "Íå âûáðàíû ñèìâîëû äëÿ ïåðåáîðà!!!" ); return(0); }
ArrayResize( Chars, CharsCount );
//---- îöåíî÷íîå âðåìÿ ðàáîòû = êîë-âî êîìáèíàöèé * âðåìÿ ïðîâåðêè îäíîé êîìáèíàöèè íà ìîåì êîìïå =)
double count_seconds = MathPow(CharsCount,Max_CharsInSymbolName)*0.00000350;
double count_minutes = MathFloor(count_seconds/60.0);
count_seconds -= count_minutes*60;
double count_hours = MathFloor(count_minutes/60.0);
count_minutes -= count_hours*60;
Comment( "Ïîèñê çàéìåò ïðèáëèçèòåëüíî ", NormalizeDouble( count_hours, 0 ), " ÷ ", NormalizeDouble( count_minutes, 0 ), " ì ", NormalizeDouble( count_seconds, 0 ), " ñ, æäèòå...." );
for ( s1 = 0; s1 < CharsCount; s1 ++ )
{
if ( Min_CharsInSymbolName <= 1 )
{
tmpSymbol = Chars[s1];
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 2 ) { continue; }
for ( s2 = 0; s2 < CharsCount; s2 ++ )
{
if ( Min_CharsInSymbolName <= 2 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 3 ) { continue; }
for ( s3 = 0; s3 < CharsCount; s3 ++ )
{
if ( Min_CharsInSymbolName <= 3 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 4 ) { continue; }
for ( s4 = 0; s4 < CharsCount; s4 ++ )
{
if ( Min_CharsInSymbolName <= 4 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3], Chars[s4] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 5 ) { continue; }
for ( s5 = 0; s5 < CharsCount; s5 ++ )
{
if ( Min_CharsInSymbolName <= 5 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3], Chars[s4], Chars[s5] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 6 ) { continue; }
for ( s6 = 0; s6 < CharsCount; s6 ++ )
{
if ( Min_CharsInSymbolName <= 6 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3], Chars[s4], Chars[s5], Chars[s6] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 7 ) { continue; }
for ( s7 = 0; s7 < CharsCount; s7 ++ )
{
if ( Min_CharsInSymbolName <= 7 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3], Chars[s4], Chars[s5], Chars[s6], Chars[s7] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 8 ) { continue; }
for ( s8 = 0; s8 < CharsCount; s8 ++ )
{
if ( Min_CharsInSymbolName <= 8 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3], Chars[s4], Chars[s5], Chars[s6], Chars[s7], Chars[s8] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 9 ) { continue; }
for ( s9 = 0; s9 < CharsCount; s9 ++ )
{
if ( Min_CharsInSymbolName <= 9 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3], Chars[s4], Chars[s5], Chars[s6], Chars[s7], Chars[s8], Chars[s9] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
if ( Max_CharsInSymbolName < 10 ) { continue; }
for ( s10 = 0; s10 < CharsCount; s10 ++ )
{
if ( Min_CharsInSymbolName <= 10 )
{
tmpSymbol = StringConcatenate( Chars[s1], Chars[s2], Chars[s3], Chars[s4], Chars[s5], Chars[s6], Chars[s7], Chars[s8], Chars[s9], Chars[s10] );
if ( MarketInfo( tmpSymbol, MODE_BID ) > 0 )
{
Symbols[SymbolsCount] = tmpSymbol;
SymbolsCount ++;
}
}
}
}
}
}
}
}
}
}
}
}
count_seconds = (GetTickCount() - StartTickCount)/1000;
count_minutes = MathFloor(count_seconds/60.0);
count_seconds = count_seconds - count_minutes*60;
count_hours = MathFloor(count_minutes/60.0);
count_minutes -= count_hours*60;
if ( SymbolsCount < 1 )
{
Comment( StringConcatenate( "Âðåìÿ ðàáîòû: ", NormalizeDouble( count_hours, 0 ), " ÷ ", NormalizeDouble( count_minutes, 0 ), " ì ", NormalizeDouble( count_seconds, 0 ), " ñ \nÍå íàéäåíî íè îäíîãî ñèìâîëà, îòâå÷àþùåãî óñëîâèÿì!!!" ) );
return(0);
}
ArrayResize( Symbols, SymbolsCount );
string strAllSymbols = Symbols[0];
for ( int CurSymbol = 1; CurSymbol < SymbolsCount; CurSymbol ++ )
{
strAllSymbols = StringConcatenate( strAllSymbols, "\n", Symbols[CurSymbol] );
}
Comment( StringConcatenate( "Âðåìÿ ðàáîòû: ", NormalizeDouble( count_hours, 0 ), " ÷ ", NormalizeDouble( count_minutes, 0 ), " ì ", NormalizeDouble( count_seconds, 0 ), " ñ \nÍàéäåíî ", SymbolsCount, " ñèìâîëîâ:\n", strAllSymbols ) );
int handle = FileOpen( StringConcatenate( "SymbolList(", ServerAddress(), ").csv" ), FILE_CSV | FILE_WRITE );
if ( handle < 0 )
{
Print( "Îøèáêà ¹", GetLastError(), " ïðè îòêðûòèè ôàéëà!!!" );
return(-1);
}
FileWrite( handle,
"SYMBOL",
"POINT",
"DIGITS",
"SPREAD",
"STOPLEVEL",
"LOTSIZE",
"TICKVALUE",
"TICKSIZE",
"SWAPLONG",
"SWAPSHORT",
"STARTING",
"EXPIRATION",
"TRADEALLOWED",
"MINLOT",
"LOTSTEP",
"MAXLOT"
);
for ( CurSymbol = 0; CurSymbol < SymbolsCount; CurSymbol ++ )
{
FileWrite( handle,
Symbols[CurSymbol],
MarketInfo( Symbols[CurSymbol], MODE_POINT ),
MarketInfo( Symbols[CurSymbol], MODE_DIGITS ),
MarketInfo( Symbols[CurSymbol], MODE_SPREAD ),
MarketInfo( Symbols[CurSymbol], MODE_STOPLEVEL ),
MarketInfo( Symbols[CurSymbol], MODE_LOTSIZE ),
MarketInfo( Symbols[CurSymbol], MODE_TICKVALUE ),
MarketInfo( Symbols[CurSymbol], MODE_TICKSIZE ),
MarketInfo( Symbols[CurSymbol], MODE_SWAPLONG ),
MarketInfo( Symbols[CurSymbol], MODE_SWAPSHORT ),
MarketInfo( Symbols[CurSymbol], MODE_STARTING ),
MarketInfo( Symbols[CurSymbol], MODE_EXPIRATION ),
MarketInfo( Symbols[CurSymbol], MODE_TRADEALLOWED ),
MarketInfo( Symbols[CurSymbol], MODE_MINLOT ),
MarketInfo( Symbols[CurSymbol], MODE_LOTSTEP ),
MarketInfo( Symbols[CurSymbol], MODE_MAXLOT )
);
}
FileClose( handle );
return(0);
}
Comments