m_symbol.Ask() and m_symbol.Bid() not showing real Ask and Bid price

 

Hello!

I have an issue with an EA. I have a function that modifies the current open position stops and I realized that m_symbol.Ask() and  m_symbol.Bid() are not the real Ask and Bid prices.

In order to debug it, I have this code to print the values:


Print("M symbol ask1  ======================= ", SymbolInfoDouble(_Symbol, SYMBOL_ASK));

Print("M symbol bid1  ======================= ", SymbolInfoDouble(_Symbol, SYMBOL_BID));

Print("M symbol ask2  ======================= ", m_symbol.Ask());

Print("M symbol bid2  ======================= ", m_symbol.Bid());


And this is the result:

The correct prices are the ones calculated with "SymbolInfoDouble"  (ask1, and bid1), but the expert considers the other values, the ones calculated with m_symbol.Ask() and m_symbol.Bid()

This causes that position modification fails because of invalid stops. In the example, the TP is higher than the 'fake' ask price that expert is considering.

Do you know why is this happening?

Any help would be appreciated, thank you!

 
Your topic has been moved to the section: Expert Advisors and Automated Trading — In the future, please consider which section is most appropriate for your query.
 

The current tick values can change during one moment to the next during which you are collecting data.

However, you have not shown that you are refreshing rates, nor that the class object "m_symbol", is in fact referring to the same current symbol "_Symbol".

m_symbol.RefreshRates();
Print("M symbol ask1  ======================= ", SymbolInfoDouble(_Symbol, SYMBOL_ASK));
Print("M symbol bid1  ======================= ", SymbolInfoDouble(_Symbol, SYMBOL_BID));
Print("M symbol ask2  ======================= ", m_symbol.Ask());
Print("M symbol bid2  ======================= ", m_symbol.Bid());
Print("M symbol name1 ======================= ", _Symbol);
Print("M symbol name2 ======================= ", m_symbol.Name());

I repeat even with the RefreshRates, it can still happen that the values will update between reading the current values, as the current tick can change from one moment to the next.

 

Yes, that was the problem, I was not refreshing rates :/

Thank you very much Fernando.

Reason: