Download MetaTrader 5

getting the last price of a symbol

To add comments, please log in or register
Use searching on MQL5.community. It is easy!
sd2000sd
212
sd2000sd 2014.02.27 10:01 

I want to get the info for a symbol using:

what is wrong with my code?

it prints: 7.0

but it must print : price of the last deal which is: 3588 

ENUM_SYMBOL_INFO_DOUBLE symbInfoDouble;
SymbolInfoDouble(Symbol(),symbInfoDouble);
double last=(symbInfoDouble.SYMBOL_LAST);
Print (last);
zartan
650
zartan 2014.02.27 10:51  
double toto=SymbolInfoDouble("EURUSD",SYMBOL_LAST);
Paul Anscombe
3996
Paul Anscombe 2014.02.27 10:52  
sd2000sd:

I want to get the info for a symbol using:

what is wrong with my code?

it prints: 7.0

but it must print : price of the last deal which is: 3588 

you are getting a little lost....

this will do what you require:

 double Price = SymbolInfoDouble(_Symbol,SYMBOL_BID);

notice I used SYMBOL_BID just to get the current bid price,  SYMBOL_LAST gets the last deal price so LAST may return a non-meaningful number if a trade has not taken place since terminal start.

Alain Verleyen
Moderator
30755
Alain Verleyen 2014.02.27 11:00  
MaxTrader:

you are getting a little lost....

this will do what you require:

notice I used SYMBOL_BID just to get the current bid price,  SYMBOL_LAST gets the last deal price so LAST may return a non-meaningful number if a trade has not taken place since terminal start.

??? Do you have any evidence of that ?

SYMBOL_LAST gives the price of the last deal on the market you are trading. Nothing to do with your terminal. Of course, it's only significant for centralized market, not for Forex.

Paul Anscombe
3996
Paul Anscombe 2014.02.27 11:02  
angevoyageur:

??? Do you have any evidence of that ?

SYMBOL_LAST gives the price of the last deal on the market you are trading. Nothing to do with your terminal. Of course, it's only significant for centralized market, not for Forex.

from the MT5 documentation..   "It may well be that not a single quote has appeared yet since the terminal is connected to a trading account. In such a case, the requested value will be indefinite."

https://www.mql5.com/en/docs/marketinformation/symbolinfodouble 

Documentation on MQL5: Market Info / SymbolInfoDouble
Documentation on MQL5: Market Info / SymbolInfoDouble
  • www.mql5.com
Market Info / SymbolInfoDouble - Documentation on MQL5
Alain Verleyen
Moderator
30755
Alain Verleyen 2014.02.27 11:03  
MaxTrader:
from the MT5 documentation..   "It may well be that not a single quote has appeared yet since the terminal is connected to a trading account. In such a case, the requested value will be indefinite."
Can you provide a link when you quote documentation please.
Paul Anscombe
3996
Paul Anscombe 2014.02.27 11:04  
angevoyageur:
Can you provide a link when you quote documentation please.

done

but on second read I think that statement actually applies to the quotes not the deals, either way at least he now has the correct line of code to do as he wishes. 

Alain Verleyen
Moderator
30755
Alain Verleyen 2014.02.27 11:13  
MaxTrader:
done

Thank you.

However you mixed different thing. You can be right that "SYMBOL_LAST may return a non-meaningful number", but it's not because "a trade has not taken place since terminal start", but because "not a single quote has appeared yet since the terminal is connected".

So to answer the question of the OP, the best solution is :

MqlTick tick;
double last=0;

if(SymbolInfoTick(_Symbol,tick))
   last=tick.last;

as your link to documentation say :

It is recommended to use SymbolInfoTick() if the function is used for getting information about the last tick.

To add comments, please log in or register