Skip to content

Instruments and schedules

The instrument identifies what you trade. The schedule determines when the strategy checks its rules.

One instrument or a list

symbol: TCS
universe: [TCS, INFY, RELIANCE]

Choose one of these scopes. Use exact identifiers supported by the selected market, broker and data source.

The two lines above are alternatives: do not put both in a strategy. A fixed list applies the same conditional rules to each name. universe: [TCS] is an explicit one-name list; brackets also make it clear that you are supplying names rather than a dynamic named universe, which is unsupported in the current authoring path.

An identifier must match the chosen environment, including any exchange qualifier. Changing the document's list does not hot-reload the membership of an already running deployment; stop and redeploy it with the new list.

Choose a schedule

Form Use
run: daily Check a daily strategy.
run: 15m Use a 15-minute signal interval.
run: each bar Check each bar of the configured interval.
run: monthly Schedule a monthly portfolio review.

Lookbacks count bars. ema(20) on 15-minute and daily data describe different horizons.

Interval, cadence and filters

Read run: as a comma-separated combination of a signal interval or cadence and optional calendar restrictions:

run: 5min, Mon-Fri, 09:15-15:30
Part Meaning
5min A five-minute signal interval; 5m is also accepted.
Mon-Fri Permit Monday through Friday. A single day such as Fri is accepted too.
09:15-15:30 Limit eligible evaluations to this market-local window.

15m and 15min describe the same interval; 1h is hourly. each bar uses the configured interval rather than choosing a new one. A named cadence such as monthly schedules a portfolio review; it is not a 30-bar indicator lookback. every N bars is a multiplier on the deployment interval, not an absolute number of minutes, and the local synthetic runner does not enforce it.

Do not supply multiple conflicting intervals, weekday filters or time windows. Calendar filters narrow opportunities to evaluate; they do not manufacture missing bars or open a closed market. Specify run: explicitly and check the deployment's data interval when comparing backtests.

Restrict trading hours

//@version=1
symbol: TCS
run: 5min, Mon-Fri, 09:15-15:30
size: 5% per instrument
entry:
    long when: after("10:00") and before("14:30") and close > ema(20)
exit:
    long at 15:20

Times use the resolved market-local clock. Restrictions cannot make a closed exchange tradable. long at 15:20 requires an eligible bar stamped at that minute; it does not silently act later.

In the example, the schedule restricts both entry and signal-exit evaluations. The extra after/before condition narrows entries only. Ending a run window does not itself flatten the position. On a five-minute grid, choose an exit minute actually present in the data; an exact-time exit at 15:22 would miss that grid.

Exit after a trading session

exit:
    after 1 session at 15:20

The entry session counts as zero. This exits at the specified clock on the next observed trading session. Weekends and full-day no-bar holidays do not count. after N bars and after N days are different elapsed-time forms.

Exit form What is counted
after 10 bars Bars since entry. Its elapsed duration depends on the interval.
after 2 days Elapsed days rather than ten-minute or daily bar counts.
after 1 session at 15:20 The next observed trading session, at the requested exit clock.

Unlike an ordinary exact-time exit, a session-relative exit can use the first eligible observation at or after its clock. The schedule still needs an eligible evaluation before its window closes. Do not rely on a daily bar to execute an arbitrary intraday exit minute.

Build an opening-range rule

//@version=1
symbol: TCS
run: 5min, Mon-Fri, 09:15-15:30
size: 5% per instrument
define opening_range = session_range("09:15", "09:30")
entry:
    long when: after("09:30") and close > opening_range.high
exit:
    long at 15:20

session_range(start, end) summarises the current day's bars inside the window. The start is included and the end excluded: on this five-minute grid, 09:15, 09:20 and 09:25 belong to the range. It becomes available at 09:30, while this sample's strict after("09:30") begins matching later than that minute.

Field Meaning
.high / .low Highest high and lowest low in the window.
.range / .width High minus low, in price units.
.avg_volume / .mean_volume Mean per-bar volume in the window.
.total_volume Sum of the window's volume.
.bars Number of valid bars used.

The summary resets on a new day. Until the window is complete, or if it contains no valid bars, the binding is unavailable and this strategy skips its rule evaluation. That also postpones signal exits; consider the effect when carrying a holding overnight. This helper summarises observed bars rather than supplying a complete exchange calendar.