MarketInfo(Symbol(), MODE_SPREAD)
thanks,
you mean:
extern double MaxSpread = 4; Spread = MarketInfo(Symbol(), MODE_SPREAD); if(Spread >= MaxSpread) { return(0);}
you mean: [...]
Taking the later one first, MODE_SPREAD is a multiple of MODE_POINT. Therefore, if the broker quotes prices to 5DP, e.g. 1.23456, then if MODE_SPREAD is 8 then it means that the spread is 0.00008, not 0.0008. Putting it another way, MODE_SPREAD does not necessarily return a value measured in what you would consider to be a "pip".
The problem with your first route is that it doesn't work on JPY (plus things like HUF). For example, if the USDJPY spread is from 77.673 to 77.681, then multiplying the difference by 10000 is going to give a result of 80 pips, not 0.8 pips.
There are lots of previous discussions on this forum about how to handle values in pips.
[...] if the broker quotes prices to 5DP, e.g. 1.23456, then if MODE_SPREAD is 4 then it means that the spread is 0.00004, not 0.0004.
wrong 40 not 0.00004
try
Alert(MarketInfo(Symbol(), MODE_SPREAD));
sorry jjc:
[....]
Don't understand what you're trying to say. For example, on an Alpari UK build right now, with bid/ask of 1.36419/1.36423, then the spread in price terms is 0.00004 and MODE_SPREAD is reported as 4. Most people would call that 0.4 pips, but that's a semi-arbitrary convention.
hm, could you please post a example, I'm just a beginner in mq4 coding:-)
If you want something simple which will work in most scenarios, then you could change your first example to something like the following:
if (StringFind(Symbol(), "JPY") >= 0) { Spread = (Ask-Bid)*100; } else { Spread = (Ask-Bid)*10000; }
In other words, if the symbol name contains "JPY" (e.g. USDJPY, EURJPY), then multiply the price difference by 100 rather than 10000.
An alternative, which produces better results for things like XAUUSD, would be something like:
switch (MarketInfo(Symbol(), MODE_DIGITS)) { case 3: case 5: Spread = MarketInfo(Symbol(), MODE_SPREAD) / 10; break; default: Spread = MarketInfo(Symbol(), MODE_SPREAD); break; }
In other words, use MODE_SPREAD, but cater for the fact that most people regard a pip as being 0.0001 or 0.01, and MODE_SPREAD therefore needs to be adjusted if the symbol is quoted to 3DP or 5DP.
For further information, see topics such as https://www.mql5.com/en/forum/126450

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
is this working?