MQL4 Get Current Price

In this article you can learn how to get the current price using the MQL4 language. When programming an Indicator or an Expert Advisor it is often necessary to get the current price via MQL language. MQL4 Get Current Price in some very simple ways and in this article you are going to see some code to achieve this. MQL4 Get Current Price

Get Current Price with MQL4

Getting the current price of a pair or another instrument is one of the frequent tasks to perform when coding a new indicator or expert advisor. The operation itself is very easy and we are going to examine the code to do that. Before coding it is first necessary to establish what price we need to extract. Each instrument has in fact two prices: bid and ask. Bid is the price to sell an instrument while Ask is the price to pay to buy it. When in Metatrader 4 we see the current price line on a chart that is by default the Bid price.

MQL4 Get Current Price Using MarketInfo()

The following code uses the native Metatrader 4 function MarketInfo()  to get the price of the current instrument. The values of Bid and Ask are then saved into variables and presented with a text box. You can test the code simply creating a new script and copying and pasting it MarketInfo()  is a very powerful function that can return many information about an instrument. In the way we used it we just asked to retrieve the bid and ask price for the current instrument.

MQL4 Get Current Price with Close()

There is an alternative way of retrieving the current price but in this case we will only be able to get the current Bid price via MQL. This alternative method is using the function Close() or iClose(). Close is a function that returns the Close price (Bid) of the selected candle, where the selection is done via a index. Close[0]  will return the Close price of the candle at index 0 which is the one in formation. Using this function we can have

Conclusion On MQL4 Get Current Price

As you can see it is not hard to get the current price via MQL coding, it only requires a few lines of code. The MQL language already includes tools to help achieving it and it is just a matter of finding and using it.

If you want to save hours of research and coding and you want to see some professional code check this out! You can use it to build your own EA!

We use cookies to ensure that we give you the best experience on our website.