getting the last price of a symbol

 

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);
 
double toto=SymbolInfoDouble("EURUSD",SYMBOL_LAST);
 
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.

 
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.

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

 
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.

 
SYMBOL_LAST and SYMBOL_BID will only give you the same result, why is that?
 
alexclaor:
SYMBOL_LAST and SYMBOL_BID will only give you the same result, why is that?

Please do not double post. Your other topic has been deleted.

 
Keith Watford:

Please do not double post. Your other topic has been deleted.

Hi Keith, Sorry about that. Hope you can help me get the correct SYMBOL_LAST. I already tried different brokers with live account but I still get the same information where the SYMBOL_LAST and SYMBOL_BID are just the same. Hope to hear from you soon :)
Reason: