Code Library / Trade Management
Session Time Filter
Trade only during specific market sessions.
Language: MQL4 · Category: Trade Management · Tags: session filter, London, New York, MQL4
Source code
bool InSession(int s){
int h=TimeHour(TimeCurrent());
if(s==0) return h>=8&&h<16;
if(s==1) return h>=13&&h<21;
if(s==2) return h>=0&&h<8;
return true;
}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.