Download MetaTrader 5

Spread confusion

To add comments, please log in or register
Looking for like-minded people? You will find lots of them on the Forum!
Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2014.04.04 19:19 

Hello,

I am confused related how to use Spread. In Docs stated:

Spread

Gets the element of the Spread timeseries by index.

double  Spread(
   int    ind         // index
   )

Parameters

ind

[in]  Element index.

Returned value

If successful, it returns the numerical value of the Spread timeseries element with specified index, otherwise it returns EMPTY_VALUE.

Note

The EMPTY_VALUE is returned in two cases:

1.Timeseries is not used (the corresponding bit is not set).

2. Element index is out of range.


 

So, I want to use it in an EA like this: 

if(bid>last.price+Spread()) .....other statements 

But I do not understand who is and how to use index.

Thanks in advance for reply! 

Rodrigo Malacarne
Moderator
9904
Rodrigo Malacarne 2014.04.05 00:28  
tenlau:

So, I want to use it in an EA like this: 

if(bid>last.price+Spread()) .....other statements  

If you are able to get the bid price, I suppose you can also get the ask price, right?

So, why don't you define the spread simply as the difference between ask and bid prices?

Something like: 

double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
double spread=ask-bid;
Alain Verleyen
Moderator
30752
Alain Verleyen 2014.04.05 00:33  
tenlau:

Hello,

I am confused related how to use Spread. In Docs stated:

...

So, I want to use it in an EA like this: 

if(bid>last.price+Spread()) .....other statements 

But I do not understand who is and how to use index.

Thanks in advance for reply! 

Please provide a link when you quote documentation.

About how to get the spread, see https://www.mql5.com/en/forum/17858/page2#comment_731798

Laurentiu Sorin Tene
692
Laurentiu Sorin Tene 2014.04.08 12:12  

Thank you both!

@angevoyageur From now on I'll provide links 

To add comments, please log in or register