CODESCRIPT

Multi-timeframe

24 entries. What each one takes, what it returns, and a working example.

currencyRate(kaynak, hedef)

Returns the exchange-rate series between two currencies. 1.0 if source = target; na if unavailable.

kaynak
string
Source currency (e.g. "EUR").
hedef
string
Target currency (e.g. "USD").
NOTE

For converting values in different currencies to a comparable unit. Rate data would come from the terminal once connected; currently not connected (see limits).

CODESCRIPT
plot(currencyRate("EUR", "USD"), "EURUSD Kuru")

Currently always na (empty line) — no data source connected yet.

CODESCRIPT
plot(currencyRate("USD", "USD"), "Aynı para")

Plots a constant 1.0 because the same currency is given.

dividends(sembol, alan?)

Returns the company's dividend payments as a series aligned to payment bars.

sembol
string
Company symbol.
alan
string
Optional. "gross"/"net" etc. (default "gross").
NOTE

na on non-payment bars; the whole series is na if no data.

CODESCRIPT
plot(dividends("THYAO", "gross"), "Temettü")

Currently always na (empty line) — no data source connected yet.

earnings(sembol, alan?)

Returns the company's earnings releases (EPS etc.) as a series aligned to announcement bars.

sembol
string
Company symbol.
alan
string
Optional. "actual"/"estimate" etc. (default "actual").
NOTE

na on non-announcement bars; na if no data.

CODESCRIPT
plot(earnings("THYAO", "actual"), "Açıklanan Kâr")

Currently always na (empty line) — no data source connected yet.

economic(ülke, alan)

Returns a country's economic indicator (GDP, inflation, etc.) as a series aligned to release bars.

ülke
string
Country code (e.g. "TUR", "USA").
alan
string
Economic indicator code (e.g. "GDP", "CPI").
NOTE

na if no data; macro indicators are released infrequently (the value is carried forward until the next release).

CODESCRIPT
plot(economic("TUR", "GDP"), "GSYİH")

Currently always na (empty line) — no data source connected yet.

financial(sembol, kalem, dönem?)

Returns a company's fundamental (financial-statement) metric as a series aligned to the bars where it was reported.

sembol
string
Company symbol (e.g. "THYAO").
kalem
string
Financial metric code (e.g. "TOTAL_REVENUE").
dönem
string
Optional. Period: "FY" / "FQ" / "TTM" — default "FY".
NOTE

The value applies only from its report date onward (no look-ahead); na if unavailable.

CODESCRIPT
plot(financial("THYAO", "TOTAL_REVENUE", "FY"), "Yıllık Gelir")

Currently always na (empty line) — no data source connected yet.

htf(timeframe, source)

Samples the source to the higher timeframe: once each HTF bar COMPLETES, its last value is carried forward (constant within the bar).

timeframe
string
Higher timeframe (e.g. "60", "1D", "1W").
source
series
The series to sample to the higher timeframe (e.g. close).
NOTE

There is NO look-ahead — the value appears only after the HTF bar closes, so it does not peek into the future (repaint-safe). A simpler shortcut than `security` for same-symbol higher timeframes.

CODESCRIPT
gunluk_kapanis = htf("1D", close)
plot(gunluk_kapanis, "Günlük Kapanış")

Carries the daily close onto the lower-TF chart as a step line.

CODESCRIPT
plot(close > htf("1D", sma(close, 20)) ? 1 : 0, "Günlük SMA üstünde")

1 when price is above the daily 20-SMA (a higher-TF trend filter).

quandl(kod, ...)

Always returns an empty (na) series — no data is provided because the source (NASDAQ Data Link) was discontinued.

kod
string
Dataset code.
NOTE

Present for backward compatibility; it returns no functional data because the source was shut down (the upstream itself is closed).

CODESCRIPT
plot(quandl("FRED/GDP"), "Quandl")

Returns an empty (na) series — source is closed.

security(symbol, timeframe, source, gaps?, lookahead?, ignore_invalid_symbol?)

The series of the expression computed on the higher timeframe and aligned to the current bar without looking ahead.

