Code Library / Session/Time
MQL4 Session Filter
Filter trades by trading session for optimal liquidity.
Language: MQL4 · Category: Session/Time · Tags: session filter, MQL4, London, New York, Asian
Source code
bool InSession(int type) {
int h=TimeHour(TimeCurrent());
switch(type) {
case 0: return h>=0&&h<9; // Asian
case 1: return h>=7&&h<16; // London
case 2: return h>=13&&h<22; // NY
case 3: return h>=13&&h<16; // Overlap
}
return false;
}
bool HighLiquidity() { return InSession(1)||InSession(2); }How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL4 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.