Skip to main content
Version: 2.0

TIM - Timing

Timing is undeniably a crucial element in trading. It's not just about identifying the right moment to initiate a trade but also discerning when it's best to refrain from trading. Many trading strategies are designed to operate effectively only during specific hours, days, or weeks of the year.

The Expert Advisor Builder provides a feature allowing users to specify when a trading module can open new trades. This timing module functions as a filter. While it doesn't generate trading signals independently, it does regulate the number of trading signals produced by signal generators. Thus, it plays a vital role in managing the frequency and timing of trades. All examples on this page have the timing visualization feature enabled to make things easier to understand. For more information about this feature, please refer to the relevant section.

It's important to note that the example trades are only initiated outside the blocked time ranges (indicated by red and orange areas). However, the management of open trades continues as usual within these time ranges.

Concept diagram

The concept diagram provided below depicts the function block associated with this page.

Concept diagram, Timing.png

Trading seconds, minutes, and hours

To specify the seconds, minutes, and hours a trading module can initiate new trades, refer to the input parameters in the subsequent table.

Input variable within MetaTrader
(Identifier in SET file)
Default valueComment
> (TIM) Trading seconds (A-B;C;D-E)
(IN_strTimTradingSeconds)
0-59The input value has to be in the format A-B;C;D-E with values between 0 and 59.
> (TIM) Trading minutes (A-B;C;D-E)
(IN_strTimTradingMinutes)
0-59The input value has to be in the format A-B;C;D-E with values between 0 and 59.
> (TIM) Trading hours (A-B;C;D-E)
(IN_strTimTradingHours)
0-23The input value has to be in the format A-B;C;D-E with values between 0 and 23.

With text-based input parameters, you define when new trades can be opened. Each input parameter must have at least one time range but can also be configured with multiple time ranges. For instance, a minute selector value of 0-59 implies that trading is permitted at every minute, while a value of 0-30 means that trading is only allowed from the 0th to the 30th minute. To define multiple time ranges, separate them with a semicolon. For example, 1-20;30;40-59 defines three time ranges during which trading is permitted: the 1st to 20th minute, the 30th minute, and the 40th to 59th minute. Consequently, the trading module takes a break for approximately 19 minutes every hour.

All timing input parameters follow the same configuration principle. The trading module can open new trades only if the timing input parameters are met. This means that the input parameters of all trading modules are combined.

The first example series showcases examples with different values for the > (TIM) Trading hours input parameter.

Configuration, Timing, Trading seconds, minutes, and hours, Example charts 1.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_2_v_2_0.zip.

The second example series presents examples with varied values for the > (TIM) Trading minutes input parameter.

Configuration, Timing, Trading seconds, minutes, and hours, Example charts 2.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_3_v_2_0.zip.

The third example demonstrates examples with a combination of different values for the > (TIM) Trading hours and > (TIM) Trading minutes input parameters.

Configuration, Timing, Trading seconds, minutes, and hours, Example charts 3.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_4_v_2_0.zip.

As the last example demonstrates, the trading module only opens trades when the hour and minute timing parameters are met.

Trading days, weeks, and months

To specify the days, weeks, and months a trading module can initiate new trades, refer to the input parameters in the subsequent table.

Input variable within MetaTrader
(Identifier in SET file)
Default valueComment
> (TIM) Trading days (A-B;C;D-E)
(IN_strTimTradingDays)
1-31The input value has to be in the format A-B;C;D-E with values between 1 and 7.
> (TIM) Trading weeks (A-B;C;D-E)
(IN_strTimTradingWeeks)
1-52The input value has to be in the format A-B;C;D-E with values between 1 and 52.
> (TIM) Trading months (A-B;C;D-E)
(IN_strTimTradingMonths)
1-12The input value has to be in the format A-B;C;D-E with values between 1 and 12.

A trading module can open new trades only if the timing input parameters are met. This means that the input parameters of all trading modules are combined. The first example series showcases examples with different values for the > (TIM) Trading days input parameter.

Configuration, Timing, Trading days, weeks, and months, Example charts 1.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_5_v_2_0.zip.

The second series of examples illustrate using the > (TIM) Trading weeks input parameter with various values. This parameter is handy for adjusting to the differing daylight saving times observed in North American and European markets. The two-week periods often lead to irregular behavior in automated trading modules. Therefore, if a module relies on precise timing for signal generation, the simplest solution is to turn off its trading activity for these two weeks.

Configuration, Timing, Trading days, weeks, and months, Example charts 2.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_6_v_2_0.zip.

