Pull all Symbols in Market Watch with data in EA

 

Any suggestions from the experts here on how to pull all the Symbols available in the Broker Account through an EA?


 

Try this code (limitation: only works for first 5000 characters)

//+------------------------------------------------------------------+
//|                                             Symbols to Excel.mq5 |
//|                              Copyright © 2020, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020, Vladimir Karputov"
#property version   "1.003"
#property script_show_inputs
//---
#include <Trade\SymbolInfo.mqh>
//---
CSymbolInfo    m_symbol;                     // object of CSymbolInfo class
//--- input parameters
input int      Input1=9;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   int filehandle=FileOpen("Symbols.csv",FILE_WRITE|FILE_CSV);
   if(filehandle==INVALID_HANDLE)
     {
      Print("Operation FileOpen failed, error ",GetLastError());
      return;
     }
//---
   int symbols_total=SymbolsTotal(false);
   int start=0,stop=0;
   if(symbols_total>5000)
      stop=5000;
   else
      stop=symbols_total;
//--- creation Button[]
   for(int i=start; i<stop; i++)
     {
      string symbol_name=SymbolName(i,false);
      if(!m_symbol.Name(symbol_name)) // sets symbol name
        {
         Print("#",i," ",symbol_name,", ",__FUNCTION__,", ERROR: CSymbolInfo.Name",", IsSynchronized: ",m_symbol.IsSynchronized());
         continue;
        }
      if(RefreshRates())
        {
         //Print("#",i," ",symbol_name,", ",DoubleToString(m_symbol.Bid(),m_symbol.Digits()),", ",DoubleToString(m_symbol.Ask(),m_symbol.Digits()));
         FileWrite(filehandle,symbol_name,DoubleToString(m_symbol.Bid(),m_symbol.Digits()),DoubleToString(m_symbol.Ask(),m_symbol.Digits()));
        }
     }
   FileClose(filehandle);
  }
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data                                 |
//+------------------------------------------------------------------+
bool RefreshRates()
  {
//--- refresh rates
   if(!m_symbol.RefreshRates())
     {
      //if(InpPrintLog)
      Print(m_symbol.Name()," ",__FUNCTION__,", ERROR: ","RefreshRates error");
      return(false);
     }
//--- protection against the return value of "zero"
   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
     {
      //if(InpPrintLog)
      Print(m_symbol.Name()," ",__FUNCTION__,", ERROR: ","Ask == 0.0 OR Bid == 0.0",", IsSynchronized: ",m_symbol.IsSynchronized());
      return(false);
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
Files:
 
Vladimir Karputov:

Try this code (limitation: only works for first 5000 characters)

Thank you Mr. Vladimir. The script is working good in MT5. Stay blessed with lots of health, inner peace, prosperity and abundance from the Supreme Power!
 
Shine Scariah:
Thank you Mr. Vladimir. The script is working good in MT5. Stay blessed with lots of health, inner peace, prosperity and abundance from the Supreme Power!
How about for MT4?
 
Shine Scariah :
How about for MT4?

Throw it away and forget it. This is my advice.

 

Hello,
interesting tool.
What does the limitation of 5000 mean?

Suddenly the expert does not show up in the chart anymore...

Any idea, how to solve?

Cheers