sembol
string
Symbol; usually syminfo.tickerid (the current symbol) or a fixed code.
tf
string
Timeframe (e.g. "60", "240", "D"). Empty = chart timeframe.
kaynak
series
Expression to compute on the higher timeframe (e.g. close, sma(close,20)).
ignore_invalid_symbol
bool
Optional. If true, an invalid/unloaded symbol returns na (empty) instead of raising an error. Default false (raises an error).
NOTE

The higher-timeframe value is aligned after that bar CLOSES (it does not look ahead and does not change afterward). The `currency` (FX conversion) and `calc_bars_count` parameters are NOT supported in this version — if given, they are silently ignored.

TIP

The higher-timeframe value aligns only after that bar closes; the symbol and timeframe must stay constant throughout the run.

CODESCRIPT
plot(security(syminfo.tickerid, "60", close), "1s kapanış", "#ff9800")

A stepped line of the 1-hour close on a 5m chart (updates every hour).

CODESCRIPT
htf = security(syminfo.tickerid, "60", sma(close,20))
enterLong(crossover(close, htf))
exit(crossunder(close, htf))

BUY when price crosses above the 1-hour SMA20 — a higher-timeframe trend filter.

securityLowerTf(sembol, tf, kaynak)

For each main-chart bar, an array of the lower-TF values that fall inside that bar, in chronological order.

sembol
string
A literal symbol string (PRIMARY or empty is not supported).
tf
string
Must be a timeframe LOWER than the main chart's (LTF).
kaynak
series
The expression to evaluate in the LTF context (e.g. `close`).
NOTE

Equivalent to `request.security_lower_tf(symbol, tf, source)` (the namespace form). The `source` expression may only reference built-ins, user functions (`fn`), and independent top-level variables.

CODESCRIPT
ltfCloses = securityLowerTf("BTCUSDT", "1", close)
plot(ltfCloses.size() > 0 ? ltfCloses.get(ltfCloses.size() - 1) : na)

Returns an array of 1-minute lower-TF closes for each main-chart bar; plots the last element.

seed(kaynak, sembol)

Returns a symbol's series from a custom seed dataset, aligned to the bars.

kaynak
string
Seed dataset/source name.
sembol
string
Symbol within that source.
NOTE

Populated only if the terminal supplies the relevant seed data; otherwise na.

CODESCRIPT
plot(seed("BIST_DELAY", "THYAO"), "Seed Serisi")

Plots the series from the seed source (if data exists).

splits(sembol, alan?)

Returns the company's stock splits as a series aligned to split bars.

sembol
string
Company symbol.
alan
string
Optional. "numerator"/"denominator" (default "numerator").
NOTE

na on non-split bars.

CODESCRIPT
plot(splits("THYAO", "numerator"), "Bölünme Payı")

Currently always na (empty line) — no data source connected yet.

sym("SYMBOL")

The series of another symbol (.open/.high/.low/.close/.volume), aligned to this chart's time.

symbol
string
Symbol code, e.g. "LTCUSDT".
NOTE

For pair/ratio strategies: ratio = close / sym("LTCUSDT").close. The returned object's fields are used in calculations like any series.

CODESCRIPT
oran = close / sym("LTCUSDT").close
plot(oran, "Oran")

Plots the price ratio of the two symbols (the basis of a pair/ratio strategy).

CODESCRIPT
plot(correlation(close, sym("LTCUSDT").close, 30), "Korelasyon")

Plots the 30-bar correlation between this symbol and LTCUSDT.

syminfoPrefix(sembol)

Returns the prefix before ":" in the ticker (e.g. "BIST"); an empty string if there is no ":".

sembol
string
Full ticker (e.g. "BIST:THYAO").
NOTE

To extract which exchange/provider a symbol belongs to.

CODESCRIPT
label(close, syminfoPrefix("BIST:THYAO"))

Labels "BIST".

syminfoTicker(sembol)

With an argument, returns the symbol part after ":" (e.g. "THYAO"); called with no argument, returns the currently processed symbol.

sembol
string
Optional. Full ticker (e.g. "BIST:THYAO"). If omitted, the active context symbol.
NOTE

