TradingCharts

Built-Ins

This page is a map, not a full reference — each sub-area has its own page with signatures and examples.

Built-in series

Name Meaning
open current bar's open price
high current bar's high
low current bar's low
close current bar's close
volume current bar's volume
hl2 (high + low) / 2
hlc3 (high + low + close) / 3
ohlc4 (open + high + low + close) / 4
hlcc4 (high + low + close + close) / 4
time bar's open time, ms UTC
time_close bar's close time, ms UTC
bar_index 0-indexed bar number
last_bar_index index of the chart's last bar
last_bar_time time of the chart's last bar
timenow wall-clock time, ms UTC

Historical access is uniform: close[1], volume[5], bar_index[0] all read bar-ago values.

Series namespaces

The lists below are generated from the compiler's own tables (dcs-compiler 0.3.51) — if a name is not here, the compiler rejects it with Unknown function 'ns.name'.

ta.* — technical analysis (61 functions + 6 tuple functions)

Moving averages and smoothers: sma, ema, rma, wma, vwma, swma, alma, hma, linreg, vwap Oscillators: rsi, cci, cmo, cog, mfi, mom, roc, stoch, tsi, wpr, rci Volatility / dispersion: atr, tr, stdev, dev, variance, bbw, kcw, range Trend: sar Direction: change, rising, falling, crossover, crossunder, cross Reductions: highest, lowest, highestbars, lowestbars, max, min, cum, median, mode, percentrank, percentile_nearest_rank, percentile_linear_interpolation, correlation Pivots: pivothigh, pivotlow Volume: obv, accdist, nvi, pvi, pvt, wad, wvad, iii Query: barssince, valuewhen

Tuple-returning forms (destructure with [a, b] = …): ta.macd(src, fast, slow, signal) → [macd, signal, hist], ta.bb(src, len, mult) → [middle, upper, lower], ta.kc(src, len, mult, useTrueRange?) → [middle, upper, lower], ta.dmi(diLen, adxSmoothing) → [+DI, -DI, ADX], ta.supertrend(factor, atrLen) → [supertrend, direction], ta.vwap(src, anchor?, stdevMult?) → [vwap, upper, lower].

ta.cum, ta.obv, ta.accdist, ta.nvi, ta.pvi, ta.wad, ta.pvt are cumulative: a script using them is recomputed from the first bar on every tick (see Profiling).

The v1–v4 bare aliases (sma(…), rsi(…), crossover(…), …) still compile for the 48 classic functions.

math.* — numeric functions (24) and constants

abs, max, min, sqrt, pow, log, log10, exp, round, round_to_mintick, floor, ceil, sign, avg, sum, sin, cos, tan, asin, acos, atan, todegrees, toradians, random. Constants: math.pi, math.e. (math.phi and math.rphi are not defined — see What is not supported.)

str.* — strings (18)

tostring, tonumber, format, format_time, length, contains, startswith, endswith, pos, match, substring, split, replace, replace_all, repeat, trim, lower, upper.

See Strings.

color.* — colors

17 constants: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, yellow (plus any #rrggbb / #rrggbbaa literal). Functions: new(c, transp), rgb(r, g, b, transp?), from_gradient(value, bottom, top, bottomColor, topColor), r(c), g(c), b(c), t(c).

See Colors.

input.* — inputs (13)

int, float, bool, string, color, source, symbol, timeframe, session, time, price, textarea, enum, plus the generic input(defval, title, …).

See Inputs.

array.* — arrays (43 operations + constructors)

Constructors: array.new<type>(size?, initial?), array.from(…), and the typed new_float, new_int, new_bool, new_string, new_color, new_line, new_label, new_box, new_table, new_linefill. Mutation: push, unshift, pop, shift, set, insert, remove, clear, fill, reverse, sort, concat. Access: get, first, last, size, slice, copy, indexof, lastindexof, includes, join, every, some, sort_indices, binary_search, binary_search_leftmost, binary_search_rightmost. Statistics: sum, avg, min, max, abs, median, mode, range, stdev, variance, covariance, standardize, percentrank, percentile_nearest_rank, percentile_linear_interpolation.

map.* — maps (10)

new<K, V>(), put, put_all, get, contains, remove, clear, copy, size, keys, values.

matrix.* — matrices (50)

Shape: new<type>(rows, cols, initial?), rows, columns, elements_count, reshape, submatrix, transpose, reverse, copy, concat. Rows / columns: row, col, add_row, add_col, remove_row, remove_col, swap_rows, swap_columns, fill, first, last, get, set, sort. Algebra: sum, diff, mult, pow, det, inv, pinv, rank, trace, eigenvalues, eigenvectors, kron. Statistics: avg, median, mode, min, max. Predicates: is_square, is_zero, is_binary, is_identity, is_diagonal, is_antidiagonal, is_symmetric, is_antisymmetric, is_triangular, is_stochastic.

request.* — cross-symbol / cross-timeframe data

request.security, request.security_lower_tf, request.dividends, request.splits, request.earnings, request.financial, request.economic (compiles, returns na — no data source yet). request.quandl, request.seed, request.currency_rate and request.footprint are not available.

See Other timeframes and data.

strategy.* — order management

Orders: strategy.entry, strategy.exit, strategy.close, strategy.close_all, strategy.order, strategy.cancel, strategy.cancel_all. Risk rules: strategy.risk.allow_entry_in, max_position_size, max_drawdown, max_intraday_loss, max_cons_loss_days, max_intraday_filled_orders.

Account values (30): position_size, position_avg_price, position_entry_name, opentrades, closedtrades, wintrades, losstrades, eventrades, equity, netprofit, openprofit, grossprofit, grossloss, initial_capital, max_drawdown, max_runup, avg_trade, avg_winning_trade, avg_losing_trade, avg_trade_percent, avg_winning_trade_percent, avg_losing_trade_percent, netprofit_percent, openprofit_percent, grossprofit_percent, grossloss_percent, max_contracts_held_all, max_contracts_held_long, max_contracts_held_short, account_currency.

Per-trade accessors (18) on strategy.closedtrades.*(index) / strategy.opentrades.*(index): size, profit, profit_percent, commission, entry_id, entry_price, entry_time, entry_bar_index, entry_comment, exit_id, exit_price, exit_time, exit_bar_index, exit_comment, max_runup, max_runup_percent, max_drawdown, max_drawdown_percent.

See Strategies.

Drawing namespaces

  • line.* — new, delete, copy, get_x1/get_y1/get_x2/get_y2, set_x1/set_y1/set_x2/set_y2, set_xy1/set_xy2, set_xloc, set_color, set_width, set_style, set_extend, get_price, line.all.
  • box.* — new, delete, copy, get_left/get_right/get_top/get_bottom, set_left/set_right/set_top/set_bottom, set_lefttop/set_rightbottom, set_bgcolor, set_border_color, set_border_width, set_border_style, set_extend, set_text, set_text_color, set_text_size, set_text_halign/set_text_valign, set_text_wrap, set_text_font_family, set_text_formatting, box.all.
  • label.* — new, delete, copy, get_x/get_y, get_text, set_x/set_y/set_xy, set_xloc/set_yloc, set_text, set_textcolor, set_color, set_style, set_size, set_textalign, set_tooltip, set_text_font_family, set_text_formatting, label.all.
  • polyline.* — new(points, curved?, closed?, xloc?, line_color?, fill_color?, line_style?, line_width?), delete, polyline.all; points are chart.point objects (chart.point.new, from_index, from_time, now, copy).
  • linefill.* — new(line1, line2, color), delete, get_line1/get_line2, set_color, linefill.all.
  • table.* — new(position, columns, rows, …), delete, clear, cell, merge_cells, set_position, set_bgcolor, set_frame_color/set_frame_width, set_border_color/set_border_width, and per cell cell_set_text, cell_set_bgcolor, cell_set_text_color, cell_set_text_size, cell_set_text_halign/cell_set_text_valign, cell_set_tooltip, cell_set_width/cell_set_height, cell_set_text_font_family, cell_set_text_formatting.

See Lines and boxes, Text and shapes, Tables.

log.*, alertcondition and alert

  • log.info(msg), log.warning(msg), log.error(msg) — the editor panel's Logs pane (filters, source jump, scroll to bar: see Debugging).
  • alertcondition(cond, title, message) — declarative, bound to the chart.
  • alert(message, freq?) — dynamic, called from the body; default alert.freq_once_per_bar.

See Alerts.

Constant namespaces

Namespaces whose members are compile-time constants:

  • color.* — see Colors
  • shape.* — shape.triangleup, shape.triangledown, shape.cross, shape.circle, shape.square, shape.diamond, shape.flag, shape.arrowup, shape.arrowdown, shape.labelup, shape.labeldown, shape.xcross
  • size.* — size.auto, size.tiny, size.small, size.normal, size.large, size.huge
  • location.* — location.absolute, location.abovebar, location.belowbar, location.top, location.bottom
  • plot.* — plot.style_line, plot.style_stepline, plot.style_histogram, plot.style_cross, plot.style_area, plot.style_columns, plot.style_circles, plot.style_areabr, plot.style_linebr, plot.style_stepline_diamond, plus plot.linestyle_solid/dashed/dotted
  • hline.* — hline.style_solid, hline.style_dashed, hline.style_dotted
  • line.style_*, extend.left/right/both/none, scale.right/left/none
  • display.* — display.none, display.pane, display.data_window, display.price_scale, display.status_line, display.all
  • format.* — format.inherit, format.price, format.volume, format.percent, format.mintick
  • font.*, position.*, text.align_left/center/right, text.wrap_none/auto

Symbol / chart namespaces

  • syminfo.* — strings tickerid, ticker, symbol, prefix, root, main_tickerid, description, type, isin, currency, basecurrency, country, timezone, session, volumetype, sector, industry; numbers mintick, minmove, pricescale, pointvalue, mincontract, expiration_date, shareholders, shares_outstanding_total, shares_outstanding_float, recommendations_buy, recommendations_hold, recommendations_sell, recommendations_total, employees (always na). Values and sources: Chart information.
  • timeframe.* — period, multiplier, main_period, isseconds, isminutes, isintraday, isdaily, isweekly, ismonthly, isdwm; functions in_seconds(tf?), from_seconds(n), change(tf).
  • barstate.* — isfirst, islast, ishistory, isrealtime, isnew, isconfirmed, islastconfirmedhistory.
  • chart.* — is_standard, is_heikinashi, is_renko, is_kagi, is_linebreak, is_pnf, is_range, bg_color, fg_color, left_visible_bar_time / right_visible_bar_time (≈ first / last loaded bar — there is no viewport model server-side).
  • session.* — ismarket (always true), ispremarket / ispostmarket (always false: executions run on regular-session data), isfirstbar, islastbar, isfirstbar_regular, islastbar_regular.
  • ticker.* — new, modify, standard, heikinashi, inherit, renko, linebreak, kagi, pointfigure (the last four build the ticker string; the non-standard bars themselves come from the chart type the user selected).
  • session.* — .ismarket, .ispremarket, .ispostmarket, .isfirstbar, .islastbar
  • barstate.* — .isconfirmed, .islast, .isfirst, .ishistory, .isrealtime, .isnew, .islastconfirmedhistory
  • chart.* — .left_visible_bar_time, .right_visible_bar_time, .is_heikinashi/isrenko/iskagi/islinebreak/isrange/ispnf/isstandard, .fg_color, .bg_color
  • dayofweek.*, currency.*

Logging

log.info(msg), log.warning(msg), log.error(msg).

See Debugging.

Full reference

Every built-in ships with a tested signature in the compiler's verification corpus.

See also