please edit your post -
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
This is a good code. Do you have any problems with it?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
My goal is to create some code that I can add to me EA. I would like the ability to have my EA trade the Asian session, the London, Session and the New York Session. Sometimes I might only want it to trade during the London or New York Sessions. I am very new to coding. If anyone could take a look at my code and provide me with feedback. I am open to all suggestions. I will paste some of what I have so far.
// trading sessions
enum TradingSession {
SESSION_NONE,
SESSION_ASIAN,
SESSION_LONDON,
SESSION_NEWYORK
};
// Input parameters to select trading sessions
input bool Trade_AsianSession = true; // Enable trading during the Asian session
input bool Trade_LondonSession = true; // Enable trading during the London session
input bool Trade_NewYorkSession = true; // Enable trading during the New York session
TradingSession GetCurrentTradingSession() {
datetime now = TimeCurrent();
int hour = TimeHour(now);
if ((hour >= 0 && hour < 9) || (hour == 23)) {
return SESSION_ASIAN; // Asian session: 23:00 - 09:00
} else if (hour >= 9 && hour < 17) {
return SESSION_LONDON; // London session: 09:00 - 17:00
} else if (hour >= 17 && hour < 23) {
return SESSION_NEWYORK; // New York session: 17:00 - 23:00
}
return SESSION_NONE; // No active session
}
bool IsTradingAllowed() {
TradingSession currentSession = GetCurrentTradingSession();
if (currentSession == SESSION_ASIAN && Trade_AsianSession) {
return true;
} else if (currentSession == SESSION_LONDON && Trade_LondonSession) {
return true;
} else if (currentSession == SESSION_NEWYORK && Trade_NewYorkSession) {
return true;
}
return false;
}