Bare syminfoTicker() yields the active symbol in multi-symbol scans (useful inside request.security loops and securityLowerTf expressions).

CODESCRIPT
label(close, syminfoTicker("BIST:THYAO"))

Labels "THYAO".

tickerHeikinashi(sembol)

RAISES an error — the Heikin-Ashi bar-type transform is not supported by CodeScript.

sembol
string
Ticker string.
NOTE

CodeScript operates on standard (time) bars; Heikin-Ashi bars are not produced. Instead of silently returning wrong (standard-bar) results, it raises a clear error.

tickerInherit(sembol, kaynak)

Returns the first ticker UNCHANGED (identity).

sembol
string
Ticker string.
kaynak
string
Source ticker to inherit settings from.
NOTE

Intended for a symbol to inherit another symbol's settings; it has no effect on standard bars (a placeholder).

CODESCRIPT
label(close, tickerInherit("BIST:GARAN", "BIST:THYAO"))

Returns the first ticker as-is ("BIST:GARAN").

tickerKagi(sembol, ...)

RAISES an error — the Kagi bar-type transform is not supported by CodeScript.

sembol
string
Ticker string.
NOTE

CodeScript operates on standard (time) bars; Kagi bars are not produced. Instead of silently returning wrong (standard-bar) results, it raises a clear error.

tickerLinebreak(sembol, ...)

RAISES an error — the Line-break bar-type transform is not supported by CodeScript.

sembol
string
Ticker string.
NOTE

CodeScript operates on standard (time) bars; Line-break bars are not produced. Instead of silently returning wrong (standard-bar) results, it raises a clear error.

tickerModify(sembol, ...)

Returns the ticker UNCHANGED (identity).

sembol
string
Ticker string.
NOTE

Intended to attach session/adjustment settings to a ticker; since CodeScript works on standard bars, this transform leaves the symbol as-is (a placeholder).

CODESCRIPT
label(close, tickerModify("BIST:THYAO"))

Returns the ticker as-is ("BIST:THYAO").

tickerNew(önek, sembol)

Returns a full ticker string in "PREFIX:SYMBOL" form (just the symbol if the prefix is empty).

önek
string
Exchange/data-provider prefix (e.g. "BINANCE", "BIST").
sembol
string
Symbol code (e.g. "BTCUSDT").
NOTE

Used to build a full ticker for security or sym. The result is a string, not a series.

CODESCRIPT
label(close, tickerNew("BINANCE", "BTCUSDT"))

Builds the "BINANCE:BTCUSDT" ticker; use it in security.

tickerPointfigure(sembol, ...)

RAISES an error — the Point & Figure bar-type transform is not supported by CodeScript.

sembol
string
Ticker string.
NOTE

CodeScript operates on standard (time) bars; Point & Figure bars are not produced. Instead of silently returning wrong (standard-bar) results, it raises a clear error.

tickerRenko(sembol, ...)

RAISES an error — the Renko bar-type transform is not supported by CodeScript.

sembol
string
Ticker string.
NOTE

CodeScript operates on standard (time) bars; Renko bars are not produced. Instead of silently returning wrong (standard-bar) results, it raises a clear error.

tickerStandard(sembol)

Returns the ticker UNCHANGED (identity).

sembol
string
Ticker string.
NOTE

Intended to convert a symbol to a standard (untransformed) ticker; since CodeScript works on standard bars, this transform leaves the symbol as-is (a placeholder).

CODESCRIPT
label(close, tickerStandard("BIST:THYAO"))

Returns the ticker as-is ("BIST:THYAO").

trade(series)

Does not return a value; the backtest's profit/loss is computed over this series.

series
series
The instrument whose profit/loss the backtest computes (e.g. a ratio/spread).
NOTE

For simulating trades on a ratio/spread instead of close (pair mode). If not called, the backtest uses close.

CODESCRIPT
x = sym("LTCUSDT")
oran = close / x.close
trade(oran)
enterLong(crossover(ema(oran,5), ema(oran,13)))
enterShort(crossunder(ema(oran,5), ema(oran,13)))

Trades EMA crossovers on the ratio; P&L is computed on the ratio instead of close.