Trading days of week

Numerous trading strategies are effective only on specific days of the week. For instance, forex trading strategies often capitalize on the market opening on Monday mornings. To restrict trading to particular days of the week, utilize the input parameter below.

Input variable within MetaTrader
(Identifier in SET file)
Default valueComment
> (TIM) Trading days of week (A-B;C;D-E and 0->Sunday)
(IN_strTimTradingDaysOfWeek)
0-6The input value has to be in the format A-B;C;D-E with values between 0 and 6.

This input parameter, like others, can be configured with multiple time ranges, which a semicolon should separate. Each weekday is represented by a number, with 0 for Sunday, 1 for Monday, and so forth. The following examples demonstrate how to restrict a trading module to operate from Monday to Thursday and from Tuesday to Thursday, respectively.

Configuration, Timing, Trading days of week, Example charts.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_7_v_2_0.zip.

Intraday trading mode

In addition to the universally applicable timing input parameters discussed on this page, the Expert Advisor Builder also offers a configuration option for an intraday trading mode. This feature is especially beneficial for scalping and day trading strategies that operate on shorter timeframes, such as M1 - M15. All input parameters associated with this feature are detailed in the table below. The feature comprises three time-based inputs and a toggle to turn the feature on or off. By default, the intraday feature is turned off.

Input variable within MetaTrader
(Identifier in SET file)
Default valueComment
> (TIM) Intraday mode (OFF -> Time ignored)
(IN_enmTimIntradayMode)
OFFNumeric values usable in SET files:
0 - OFF
1 - ON
> (TIM) Start intraday trading (HH:MM:SS)
(IN_strTimStartIntradayTrading)
09:00:00The input value has to be in the format HH:MM:SS.
> (TIM) Stop intraday trading (HH:MM:SS)
(IN_strTimStopIntradayTrading)
18:00:00The input value has to be in the format HH:MM:SS.
> (TIM) Deadline intraday trading (HH:MM:SS or 'OFF')
(IN_strTimDeadlineIntradayTrading)
21:00:00The input value has to be in the format HH:MM:SS or OFF.

To comprehend the input parameters, please refer to the subsequent illustration.

Configuration, Timing, Intraday trading mode, Function principle.png

This illustration elucidates the operational principle of the intraday mode. In brief, each input parameter serves the following purposes:

  • > (TIM) Start intraday trading: This parameter sets the beginning of the time range when new trades can be opened. Existing trades can be maintained outside this time range, but new trades can only be initiated within the period defined by the start and stop time.
  • > (TIM) Stop intraday trading: This parameter marks the end of the time range when new trades can be opened. Like the start parameter, existing trades can be sustained outside this time range, but new trades can only be opened within the trading period defined by the start and stop parameters.
  • > (TIM) Deadline intraday trading: This parameter designates the start of the time range from which open trades are not permitted. Once this deadline is reached, all trades, irrespective of their performance, will be closed. This parameter can be configured to coincide with the swap deadline to evade fees and unexpected market fluctuations overnight.

These three input parameters work together with the timing input parameters discussed in the previous sections. As such, you can define a trading range, for instance, from 09:00:00 to 17:00:00, with a break from 11:00:00 to 14:00:00. The intraday mode is demonstrated in example charts series a) and b) below. As observed, the times when new trades cannot be opened, but existing ones can be maintained are colored orange. The time range during which no trade can be open is colored in red. All trades will be closed at the onset of a red time range, regardless of their performance.

Configuration, Timing, Intraday trading mode, Example charts.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_9_v_2_0.zip.

Trading time visualization

As illustrated in the above example series, the time range during which trading is disabled is highlighted with orange and red areas. This feature is designed for your convenience to simplify the configuration of timing. The timing visualization can be turned off at any time. However, even without graphical visualization, the trading timing ranges remain operational.

Input variable within MetaTrader
(Identifier in SET file)
Default valueComment
> (TIM) Visualize timing
(IN_enmTimVisualizeTiming)
ONNumeric values usable in SET files:
0 - OFF
1 - ON

The subsequent example series showcases some trades with the timing visualization enabled and disabled. As you can easily observe, the trading results of both scenarios are identical.

Configuration, Timing, Trading time visualization, Example charts.png
tip

To reproduce the chart from above, you can download and use the SET file package um_eab_ctim_10_v_2_0.zip.

The timing visualization can also be used to create a trading module that aids manual trading. It can display the time ranges you permit yourself to initiate trades.