Code Library / Trade Management
Spread Monitor
Filter trades when spread is too high.
Language: MQL5 · Category: Trade Management · Tags: spread, filter, MQL5
Source code
input double MaxSp=3.0;
double SpreadPips(){
double s=(SymbolInfoDouble(_Symbol,SYMBOL_ASK)-SymbolInfoDouble(_Symbol,SYMBOL_BID))/SymbolInfoDouble(_Symbol,SYMBOL_POINT);
if(SymbolInfoInteger(_Symbol,SYMBOL_DIGITS)==5)s/=10;
return s;
}
bool SpreadOK(){return SpreadPips()<=MaxSp;}How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL5 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.