Docs

ITMScript

Other symbols and timeframes

How a study reads another symbol or a coarser timeframe, when each value becomes visible, and what a study may and may not combine.

A study computes on the chart's own bars. It can also read the bars of another symbol, or the same symbol on a coarser timeframe. This page says how to ask for them and when their values become visible.

Write the reference in place

These spellings cover most studies.

WriteReads
SPY.closeThe close of SPY at the chart's bar size.
close@1dThe daily close of the chart's symbol.
NVDA.close@1dThe daily close of NVDA.
@1dThe daily bars of the chart's symbol, for an operator that reads bars, such as ta.atr(14, @1d).
close@1moThe close of the last finished month.

The field after the dot is one of the nine bar fields. A bar clock is @ and a number and a unit of s, m, h, d, w, mo, q or y. A month is 1mo, a quarter is 1q and a year is 1y.

itm
//@itmscript 2
study("Daily context", overlay=false)
plot(close / SPY.close, "Relative to SPY", color=color.purple, width=2, style=line)
plot(ta.atr(14, @1d), "Daily ATR", color=color.gray, width=1, style=line)
plot(close - close@1d, "Distance from the daily close", color=color.blue, width=1, style=histogram)

A month, a quarter and a year are clocks too. A monthly bar closes at the end of the month's last session, so close@1mo is the close of the last month that has finished. The time and sessions page covers the month clocks.

itm
//@itmscript 2
study("Month and quarter", overlay=true)
plot(close@1mo, "Last month close", color=color.purple, width=2, style=stepline)
plot(close@1d, "Last day close", color=color.gray, width=1, style=stepline)

Declare it once

When a study reads the same series many times, declare it and give it a name. A declaration names a symbol, a timeframe or both. The one you leave out is the chart's.

itm
//@itmscript 2
study("Declared series", overlay=false)
d = series(timeframe="1d")
nvda = series(symbol="NVDA")
plot(ta.atr(14, d), "Daily ATR", color=color.gray, width=1, style=line)
plot(close / nvda.close, "Ratio to NVDA", color=color.blue, width=2, style=line)

A declaration can name a month, a quarter or a year as its timeframe.

itm
//@itmscript 2
study("Quarterly series", overlay=false)
q = series(timeframe="1q")
plot(q.close, "Quarter close", color=color.blue, width=2, style=stepline)
plot(ta.sma(q.close, 4), "Four quarter average", color=color.gray, width=1, style=line)

The symbol and the timeframe of a declaration can come from inputs. Declare them with input.symbol and input.timeframe, then write series(symbol=sym, timeframe=tf). The reader of the study then changes the data from its settings. A value or a table reads a series fed by an input in the same way.

A declaration that names neither is refused, because it would be the chart itself.

itm
//@itmscript 2
study("Declared series", overlay=false)
d = series()
plot(d.close, "Close", color=color.blue)

A field that is not one of the nine is refused and the message lists them.

itm
//@itmscript 2
study("Other symbol", overlay=false)
plot(SPY.price, "Price", color=color.blue)

A study may declare at most 16 series. The limits page lists the rest.

When a value becomes visible

A coarser bar is visible only after it has closed. On a five minute chart, close@1d is the close of the last finished day. It stays the same across today's bars and changes when the day ends. Today's forming daily bar is never read. This is what no lookahead means here.

For a series at the same timeframe as the chart, a value is the bar with the same close. Where the other symbol has no bar, the value is missing. A gap is a missing value and is never filled with a repeat.

What may be combined

A series finer than the chart is refused. A study runs on the chart's clock, so a chart of five minute bars cannot read one minute bars.

An operator with a window, such as ta.sma, is refused when its inputs come from different timeframes. Its window would count repeated values. Combine the values bar by bar first, and then take the window of the result.

itm
//@itmscript 2
study("Window of a spread", overlay=false)
spread = close - SPY.close
plot(ta.sma(spread, 20), "Average spread", color=color.blue, width=2, style=line)

When the data is not there

A study that reads another series needs its bars to be loaded. A study run without them stops and names the symbol and timeframe it needs. Load the bars, or remove the reference.