Skip to main content
Version: 2.0

No.2: Day trading for different market sessions

Description

You can find an example for the Custom Expert Advisor on this page. If you still need to become familiar with the MetaTrader strategy tester and the Custom Expert Advisor, please begin with the Getting Started article first.

The detailed explanation of the entire configuration process goes beyond the scope of this article. Therefore, all the necessary configuration files are also available for download. These can be found in the Chart example and profile folder download section. However, a brief explanation and the defining input parameters of each trading module in this system is provided.

Day trading is a prevalent style of trading with a multitude of strategies. One such strategy often employed is session trading. This strategy involves tailoring trading activities to the typical market hours of a specific region, rather than using the same strategy throughout the day. For instance, the trading day usually begins with the Tokyo market hours, followed by the London session, and finally, the New York session commences. Some of these sessions may overlap.

Each session has its unique characteristics, volatility, and typical economic indicators. This example demonstrates three independent trading modules, each employing a distinct strategy. Module 1 (London session) utilizes a strategy based on the Relative Strength Index (RSI), Module 2 (New York session) employs a news event-based strategy, and Module 3 (Tokyo session) uses a strategy based on Bollinger Bands.

Modules 1 and 2 employ a risk ratio-based take profit and average true range stop loss (ATRS) trailing method, while Module 3 uses a based market trailing method.

Please note that this is not a plug-and-play trading system. A trading system needs suitable adjustments, fine-tuning to the timeframe and symbol, and thorough backward and forward testing. Therefore, providing fully working trading strategies as ready-to-use examples is impossible. However, this example could serve as a foundation for your systems.

Individual trading modules

This section provides an overview of how each trading module is configured and what the trading behavior looks like. It can aid in understanding the individual signals generated by each trading module. As previously mentioned, the entire trading system in this example comprises multiple trading modules. Each module operates independently but shares the same resources, ensuring that indicators or oscillators don't need to be recalculated numerous times. This approach conserves the resources required to execute the overall trading system.

EAM_I1.set, London session

When each trading module is executed individually, you'll notice that module no. 1 only covers the time range for the London session.

Custom expert advisor example chart 0, Day trading for different market sessions, London session.png

This trading module was created with the Expert Advisor Builder. The required input parameters for this trading module are as follows.

Input variable within MetaTrader
(Identifier in SET file)
Example valueUser manual chapters
> (OUF) Idea output description (max 63 characters)
(IN_strOufIdeaOutputDescription)
London sessionOutput Folder
> (ISL) ATRS factor
(IN_dIslAtrsFactor)
1.5Initial Stop Loss
> (SLT) ATRS multiplier
(IN_dSltAtrsMultiplier)
1.5Stop Loss Trailing
> (ITP) Risk ratio
(IN_dItpRiskRatio)
0.8Initial Take Profit
> (TIM) Trading hours (A-B;C;D-E)
(IN_strTimTradingHours)
10-18Timing
> (TIM) Visualize timing
(IN_enmTimVisualizeTiming)
OFF
> (OSA1) CONF, Signal in use
(IN_enmOsa1SignalInUse)
ONConfiguration
Available Oscillators and Default Values
Example
> (OSA1) CONF, Selection
(IN_enmOsa1Selection)
RSI - Relative Strength Index
> (OSA1) COND, Value limit condition
(IN_enmOsa1ValueCondition)
SMALLER LIMIT 1
> (OSA1) COND, Value limit 1
(IN_dOsa1ValueLimit1)
30.0

EAM_I2.set, New York session

Further, module no. 2 only covers the time range for the New York session.

Custom expert advisor example chart 2, Day trading for different market sessions, New York session.png

This trading module was created with the Expert Advisor Builder. The required input parameters for this trading module are as follows.

