MQL4 Get Spread Value

The spread can be in many cases the reason why a strategy is not profitable. As a trader we always want to trade when this is low and we might pass on opportunities when this is too high, especially when scalping. If you code indicators and expert advisors you want to know how to get the spread value with MQL4 and MQL5 language. In this article you will see how the MQL4 Get Spread Value and relevant code.

Get-Spread-With-MQL4

MQL4 Get Spread Value

Dealing with the spread is something that all traders have to do, you and I included. Let’s start defining the spread and then we can see some code (MQL4 Get Spread Value).

You can also find more info about the spread in this article.

The spread is the difference between the Ask and the Bid price. It is basically the commission that you pay to the broker for the transaction. Depending on the broker and the account, you can have a fixed or variable spread. A fixed spread stays the same (but usually there is some other cost related to the order). A variable spread changes in time. Usually in moments of high volatility the spread increases.

You might think that getting the spread value via MQL4 code involves calculations and so on, but it is not the case.

MQL4 Spread With MarketInfo

With MQL4 we have the function MarketInfo()  that can easily return the current value of the spread.

The following MQL4 code saves the current spread value for the current instrument in a variable and shows it in a messagebox

MarketInfo()  provides many details about the instruments and market and one of these is in fact the spread.

MQL4 And MQL5 Spread With SymbolInfoDouble

With the version upgrade and the new release of Metatrader 5 something changed.

MT5 and MQL5 language does not include the MarketInfo function so the approach is a little different.

In this case to use MQL5 to get the spread you need to use the function SymbolInfoInteger().

SymbolInfoInteger() is available on MQL4 and MQL5 and returns details about the specified instrument.

To return the spread we query SymbolInfoInteger for the property SYMBOL_SPREAD.

The spread returned is in both cases is expressed in points, that depending on your broker can be pips or pipettes.

Download Spread Indicator For Metatrader

If you are looking for an indicator to see the spread on chart and received notifications about it please consider the following

We also talk about disabling the trading when the spread is too high in this article.

Conclusion on MQL4 Get Spread Value

As you can see in the previous code it only takes one line of code, one function, to Get the Spread Value via MQL4 language. The task is very easy and quick to perform.

Please feel free to leave a feedback or Contact Us for anything else.

Leave a Comment