Symbol Select -> SymbolGetDouble - page 2

 
Icham Aidibe:

Yes and no.

In case of disconnection for example, case in which it'll handle it as soon as reconnected. 

Then it remains possible to limit retries, add a sleep etc... 

In general using such loop without a sure way to quit is bad practice. Imagine you run your code an a broker where symbol EURUSD doesn't exist, but EURUSD.x

 
Alain Verleyen:

Seems like an mql5 bug ?

Yes, I mean... if there's an error retrieving the data ir should return 'false'.
Alain Verleyen:

Is it an EA, an indicator ?

You can always have a delay for the data to be ready. You can wait the next tick maybe ? Of if you want to have more control a timer. as suggested by WHRoeder/fxsaber you can also request/download the data your self.

All depends of your exact needs.

It's an EA. My goal is get data from all stock options to create a tool that helps me to create options structures.

fxsaber:
Icham Aidibe:

I don't think a 'for' is a good option. Sometimes the data is never loaded, so I would have to add an timeout, but how long it should be? I need to know if the data is not ready yet not not available all.

Thank you all for the replies.

 
Henrique Vilela:
Yes, I mean... if there's an error retrieving the data ir should return 'false'.

It's an EA. My goal is get data from all stock options to create a tool that helps me to create options structures.

I don't think a 'for' is a good option. Sometimes the data is never loaded, so I would have to add an timeout, but how long it should be? I need to know if the data is not ready yet not not available all.

Thank you all for the replies.

Have you found a solution?

I am always getting 0.0 calling SymbolInfoDouble(DifferentSymbol,SYMBOL_LAST) when symbol is different from chart.

Eg.

string symbols[]={"XXXX","ZZZZ","JJJJ","TTTT"}
int Size=ArraySize(symbols);
for(int i=0;i<Size-1;i++)
  { 
   string Smb=symbols[i];
   SymbolSelect(Smb,true);
   Sleep(100);
   double LastPrice=SymbolInfoDouble(Smb,SYMBOL_LAST);
  }       

I tried reading the documentation https://www.mql5.com/en/docs/series/timeseries_access

Funny thing that even though simetimes I got SymbolInfoDouble(DifferentSymbol,SYMBOL_LASTHIGH), the of SYMBOL_LASTLOW still has 0 value.

Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
Documentation on MQL5: Timeseries and Indicators Access / Organizing Data Access
  • www.mql5.com
Before price data become available in the MetaTrader 5 terminal, they must be received and processed. To receive data, connection to the MetaTrader 5 trade server must be established. Data are received in the form of packed blocks of minute bars from the server upon the request of a terminal. The mechanism of server reference for data doesn't...
 
gucrepaldi:

Have you found a solution?

I am always getting 0.0 calling SymbolInfoDouble(DifferentSymbol,SYMBOL_LAST) when symbol is different from chart.

Eg.

I tried reading the documentation https://www.mql5.com/en/docs/series/timeseries_access

Funny thing that even though simetimes I got SymbolInfoDouble(DifferentSymbol,SYMBOL_LASTHIGH), the of SYMBOL_LASTLOW still has 0 value.

string symbols[]={"XXXX","ZZZZ","JJJJ","TTTT"}
What's that ? If you want help please provide real information to reproduce your issue. What broker, symbols, MT5 build, where is this code running (EA, indicator..., OnInit(), OnTick()...). Also print the values in the log and show your log.
 
#include <Trade\Trade.mqh>
void OnStart()
{
   CSymbolInfo symbol;
   for(int i=SymbolsTotal(false)-1; i>=0; --i){
      if(symbol.Name(SymbolName(i, false)) && symbol.RefreshRates()){
         while(symbol.Bid() == 0.0 && symbol.RefreshRates());
         printf("%s = %f", symbol.Name(), symbol.Bid());
      }
   }     
}
 
nicholi shen:
Risk of endless loop, no ?
 
Alain Verleyen:
Risk of endless loop, no ?

Oh, most definitely. It is a lazy snippet after-all, and I'd assume that whoever uses it will know what to do with it to make it safe for work. 

 
Thank you guys. I am researching it. Apparently, it's a history data issue. 
 
gucrepaldi:
Thank you guys. I am researching it. Apparently, it's a history data issue. 

You need to make sure the symbol is selected in the market watch. Once it is selected the terminal will update the broker server which will then send back the most recent tick for that symbol. This is why I used a while loop in my example -- so it can pickup the exact moment the tick arrives back from the broker server.