Input variable within MetaTrader
(Identifier in SET file)
Example valueUser manual chapters
> (OUF) Idea output description (max 63 characters)
(IN_strOufIdeaOutputDescription)
New York sessionOutput Folder
> (ORM) Operation
(IN_enmOrmOperation)
SHORTOrder Manager
> (ISL) ATRS factor
(IN_dIslAtrsFactor)
1.5Initial Stop Loss
> (SLT) A Type
(IN_enmSltAType)
PARABOLIC SARStop Loss Trailing
> (SLT) PSAR step
(IN_dSltPsarStep)
0.06
> (SLT) PSAR maximum
(IN_dSltPsarMaximum)
0.6Stop Loss Trailing
> (TIM) Trading hours (A-B;C;D-E)
(IN_strTimTradingHours)
14-22Timing
> (TIM) Visualize timing
(IN_enmTimVisualizeTiming)
OFF
> (EVT) Signal in use
(IN_enmEvtSignalInUse)
ONEvents
> (EVT) Draw chart
(IN_enmEvtDrawChart)
OFF
> (EVT) Pre signal time
(IN_nEvtPreSignalTime)
600
> (EVT) Post signal time
(IN_nEvtPostSignalTime)
600
> (EVT) Region ALL
(IN_enmEvtRegionAll)
OFF
> (EVT) Region AUD
(IN_enmEvtRegionAud)
OFF
> (EVT) Region BRL
(IN_enmEvtRegionBrl)
OFF
> (EVT) Region CAD
(IN_enmEvtRegionCad)
OFF
> (EVT) Region CHF
(IN_enmEvtRegionChf)
OFF
> (EVT) Region CNY
(IN_enmEvtRegionCny)
OFF
> (EVT) Region GBP
(IN_enmEvtRegionGbp)
OFF
> (EVT) Region HKD
(IN_enmEvtRegionHkd)
OFF
> (EVT) Region INR
(IN_enmEvtRegionInr)
OFF
> (EVT) Region JPY
(IN_enmEvtRegionJpy)
OFF
> (EVT) Region KRW
(IN_enmEvtRegionKrw)
OFF
> (EVT) Region MXN
(IN_enmEvtRegionMxn)
OFF
> (EVT) Region NOK
(IN_enmEvtRegionNok)
OFF
> (EVT) Region NZD
(IN_enmEvtRegionNzd)
OFF
> (EVT) Region SEK
(IN_enmEvtRegionSek)
OFF
> (EVT) Region SGD
(IN_enmEvtRegionSgd)
OFF
> (EVT) Region USD
(IN_enmEvtRegionUsd)
OFF
> (EVT) Region ZAR
(IN_enmEvtRegionZar)
OFF
> (EVT) Importance undefined
(IN_enmEvtImportanceUndefined)
OFF
> (EVT) Importance low
(IN_enmEvtImportanceLow)
OFF
> (EVT) Impact undefined
(IN_enmEvtImpactUndefined)
OFF
> (EVT) Impact positive
(IN_enmEvtImpactPositive)
OFF

EAM_I3.set, Tokyo session

Finally, module no. 3 only covers the time range for the Tokyo session.

Custom expert advisor example chart 3, Day trading for different market sessions, Tokio session.png

This trading module was created with the Expert Advisor Builder. The required input parameters for this trading module are as follows.

Input variable within MetaTrader
(Identifier in SET file)
Example valueUser manual chapters
> (OUF) Idea output description (max 63 characters)
(IN_strOufIdeaOutputDescription)
Tokyo sessionOutput Folder
> (SLT) A Type
(IN_enmSltAType)
MARKETStop Loss Trailing
> (ITP) Risk ratio
(IN_dItpRiskRatio)
1.0Initial Take Profit
> (TIM) Trading hours (A-B;C;D-E)
(IN_strTimTradingHours)
0-9Timing
> (TIM) Visualize timing
(IN_enmTimVisualizeTiming)
OFF
> (INA1) CONF, Signal in use
(IN_enmIna1SignalInUse)
ONConfiguration
Available Indicators and Default Values
Example
> (INA1) CONF, Selection
(IN_enmIna1Selection)
BB - Bollinger Bands
> (INA1) CONF, Line index
(IN_nIna1LineIndex)
1
> (INA2) CONF, Signal in use
(IN_enmIna2SignalInUse)
ON
> (INA2) CONF, Selection
(IN_enmIna2Selection)
SMA - Simple Moving Average
> (INB) CONF, Signal in use
(IN_enmInbSignalInUse)
ON
> (INB) COND, Relation 1 INB1 to INB2
(IN_enmInbRelation1)
VALUE 1 CROSS VALUE 2
> (INB1) CONF, Signal in use
(IN_enmInb1SignalInUse)
ON
> (INB1) CONF, Selection
(IN_enmInb1Selection)
BB - Bollinger Bands
> (INB1) CONF, Line index
(IN_nInb1LineIndex)
2
> (INB2) CONF, Signal in use
(IN_enmInb2SignalInUse)
ON
> (INB2) CONF, Selection
(IN_enmInb2Selection)
PRICE - Price directly from series

Chart example and profile folder download

As a result of combining all three trading modules, the chart will generate signals and trade, as shown in the following picture.

Custom expert advisor example chart 4, Day trading for different market sessions, All modules combined.png
tip

To reproduce this example, you can also download the zip package cea_example_2_v_2_0.zip containing the entire profile folder.

In addition to the trading module SET files, the Custom Expert Advisor requires further input information, which defines the trading modules used for the trading system and the current trading stage.

The information about which trading modules are in use is defined in the System.txt file. This standard text file can be edited with any text editor. Please ensure that the existing format is maintained and lines are only added or removed. A helpful feature is that this can be done even when the Custom Expert Advisor is active.

/cea_example_2/System/System.txt
Please ensure data is in format <MODULE_NAME>.
EAM_I1
EAM_I2
EAM_I3

Since there may be a need to turn off trading modules, a second text file-based input, which defines the trading state, is required. The code block below shows what this file (Condition.txt) looks like for the example provided in this article.

/cea_example_2/Condition/Condition.txt
Please ensure data is in format <MODULE_NAME> <MODULE_STATE> where MODULE_STATE can be ENABLED, DISABLED_WITHOUT_CLOSING or DISABLED_WITH_CLOSING for each module!
EAM_I1 ENABLED
EAM_I2 ENABLED
EAM_I3 ENABLED

Please remember not to alter the basic file formatting. Like the system file, the condition file can also be adapted while the Custom Expert Advisor is active. The trading system will adjust accordingly whenever a file change is detected. This allows for modifying active trading systems while preserving previous inspector values.