Determines the behavior during weekend bars (by default, Friday 20:00 UTC until Sunday 23:00 UTC), outside market hours, and at international business holidays.
0 - trade even during the weekend. For test purposes or for
24/7 traded assets, such as cryptocurrencies.
1 - don't enter trades during the weekend, but generate bars, observe exit limits (stop / takeprofit / trail), and run TMFs when price quotes arrive.
2 - don't begin or end bars during the weekend, but observe exit limits and run TMFs when price quotes arrive (default).
3 - don't begin or end bars, don't observe exit limits, and don't run TMFs during the weekend.
+4 - log off at weekend when there are no weekend bars. Only recommended if the broker API tends to crash when the broker server goes offline.
+8 - don't enter trades outside the
StartMarket and EndMarket time in the selected asset's time
+16 - don't
begin or end bars outside the
StartMarket and EndMarket time in the first asset's
time zone (AssetMarket).
- The weekend period can be set up with the StartWeek and EndWeek variables in the dhhmm format, where d = day number (1 = Monday .. 7 = Sunday), hh = hour (UTC) and mm = minute. At the default values (StartWeek = 72300, EndWeek = 52000) the week starts Sunday 23:00 UTC and ends Friday 20:00 UTC. Markets close later, but it is normally not recommended to open trades in the late Friday hours.
- At Weekend = 3 the tick function
is still executed when a price quote arrives. To prevent processing the
quote on weekends, check workday() or
- Weekend can noticeably affect a strategy performance. If at 1, bars can begin and end during the weekend when they contain price quotes. However no trade is triggered by a bar that ends at weekend. If Weekend is at 2 or above, a bar can not end during the weekend; the last Friday bar is thus extended by a multiple of BarPeriod until the weekend is over. Thus a daily bar starting Friday 00:00 UTC will normally end Monday 00:00 UTC. If not explicitly prevented by script, a signal occurring during that bar can trigger a trade at the start of the week. Therefore Weekend = 2 generates less bars, but can generate more trades than Weekend = 1. This can positively or adversely affect the strategy performance.
- When Weekend is at 1 or 0, bars are generated on workdays even when no price quotes are received. At 2 or above, any bar must contain at least one price quote of the first used asset,
and must not begin or end between EndWeek
and StartWeek. Otherwise the bar is extended by a multiple of BarPeriod until a quote arrives
and the weekend has ended.
- December 25 and January 1 count as weekend. Other holidays are not
automatically included, but can be taken account of in the script.
- The Weekend variable affects the sampling of price data and thus must be set before any asset calls.
If Weekend is set up so that StartWeek,
EndWeek, StartMarket, or EndMarket
also affect the sampling of price data, they must also be set before any
asset calls. For only affecting the entering of trades, they
can be changed afterwards.
StartWeek = 10400; // start Monday 4 am
EndWeek = 51900; // end Friday 7 pm
Weekend = 1+4+8; // log off during the weekend and don't enter trades outside market hours
bar, BarPeriod, Stop, StartWeek/EndWeek
► latest version online