MQL5Book/Scripts/p6/SymbolList.mq5

29 lines
1.2 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:09:41 +02:00
//+------------------------------------------------------------------+
//| SymbolList.mq5 |
//| Copyright 2022, MetaQuotes Ltd. |
//| https://www.mql5.com |
//| Write a list of symbols to the log. |
//+------------------------------------------------------------------+
#property script_show_inputs
#include "..\..\Include\PRTF.mqh"
input bool MarketWatchOnly = true;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
const int n = SymbolsTotal(MarketWatchOnly);
// list all symbols in Market Watch or available in general
Print("Total symbol count: ", n);
for(int i = 0; i < n; ++i)
{
PrintFormat("%4d %s", i, SymbolName(i, MarketWatchOnly));
}
// now incorrect (out of bound) request made intentionally to demo the error
PRTF(SymbolName(n, MarketWatchOnly)); // MARKET_UNKNOWN_SYMBOL(4301)
}
//+------------------------------------------------------------------+