Issue with MarketInfo(NULL,MODE_SPREAD) on live account

double Spread = MarketInfo(NULL,MODE_SPREAD) / 100000;
double COpen = iOpen(NULL,240,0);
double P2Low = iLow(NULL,240,2);

double BuySL = P2Low - 0.0001; 
double BuySLDist = COpen + Spread - BuySL;
double BuyTP = COpen + Spread + BuySLDist * 6;

Above snippet works fine in backtest, but first trade on live and BuyTP is short by exactly 6 * Spread + slippage. The shortage from slippage (if any) makes perfect sense, but any idea why Spread seems to have returned 0 in this instance? (Average spread at this broker is .4 pips and this was during Asia so really doubt spread was 0 when trade occurred).

‌Consensus seems to be use symbol() instead of NULL, but don’t think this is issue.

‌Can easily rectify with an order modify after trade entry and will do this to account for slippage, but would like to fix spread issue at source.

‌Any help would be much appreciated.

‌Spread alternatives:

double Spread = Ask - Bid; 
// Or
double Spread = MarketInfo( _Symbol, MODE_SPREAD ) * _Point; // MarketInfo Spread is in Points
// Or
double Spread = SymbolInfoInteger( _Symbol, SYMBOL_SPREAD ) * _Point; // Compatible with both MQL4 and MQL5

And, don’t Hard-Code your constants:


   COpen = iOpen( NULL, PERIOD_H4, 0 ),
   P2Low = iLow(  NULL, PERIOD_H4, 2 );

W‌hy do you divide with 100000? It is already in points.

double Spread = MarketInfo(NULL,MODE_SPREAD) / 100000;

That is exactly the reason! The OP is converting the “points” into “price delta”. That is why in my example, I showed that the correct way is by using " * _Point " instead of " / 100000", because different symbols have different Point sizes.

The 240 was mentioned above. Don’t hard code constants.
MT5 doesn’t have a MarketInfo so why did you post in the forum / MT5 Expert Advisors section instead of the MT4 section? I Assume you meant MT4.
You can only use NULL in those calls where the documentation specifically mentions it and those are mostly to substitution for _Symbol. MI is not one of those. Don’t use NULL (except for pointers where you explicitly check for it.)
Spread returns the number of points, usually in the 5 - 50 range (0.5-5.0 pips on a 5 digit broker.) If you want the number of points, don’t divide.
If you want the spread as a price change, multiply by _Point (or subtract Bid from Ask.) Don’t hard code constants (1/100K) is _Point for non-JPY/5 digit broker pairs, but your code fails on Yen pairs or 4 digit brokers.
You must adjust SL, TP, and slippage for 4/5 digit brokers and for JPY pairs.

double   pip          = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
int      pipDigits    = (int)MathLog10(pip/_Point);
int      pipsToPoints = int(pip / _Point);
int      slippage     = 3 * pipsToPoints;

Just as an extra note, special case is not just the JPY but also the RUB (and some metals, CFDs and others).

I am in forex since 2005.

See my products, they are the greatest.
Note that I am always updating them.

For MT4 Experts programming/development, please apply to the link below:

My library/codes (examples):