Download MetaTrader 5
To add comments, please log in or register
Do you have Mac OS? Find out how to install MetaTrader on it!
Automated-Trading
Admin
98900
Automated-Trading 2011.01.13 14:32 

MQL5 Wizard - Trade Signals Based on Crossover of Two EMA with intraday time filter:

MQL5 Wizard allows to create the code of Expert Advisors automatically. See Creating Ready-Made Expert Advisors in MQL5 Wizard for the details.

The trading signals of the strategy, based on two moving averages are considered in MQL5 Wizard - Trade Signals Based on Crossover of Two Exponentially Smoothed Moving Averages. The moving averages are effective when trend, in other cases they provide many false signals. One of the ways to improve the strategy is the use of the time filters (for example, open new positions when European session of FOREX).

Here we will consider the strategy based on crossover of two exponentially smoothed Moving Averages (fast EMA and slow EMA) with intraday time filter. The strategy called "Signals based on crossover of two EMA with intraday time filter" (when creating EA automatically in MQL5 Wizard).

Trade signals:

  • Open long position: the Fast EMA crossovers upward the slow EMA and intraday time filter conditions are satisfied.
  • Open short position: the Fast EMA crossovers downward the slow EMA and intraday time filter conditions are satisfied.

This strategy is implemented in CSignal2EMA_ITF class of the Trading Strategy classes of MQL5 Standard Library (located in MQL5\Include\Expert\Signal\Signal2EMA-ITF.mqh).

The filtration of signals, based on specified time periods is implemented in CSignalITF class. As example of its use, we will consider the CSignal2EMA_ITF class (it contains the CSignalITF class object).

The trading system is based on pending orders, the price levels are calculated depending on values of moving average, the ATR units (Average True Range) are used.

Figure 1. Trade signals, based on crossover of two EMA with intraday time filter

Figure 4. Testing Results of the Expert Advisor with trading signals, based on crossover of two EMA with time filter (BadHoursofDay=16777152)

Author: MetaQuotes Software Corp.


muller
559
muller 2011.01.13 17:37  

Good article but i beg some explanations:

****  to open positions only from 0:00 till 5:59. It can be done by setting the value of BadHoursOfDay=16777152=111111111111111111000000b.  All other trade hours are "bad", so it's better to prohibit the opening of new positions from 6:00 till end of the day. ****

Some details here are needed:

- how to calculate/define this value of " 16777152", how to define it for an other "opening/closing" or only "opening" time ?

- how to take decisions on multiple ITFs , for examples: TOKYO/LONDON/NY opening times ?

Automated-Trading
Admin
98900
Automated-Trading 2011.01.13 18:08  
razoff:

Some details here are needed:

- how to calculate/define this value of " 16777152", how to define it for an other "opening/closing" or only "opening" time ?

In this example the filter on new position opening is implemented. (It's assumed that they will be closed by SL/TP).

The binary representation of 16777152 is:

In our case we used the filter by hours, the "bad" hours have marked with corresponding bits=1. The same can be done with BadMinutesOfHour.

You can use calc.exe to convert binary values:


- how to take decisions on multiple ITFs , for examples: TOKYO/LONDON/NY opening times ?

If you want to use 3 separate filters (TOKYO,LONDON,NY), you can add additional instances of  CSignalITF class (in our case there is an only one m_time_filter) into your signals class.

Stephen Njuki
5179
Stephen Njuki 2011.01.13 18:39  
How would you optimize the time filter in strategy tester?

Automated-Trading
Admin
98900
Automated-Trading 2011.01.13 18:50  
ssn:
How would you optimize the time filter in strategy tester?

The best time filter can be found using the optimization of the BadHoursOfDay input parameter in Strategy Tester. You can specify starting and ending values of the parameters and it will find the best hours, because of the use of the genetic optimization algorithm it doen't need much time, as it seems.

The second way is to check the time of loss deals manually and "mark" them in bits of BadHoursOfDay parameter.

In fact, it allows to tune your stategy and take into account some "logical" reasons of trade idea. For example, the oscillators works better when flat, the reason of flat may be the absence of news, the session/currency pair properties, etc.

muller
559
muller 2011.01.13 19:13  
Automated-Trading:

In this example the filter on new position opening is implemented. (It's assumed that they will be closed by SL/TP).

The binary representation of 16777152 is:

In our case we used the filter by hours, the "bad" hours have marked with corresponding bits=1. The same can be done with BadMinutesOfHour.

You can use calc.exe to convert binary values:


If you want to use 3 separate filters (TOKYO,LONDON,NY), you can add additional instances of  CSignalITF class (in our case there is an only one m_time_filter) into your signals class.

Thanks for this howto, but what a headache :( Cant we simply use something more user friendly like StartHour/EndHour/StartMinute/EndMinute as we can do with MT4 ? Why using this so complicated binary mode ?
Automated-Trading
Admin
98900
Automated-Trading 2011.01.13 19:29  
razoff:
Thanks for this howto, but what a headache :( Cant we simply use something more user friendly like StartHour/EndHour/StartMinute/EndMinute as we can do with MT4 ? Why using this so complicated binary mode ?

The binary representation of parameters has some significant advantages. For example, you can explore the parameter space in Strategy Tester (start from 0, end 16777215, step 1). Try it.

After finding the best hours you can explore the days. But note, that time filters are effective for lower timeframes (H1 and lower).

If you need more "friendly" way, you can write your own class of trade signals (see MQL5 Wizard: How to Create a Module of Trading Signals).

muller
559
muller 2011.01.13 19:49  
Automated-Trading:

The binary representation of parameters has some significant advantages. For example, you can explore the parameter space in Strategy Tester (start from 0, end 16777215, step 1). Try it.

After finding the best hours you can explore the days. But note, that time filters are effective for lower timeframes (H1 and lower).

If you need more "friendly" way, you can write your own class of trade signals (see MQL5 Wizard: How to Create a Module of Trading Signals).

Ok, i've to understand this binary thing first; if calc.exe or any other scientific app can "convert" binary, i need to find how to get binary in a simple and easy way(not everyone is Einstein: for example in the explanation's example, why starting from 23 to end to 0 to calculate that binary ? Then how to get binary for other timeframes like Days (Saturday to Monday ?), Minute (59 to 0 ?))
Stephen Njuki
5179
Stephen Njuki 2011.01.19 20:23  
Automated-Trading:

The best time filter can be found using the optimization of the BadHoursOfDay input parameter in Strategy Tester. You can specify starting and ending values of the parameters and it will find the best hours, because of the use of the genetic optimization algorithm it doen't need much time, as it seems.

The second way is to check the time of loss deals manually and "mark" them in bits of BadHoursOfDay parameter.

In fact, it allows to tune your stategy and take into account some "logical" reasons of trade idea. For example, the oscillators works better when flat, the reason of flat may be the absence of news, the session/currency pair properties, etc.

Okay please correct me if am wrong but supposing I want to filter bad minutes does this mean I need to sift through 1152921504606846975 options?
Victor Kirillin
491
Victor Kirillin 2011.01.24 12:29  
ssn:
Okay please correct me if am wrong but supposing I want to filter bad minutes does this mean I need to sift through 1152921504606846975 options?
That is correct.
/
To add comments, please log in or register