Download MetaTrader 5

do not trade if spread is higher as max spread?

To add comments, please log in or register
fulltilt
384
fulltilt  

is this working?

extern double MaxSpread = 5.0;

Spread = (Ask-Bid)*10000;
if(Spread >= MaxSpread) { return(0);}
qjol
3243
qjol  
MarketInfo(Symbol(), MODE_SPREAD)
fulltilt
384
fulltilt  

thanks,

you mean:

extern double MaxSpread = 4;

Spread = MarketInfo(Symbol(), MODE_SPREAD);
if(Spread >= MaxSpread) { return(0);}
JC
1515
JC  
fulltilt:

you mean: [...]

There are problems with both your routes.

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.
qjol
3243
qjol  
u need to adjust for 4/5 digit broker
qjol
3243
qjol  
jjc:

[...] 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:

fulltilt
384
fulltilt  
hm, could you please post a example, I'm just a beginner in mq4 coding:-)
JC
1515
JC  
qjol:
[....]
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.
qjol
3243
qjol  
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.
hoopppssss, my mistake, i apologize
JC
1515
JC  
fulltilt:
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

fulltilt
384
fulltilt  

thank you very much,

this EA works for eurusd only, but now i know to use a spreadfilter :-)

12
To add comments, please log in or register