Symbol Select -> SymbolGetDouble

 

I'm trying to select a symbol and get its last price

string symbol="ANY_SYMBOL_HERE";
double last;
bool ok=SymbolSelect(symbol,true); // OK is True
bool ok=SymbolInfoDouble(symbol,SYMBOL_ASK,last); //  // OK is True
// last is zero

SymbolInfoDouble returns true, but the variable is zero.

If I add a sleep after the SymbolSelect command everything works. But of course is not a good solution. 

string symbol="ANY_SYMBOL_HERE";
double last;
bool ok=SymbolSelect(symbol,true); // OK is True
Sleep(100);
bool ok=SymbolInfoDouble(symbol,SYMBOL_ASK,last); //  // OK is True
// last has value

Searching the documentation I've found the SymbolIsSynchronized function, the description sounds like what I'm looking for but it always returns false.

So, what's the best practice to make sure the symbol data is already available?

 
On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
 
Henrique Vilela:

I'm trying to select a symbol and get its last price

SymbolInfoDouble returns true, but the variable is zero.

If I add a sleep after the SymbolSelect command everything works. But of course is not a good solution. 

Searching the documentation I've found the SymbolIsSynchronized function, the description sounds like what I'm looking for but it always returns false.

So, what's the best practice to make sure the symbol data is already available?

Honestly I am tired to answer you, as most of the time :

1° You don't answer or thanks most of the time, nothing. #1, #2, #3, #4, #5, #6, #7, #8

2° and/or you never give any feedback. #1, #2, #3, #4, #5, #6, #7, #8, #9, #10, #11.

3° with some exceptions #1, #2, #3, #4.

On your idea, why people are answering to question on the forum ? That's because they can :

  • share (both direction is largely preferred, you never helped anyone AFAIK),
  • learn
  • have social contacts
  • do what they like (coding, trading, babbling, etc...). For example, I like numbers and precision, so I checked all the topics you created (well actually I stopped after 30th as I was bored).

It seems to me you are only interested to get information and idea without sharing anything. It's a pity as your questions are often interesting.

Please tell me I am wrong ? @Henrique Vilela

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Ошибки, баги, вопросы

Slava, 2017.02.14 12:24

Before you check the synchronization history flag, you must first call CopyRates (Symbol (), PERIOD_M1,0,1000, rates)

If this is done from the indicator, then exactly given 'as is', but with a request to the historical center about pumping. Then it can be excruciating.

If this is done from an expert or a script, several queries can be made inside the function with a waiting response, and as a rule after such a call the history will be synchronized

 
whroeder1:
On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5

Thank you.

Alain Verleyen:

Please tell me I am wrong ? @Henrique Vilela

No. You're right. Sorry.

My english is terrible and the portuguese forum here has no action, so I only log here when I can't solve the problem somewhere else. By default this forum give no notification, so many times I just forgot that I had asked here. Just recently I've discover the golden star icon to get notifications.

But I can assure you I'm not a selfish information collector, I do my fair share of given. :) 

I manage a portuguese MQL5 and whatpsapp community with 2.300 members and a portuguese Metatrader 5 community with 7.700 members. Also in my Youtube Channel I have an 100% free MQL5 course with 4.300 views.

On those communities I play your role. :)

But again, you're right and I'm sorry. I hope you understand and thank you for your time.

 
Henrique Vilela:

Thank you.

No. You're right. Sorry.

My english is terrible and the portuguese forum here has no action, so I only log here when I can't solve the problem somewhere else. By default this forum give no notification, so many times I just forgot that I had asked here. Just recently I've discover the golden star icon to get notifications.

But I can assure you I'm not a selfish information collector, I do my fair share of given. :) 

I manage a portuguese MQL5 and whatpsapp community with 2.300 members and a portuguese Metatrader 5 community with 7.700 members. Also in my Youtube Channel I have an 100% free MQL5 course with 4.300 views.

On those communities I play your role. :)

But again, you're right and I'm sorry. I hope you understand and thank you for your time.

I understand, thanks for the explanation. By the way your English is fine, at least for me :-)

Thank you.

 
Henrique Vilela:

I'm trying to select a symbol and get its last price

SymbolInfoDouble returns true, but the variable is zero.

Seems like an mql5 bug ?

If I add a sleep after the SymbolSelect command everything works. But of course is not a good solution. 

Searching the documentation I've found the SymbolIsSynchronized function, the description sounds like what I'm looking for but it always returns false.

So, what's the best practice to make sure the symbol data is already available?

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.

 
#define _CS(A) ((!IsStopped()) && (A))

// Only for Experts and Scripts
bool SymbolSync( const string Symb )
{
  static const bool IsNotIndicator = ((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE) != PROGRAM_INDICATOR);
  
  bool Res = IsNotIndicator && SymbolInfoInteger(Symb, SYMBOL_SELECT) && !SymbolInfoInteger(Symb, SYMBOL_CUSTOM);
  
  if (Res)
  {
    MqlTick Tick = {0};
    
    while (_CS(!(SymbolInfoTick(Symb, Tick) && (Res = Tick.time))))
      Sleep(0);
  }
  
  return(Res);
}

void OnStart()
{
  for (int i = SymbolsTotal(false) - 1; i >= 0; i--)
  {
    const string Symb = SymbolName(i, false);
    
    if ((!SymbolInfoInteger(Symb, SYMBOL_SELECT)) && SymbolSelect(Symb, true))
    {
      Print(Symb);
      Print(SymbolSync(Symb));
      Print(SymbolInfoDouble(Symb, SYMBOL_ASK));
      
      break;
    }
  }
}
 
Henrique Vilela:

I'm trying to select a symbol and get its last price

SymbolInfoDouble returns true, but the variable is zero.

If I add a sleep after the SymbolSelect command everything works. But of course is not a good solution. 

Searching the documentation I've found the SymbolIsSynchronized function, the description sounds like what I'm looking for but it always returns false.

So, what's the best practice to make sure the symbol data is already available?

I would have do it so : 

do { /*nothing*/ }
while ((!SymbolSelect("EURUSD",true)) || (SymbolInfoDouble("EURUSD",SYMBOL_ASK)==0));
printf("*** Ask : %g",SymbolInfoDouble("EURUSD",SYMBOL_ASK));
 
Icham Aidibe:

I would have do it so : 

Bad practice, you could have an infinite loop.

 
Alain Verleyen:

Bad practice, you could have an infinite loop.


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... 

Reason: