Optimizing Your EA to Trade on Certain Weekdays

(This post will be interesting only to the MQL coders.)
One of the most overlooked parameters of the Forex expert advisor that can be used in optimization of the trading results is the set of weekdays for the EA to trade on. Different strategies are good under different market conditions. And the market conditions tend to vary greatly depending on the current day of the week. Of course, sometimes Monday can show higher volatility than Wednesday or Thursday, but statistical trends are quite definite here. That’s why I recommend optimizing your expert advisor to trade only on certain days of the week. Especially, when it can be done easily in MetaTrader platform.
First, let’s limit the maximum amount of trading days to 5 — Monday, Tuesday, Wednesday, Thursday, Friday. It’s much easier to build and optimize an EA without the small early Sunday’s or late Saturday’s sessions that occur on the MetaTrader servers with the timezones too far from GMT.
Second, let’s presume that you already have a nice EA that performs some position opening and closing. It’s a good idea to limit only position opening on certain weekdays, closing should be performed even on the “restricted” days.
The best way to start is to declare a variable (as an input parameter, of course) for each day of the week. Although it’d more logical to make them Boolean (bool), in practice it’s better to work with them when they are either “0” or “1” so, it’s more prudent to declare them as integer (int):

input int Monday    = 1;
input int Tuesday   = 1;
input int Wednesday = 1;
input int Thursday  = 1;
input int Friday    = 1;

The default values are “1”, which means that the EA will trade on all weekdays.
If we want to check current day of the week in MQL5, we’ll have to start by getting a time structure with the current time and date:

MqlDateTime dt;
TimeToStruct(TimeCurrent(), dt);

Now we can time our position entry function with the code similar to this:

if ((dt.day_of_week == 1) && (Monday) ||
    (dt.day_of_week == 2) && (Tuesday) ||
    (dt.day_of_week == 3) && (Wednesday) ||
    (dt.day_of_week == 4) && (Thursday) ||
    (dt.day_of_week == 5) && (Friday))
    {
        Entry();
    }

Now we can either test it manually or use the MetaTrader 5 strategy tester to backtest the EA and try all 32 possible combinations of the weekdays. In the input settings of the strategy tester we check all 5 days and for all of them set Start to “0”, Step to “1” and Stop to “1”. As you see, it results in 32 combinations:

Don’t forget that for such optimization you have to choose a rather long period because testing on just one week will lead to nothing good. At least 10 weeks are recommended. Here are the example optimization results of one of my test EAs; the period was 6 months:

The optimization results are sorted by profit. As you see, the best result was when the EA traded only on Mondays and Fridays but it made only 140 trades. Adding Tuesday to them reduces the profit only slightly but it increases the amount of trades, making the result more stable. Adding Thursday also reduces the profit by a minimal amount and increases total trades significantly. Other results aren’t that interesting. To conclude, we can say that excluding Wednesday from the trading weekdays is an optimal decision.
Now you can use this technique to improve your own expert advisor or to optimize your manual trading strategy (if you can implement a test EA out of it, of course).

If you have any comments or questions regarding weekday trading optimization for MetaTrader expert advisors, please, reply using the form below.

Leave a Reply

Your email address will not be published. Required fields are marked *

− seven = two