spread value

 

Hi, one question,

if I have the spread value in these terms

int spread_value = MarketInfo("EURUSD",MODE_SPREAD);

which is the most correct way to convert

5 into 0.00005 for example?

 
florenceale: 5 into 0.00005 for example?

You don't want to convert a spread of 5 points into 0.00005, breaks on JPY pairs. Multiply by _Point to get 0.005 or 0.00005.

 

I did exactly like this, but the result is 0...

 
florenceale:I did exactly like this, but the result is 0...
  1. You should only check the spread after the first tick has arrived and not during the OnInit() cycle.
  2. Make sure you are using the correct Symbol name as some brokers add prefixes and suffixes to the name. It might be "EURUSD.m" instead for example. So, if referring to the chart symbol, use the the variable _Symbol or the function Symbol() instead.
  3. If checking for another symbol, which is not the chart symbol, then make sure that the symbol is available in the "Market Watch" or handle 4066/4073 errors.

The "MarketInfo( _Symbol, MODE_SPREAD )" will always return a value in points, not in price delta. So convert it as follows:

int    intMarketSpreadPoints = MarketInfo( _Symbol, MODE_SPREAD ); // e.g. 15 points
double dblMarketSpreadPrice  = intMarketSpreadPoints * _Point;     // e.g. 0.00015 price delta
double dblCurrentSpreadPrice = Ask - Bid;                          // e.g. 0.00015 price delta ( Alternative Method )

If using the function to check the spread of another symbol which is not the chart symbol, a different approach may be needed:

string strSymbol             = "XAUUSD.m";
int    intSymbolSpreadPoints = MarketInfo( strSymbol, MODE_SPREAD );       // e.g. 25 points
double dblSymbolPointSize    = MarketInfo( strSymbol, MODE_POINT  );       // e.g. 0.01 price delta
double dblSymbolSpreadPrice  = intSymbolSpreadPoints * dblSymbolPointSize; // e.g. 0.25 price delta
 

Or you can also use the MqlTick...

   MqlTick tick;
   SymbolInfoTick(_Symbol,tick);
   double spread = tick.ask - tick.bid;
Reason: