Get best bid and ask for symbol that is not in market watch

 

Hi!

I want to export to a csv file all papers of trading server and some of their current information, mainly the best bid and ask.

I already now that MT is event based so I now that the correct way to that would using some of the events functions like OnTimer or OnTick, but I'd like to export information of symbols that are not the current graph window or even not in the market watch, since I would be limited to 1.000 symbols.

So, what should be the correct or the best way to do that? Right now, I'm using an "Sleep" and checking for X times if I can get the some information like the last trade price, and then I go to the next symbol, but it takes long and it's not smart, since sometimes the symbol may take longer than that to load and I'll miss the information :)

Is there some way to verify if the symbol information is loaded or is there a way to force it's synchronization and to monitor when it's ready?

So, what I have so far right now:

   int RETRIES=4;
   int SLEEP=250;
   MqlBookInfo BookInfo[];
   bool MARKET=true;
   int h=FileOpen("symbols.csv",FILE_WRITE|FILE_ANSI|FILE_TXT);

   if(h==INVALID_HANDLE){
      Alert("Error opening file");
      return;
   }
   int HowManySymbols=SymbolsTotal(MARKET);

   // HEADER
   FileWrite(h,"SYMBOL,DESCRIPTION,PRICE,RIGHT,TYPE,STRIKE,DUE,BID,ASK,VOLUME");


   for(int j=0;j<HowManySymbols;j++)
   {
      SymbolSelect(SymbolName(j,MARKET),true);
      int x=0;
      if(SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_LAST)==0){
         while(SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_LAST)==0 && x<RETRIES){
            Print("Waiting "  + SymbolName(j,MARKET) + " " + (x+1) + "/"+RETRIES);
            Sleep(SLEEP);
            x++;
         }
      }

         FileWrite(h,"\""+
            SymbolName(j,MARKET)+"\",\""+
            SymbolInfoString(SymbolName(j,MARKET),SYMBOL_DESCRIPTION)+"\",\""+
            SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_LAST)+"\",\""+
            (SymbolInfoInteger(SymbolName(j,MARKET),SYMBOL_OPTION_MODE)?"AMER":"EUR")+"\",\""+
            (SymbolInfoInteger(SymbolName(j,MARKET),SYMBOL_OPTION_RIGHT)?"PUT":"CALL")+"\",\""+
            SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_OPTION_STRIKE)+"\",\""+
            (datetime)SymbolInfoInteger(SymbolName(j,MARKET),SYMBOL_EXPIRATION_TIME)+"\",\""+
            SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_BID)+"\",\""+
            SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_ASK)+"\",\""+
            SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_SESSION_VOLUME)+"\""
          );

           SymbolSelect(SymbolName(j,MARKET),false);
   }
   FileClose(h);

Thanks in advance!

 
you should change MARKET to false.
 
Mohammad Hashemi:
you should change MARKET to false.

sorry, my bad! I made it, but I still getting empty values for almost the symbols for SymbolInfoDouble(SymbolName(j,MARKET),SYMBOL_ASK), since the SYMBOL is not synchronized (or MT does not have information yet for this symbol).

My doubt is, how to load that and check if it's already synchronized and the write in the file. Thanks!!