SymbolInfoInteger doesn't work

 

Hi every body.

I wrote following code to identify if a symbol has some data in its history or not:

bool SymbolHasData(string symbolName)
{
   bool alreadySelected = false;
   if(SymbolInfoInteger(symbolName, SYMBOL_SELECT))
      alreadySelected = true;
   else
      SymbolSelect(symbolName, true);
  
   bool bHasData = false;
   if(SymbolInfoInteger(symbolName, SYMBOL_TIME))
      bHasData = true;

   if(!alreadySelected)
      SymbolSelect(symbolName, false);
   
   return bHasData;
}



int OnStart(void)
{
   if(SymbolHasData("AUDCAD"))
      Print("AUDCAD has data");
   else
      Print("AUDCAD has no data");
      
   if(SymbolHasData("USDJPY"))
      Print("USDJPY has data");
   else
      Print("USDJPY has no data");
      
   if(SymbolHasData("USDCHF"))
      Print("USDCHF has data");
   else
      Print("USDCHF has no data");
   
   return 0;
}

When I run this code normally(not to debug or debug step-by-step but not to enter function SymbolHasData), SymbolInfoInteger returns zero and in result SymbolHasData returns false.
But if I debug the code step-by-step and enter SymbolHasData and reach to highlighted line, SymbolInfoInteger will return non-zero value and eventually SymbolHasData returns true.

Why running the code indifferent ways gives different results?

I run the code in version 5.0 build 2085.

Thanks.

 
to start with, the 2 parameter version of the function returns a long value, not a bool, so doesn't make much sense to put this into your if-statement
 
Chris70:
to start with, the 2 parameter version of the function returns a long value, not a bool, so doesn't make much sense to put this into your if-statement

Thanks for your comment, 

I know that the 2 parameter version of the SymbolInfoInteger returns a long value, not a bool, so putting it into if-statement means implicitly 'if(returned value > 0)' .

Writing code this way is however less readable but is correct.

 

Okay, get it; just wasn't sure if an !=0 check really was your intention; in this case ignore my first comment.

Another thing: Is the function supposed to be part of a script, expert or indicator (I'm asking because you're calling it from the OnStart event, which makes me assume it's a script)? Do you get different results from OnTick?

 
Chris70:

Okay, get it; just wasn't sure if an !=0 check really was your intention; in this case ignore my first comment.

Another thing: Is the function supposed to be part of a script, expert or indicator (I'm asking because you're calling it from the OnStart event, which makes me assume it's a script)? Do you get different results from OnTick?

Thanks again, yes it is a script not an expert or indicator.
I am using the function SymbolHasData here and in another script in a loop to find all symbols that have any data.
Calling it in OnTimer event handler of an expert also gives incorrect result.

 

Hello please try to call.

SymbolName(pos,0) 
 
rbigdelis:

Hi every body.

I wrote following code to identify if a symbol has some data in its history or not:

When I run this code normally(not to debug or debug step-by-step but not to enter function SymbolHasData), SymbolInfoInteger returns zero and in result SymbolHasData returns false.
But if I debug the code step-by-step and enter SymbolHasData and reach to highlighted line, SymbolInfoInteger will return non-zero value and eventually SymbolHasData returns true.

Why running the code indifferent ways gives different results?

I run the code in version 5.0 build 2085.

Thanks.

Seems like an MT5 bug.

If you add an output like :

   if(SymbolInfoInteger(symbolName,SYMBOL_TIME))
      bHasData=true;
   else
      printf("Error #%i with SymbolInfoInteger TIME",_LastError);

It prints to the log :

2019.09.03 07:11:46.676    321459 (USDCAD,D1)    Error #0 with SymbolInfoInteger TIME

So it returns a wrong date, but report "No Error".

However if you use the other signature, it works well.

   bool bHasData=false;
   datetime time;
   if(SymbolInfoInteger(symbolName,SYMBOL_TIME,time))
      bHasData=true;
   else
      printf("Error #%i with SymbolInfoInteger TIME",_LastError);
 

Thanks, when I run modified code as you recommended, I get different results at different times.

Sometimes for symbols with empty history, SymbolInfoInteger returns true but returned time is zero that means no data is available.

And sometimes for symbols with non-empty history,  SymbolInfoInteger returns true and returned time is zero that means no data is available!!!.

I think SymbolSelect has a bug that doesn't updates MarketWatch immediately, so calling functions like SymbolInfoInteger or SymbolInfoTick after SymbolSelect doesn't return correct result(s).

 
rbigdelis: I think SymbolSelect has a bug that doesn't updates MarketWatch immediately, so calling functions like SymbolInfoInteger or SymbolInfoTick after SymbolSelect doesn't return correct result(s).

Read the documentation. It is specifically stated that it does not update immediately. So of course it doesn't immediately "return corret result(s)."

On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
          Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
          SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum 2019.09.03

 
William Roeder:

Read the documentation. It is specifically stated that it does not update immediately. So of course it doesn't immediately "return corret result(s)."

...

Where ? I can't find that.

 
rbigdelis:

Thanks, when I run modified code as you recommended, I get different results at different times.

Sometimes for symbols with empty history, SymbolInfoInteger returns true but returned time is zero that means no data is available.

And sometimes for symbols with non-empty history,  SymbolInfoInteger returns true and returned time is zero that means no data is available!!!.

I think SymbolSelect has a bug that doesn't updates MarketWatch immediately, so calling functions like SymbolInfoInteger or SymbolInfoTick after SymbolSelect doesn't return correct result(s).

Documented or not, anyway you have to adapt your code to take that into account.
Reason: