Skip to content
ChartDeck ChartScript docs Account Open the terminal

Global names

Built-in variables and functions that are not inside a namespace: the bar's prices, the script declaration, plots and the core helpers.

#Functions

#barcolorfunction

Colours the chart candles on each bar (na: the chart's own colour). When several scripts colour the same candle, the last one added wins.

barcolor(color: color, { offset?: input int = 0, editable?: const bool = true, show_last?: const int = na, title?: const string = "", display?: input display = display.all })
ParameterTypeDescription
colorcolorThe colour.
offsetinput intdefault 0Shift the output this many bars to the right (negative: left).
editableconst booldefault trueAccepted and ignored (styles are always editable).
show_lastconst intdefault naAccepted and ignored in this version.
titleconst stringdefault ""The name shown in the settings, legend and data window.
displayinput displaydefault display.allWhere the value is shown (display.*).

Example

ChartScriptFragmentOpen in editor
barcolor(close > ta.sma(close, 20) ? color.up : na)

Since ChartScript 1

#bgcolorfunction

Colours the pane background on each bar (na: no colour).

bgcolor(color: color, { offset?: input int = 0, editable?: const bool = true, show_last?: const int = na, title?: const string = "", display?: input display = display.all, force_overlay?: const bool = false, format?: const format = na, precision?: const int = na })
ParameterTypeDescription
colorcolorThe colour.
offsetinput intdefault 0Shift the output this many bars to the right (negative: left).
editableconst booldefault trueAccepted and ignored (styles are always editable).
show_lastconst intdefault naAccepted and ignored in this version.
titleconst stringdefault ""The name shown in the settings, legend and data window.
displayinput displaydefault display.allWhere the value is shown (display.*).
force_overlayconst booldefault falseAccepted and ignored in this version.
formatconst formatdefault naAccepted for compatibility with imported scripts (a background has no values to format).
precisionconst intdefault naAccepted for compatibility with imported scripts (a background has no values to format).

Example

ChartScriptFragmentOpen in editor
bgcolor(close > open ? color.new(color.up, 90) : na)

Since ChartScript 1

#boolfunction

Converts to bool: na and 0 are false.

bool(x: T): bool
ParameterTypeDescription
xTThe value.

Returns bool.

Example

ChartScriptFragmentOpen in editor
const b = bool(volume)

Since ChartScript 1

#dayofmonthfunction

The day of the month of the bar open (UTC). The dayofmonth of a time in a time zone.

dayofmonth(time: int, { timezone?: string = "UTC" }): int
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns int.

Example

ChartScriptFragmentOpen in editor
const v = dayofmonth(time, "UTC")

Since ChartScript 1

#fillfunction

Fills between two plots or two hlines; the gradient form colours each bar from top_color at top_value to bottom_color at bottom_value.

fill(hline1: hline, hline2: hline, { color?: color = na, title?: const string = "", editable?: const bool = true, fillgaps?: const bool = false, display?: input display = display.all, role?: const string = "", look?: const string = "", variant?: const string = "" })
fill(plot1: plot, plot2: plot, { color?: color = na, title?: const string = "", editable?: const bool = true, show_last?: const int = na, fillgaps?: const bool = false, display?: input display = display.all, role?: const string = "", look?: const string = "", variant?: const string = "" })
fill(plot1: plot, plot2: plot, top_value: float, bottom_value: float, top_color: color, bottom_color: color, { title?: const string = "", display?: input display = display.all, fillgaps?: const bool = false, editable?: const bool = true, role?: const string = "", look?: const string = "", variant?: const string = "" })
ParameterTypeDescription
hline1hlineThe first hline.
hline2hlineThe second hline.
colorcolordefault naThe colour.
titleconst stringdefault ""The name shown in the settings, legend and data window.
editableconst booldefault trueAccepted and ignored (styles are always editable).
fillgapsconst booldefault falseAccepted and ignored.
displayinput displaydefault display.allWhere the value is shown (display.*).
roleconst stringdefault ""What the color of this output means, for the color presets of the Colors tab: "up", "down", "neutral" or "accent". Empty = guessed from the role of its style (look), the theme color, the title and the hue (a teal line counts as up). Another value is error CS2014.
lookconst stringdefault ""A style made with style.plot / style.line / style.marker / style.fill (its look, shared and user-editable).
variantconst stringdefault ""The name of one of the style's variants (style.variant).
plot1plotThe first plot.
plot2plotThe second plot.
show_lastconst intdefault naAccepted and ignored in this version.
top_valuefloatThe value of the top colour.
bottom_valuefloatThe value of the bottom colour.
top_colorcolorThe colour at top_value.
bottom_colorcolorThe colour at bottom_value.

Example

ChartScriptFragmentOpen in editor
const a = plot(high)
const b = plot(low)
fill(a, b, color.new(color.accent, 80))

Since ChartScript 1

#fixnanfunction

The value, or the last value that was not na.

fixnan(source: T): T
ParameterTypeDescription
sourceTThe series to read.

Returns T.

Example

ChartScriptFragmentOpen in editor
const pv = fixnan(ta.pivothigh(high, 5, 5))

Since ChartScript 1

#floatfunction

Converts to float; also types an na.

float(x: num): float
ParameterTypeDescription
xnumThe value.

Returns float.

Example

ChartScriptFragmentOpen in editor
const f = float(na)

Since ChartScript 1

#hourfunction

The hour of the bar open (UTC). The hour of a time in a time zone.

hour(time: int, { timezone?: string = "UTC" }): int
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns int.

Example

ChartScriptFragmentOpen in editor
const v = hour(time, "UTC")

Since ChartScript 1

#indicatorfunction

Declares the script as an indicator: its name, pane and number format.

indicator(title: const string, { shorttitle?: const string = "", overlay?: const bool = false, format?: const format = format.inherit, precision?: const int = na, scale?: const scale = na, max_bars_back?: const int = 500, timeframe?: const string = "", timeframe_gaps?: const bool = true, explicit_plot_zorder?: const bool = false, max_lines_count?: const int = 50, max_labels_count?: const int = 50, max_boxes_count?: const int = 50, max_polylines_count?: const int = 50, dynamic_requests?: const bool = true, behind_chart?: const bool = false, calc_bars_count?: const int = na })
ParameterTypeDescription
titleconst stringThe name shown in the settings, legend and data window.
shorttitleconst stringdefault ""The short name used in the legend.
overlayconst booldefault falsetrue: draw on the price pane; false: in its own pane.
formatconst formatdefault format.inheritThe number format (format.*).
precisionconst intdefault naDecimals shown.
scaleconst scaledefault naThe price scale (scale.*).
max_bars_backconst intdefault 500History kept for dynamic offsets (1-10,000).
timeframeconst stringdefault ""A timeframe such as "60", "240", "1D" or "1W"; "" is the chart's.
timeframe_gapsconst booldefault trueAccepted and ignored.
explicit_plot_zorderconst booldefault falsetrue = plots, horizontal levels and fills are layered in the order they appear in the script (default: by kind, as in imported scripts).
max_lines_countconst intdefault 50How many lines are kept (1-1,000; the oldest goes first).
max_labels_countconst intdefault 50How many labels are kept (1-1,000; the oldest goes first).
max_boxes_countconst intdefault 50How many boxes are kept (1-1,000; the oldest goes first).
max_polylines_countconst intdefault 50How many polylines are kept (1-500; the oldest goes first).
dynamic_requestsconst booldefault trueAllow markets and timeframes that change at run time in requests (on by default; false = simple strings only).
behind_chartconst booldefault falsetrue = an overlay script draws behind the price candles; false (the ChartDeck default) = in front of them.
calc_bars_countconst intdefault naThe number of bars the script runs on: the newest N bars of the chart's market and timeframe, fetched for the script (5,000 when left out). Your plan's bars per run is the most (Beginner 5,000, Plus 7,500, Pro 10,000, Elite 20,000; a phone 2,000). Chart bars older than the run show no script values; scrolling back never extends the run.

Example

ChartScriptOpen in editor
//@chartscript 1
indicator("My script", { overlay: true })

Since ChartScript 1

#intfunction

Converts to int (truncates toward zero); also types an na.

int(x: num): int
ParameterTypeDescription
xnumThe value.

Returns int.

Example

ChartScriptFragmentOpen in editor
const n = int(close)

Since ChartScript 1

#libraryfunction

Declares the script as a library: its exported functions, methods, types, enums and constants can be imported by other scripts.

library(title: const string, { overlay?: const bool = false, dynamic_requests?: const bool = true })
ParameterTypeDescription
titleconst stringThe name shown in the settings, legend and data window.
overlayconst booldefault falsetrue: draw on the price pane; false: in its own pane.
dynamic_requestsconst booldefault trueAllow markets and timeframes that change at run time in requests (on by default; false = simple strings only).

Example

ChartScriptOpen in editor
//@chartscript 1
library("Tools")
export const double = (x: float) => x * 2

Since ChartScript 1

#max_bars_backfunction

Sets the history kept for one variable (compile time only).

max_bars_back(var: T, num: const int)
ParameterTypeDescription
varTThe variable.
numconst intThe number of bars of history.

Example

ChartScriptFragmentOpen in editor
const x = close - open
max_bars_back(x, 1000)

Since ChartScript 1

#minutefunction

The minute of the bar open (UTC). The minute of a time in a time zone.

minute(time: int, { timezone?: string = "UTC" }): int
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns int.

Example

ChartScriptFragmentOpen in editor
const v = minute(time, "UTC")

Since ChartScript 1

#monthfunction

The month of the bar open (1-12, UTC). The month of a time in a time zone.

month(time: int, { timezone?: string = "UTC" }): int
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns int.

Example

ChartScriptFragmentOpen in editor
const v = month(time, "UTC")

Since ChartScript 1

#nafunction

true when the value is na (missing).

na(x: T): bool
ParameterTypeDescription
xTThe value.

Returns bool.

Example

ChartScriptFragmentOpen in editor
const missing = na(close[1])

Since ChartScript 1

#nzfunction

The value, or the replacement (0 by default) when it is na.

nz(source: num, { replacement?: num = 0 }): num
nz(source: T, replacement: T): T
ParameterTypeDescription
sourcenumThe series to read.
replacementnumdefault 0The replacement.

Returns num.

Example

ChartScriptFragmentOpen in editor
const chg = nz(close - close[1])

Since ChartScript 1

#plotarrowfunction

Draws an up arrow for positive values and a down arrow for negative ones.

plotarrow(series: float, { title?: const string = "", colorup?: input color = color.up, colordown?: input color = color.down, offset?: input int = 0, minheight?: const int = 5, maxheight?: const int = 100, editable?: const bool = true, show_last?: const int = na, display?: input display = display.all, format?: const format = na, precision?: const int = na, force_overlay?: const bool = false })
ParameterTypeDescription
seriesfloatThe value to draw on each bar.
titleconst stringdefault ""The name shown in the settings, legend and data window.
colorupinput colordefault color.upThe colour of up arrows.
colordowninput colordefault color.downThe colour of down arrows.
offsetinput intdefault 0Shift the output this many bars to the right (negative: left).
minheightconst intdefault 5The smallest arrow height in pixels.
maxheightconst intdefault 100The largest arrow height in pixels.
editableconst booldefault trueAccepted and ignored (styles are always editable).
show_lastconst intdefault naAccepted and ignored in this version.
displayinput displaydefault display.allWhere the value is shown (display.*).
formatconst formatdefault naThe number format (format.*).
precisionconst intdefault naDecimals shown.
force_overlayconst booldefault falseAccepted and ignored in this version.

Example

ChartScriptFragmentOpen in editor
plotarrow(close - open, "Body")

Since ChartScript 1

#plotbarfunction

Draws OHLC bars.

plotbar(open: float, high: float, low: float, close: float, { title?: const string = "", color?: color = na, editable?: const bool = true, show_last?: const int = na, display?: input display = display.all, format?: const format = na, precision?: const int = na, force_overlay?: const bool = false })
ParameterTypeDescription
openfloatThe open value.
highfloatThe high value.
lowfloatThe low value.
closefloatThe close value.
titleconst stringdefault ""The name shown in the settings, legend and data window.
colorcolordefault naThe colour.
editableconst booldefault trueAccepted and ignored (styles are always editable).
show_lastconst intdefault naAccepted and ignored in this version.
displayinput displaydefault display.allWhere the value is shown (display.*).
formatconst formatdefault naThe number format (format.*).
precisionconst intdefault naDecimals shown.
force_overlayconst booldefault falseAccepted and ignored in this version.

Example

ChartScriptFragmentOpen in editor
plotbar(open, high, low, close, "Bars")

Since ChartScript 1

#plotcandlefunction

Draws candles.

plotcandle(open: float, high: float, low: float, close: float, { title?: const string = "", color?: color = na, wickcolor?: color = na, editable?: const bool = true, show_last?: const int = na, bordercolor?: color = na, display?: input display = display.all, format?: const format = na, precision?: const int = na, force_overlay?: const bool = false })
ParameterTypeDescription
openfloatThe open value.
highfloatThe high value.
lowfloatThe low value.
closefloatThe close value.
titleconst stringdefault ""The name shown in the settings, legend and data window.
colorcolordefault naThe colour.
wickcolorcolordefault naThe wick colour.
editableconst booldefault trueAccepted and ignored (styles are always editable).
show_lastconst intdefault naAccepted and ignored in this version.
bordercolorcolordefault naThe border colour.
displayinput displaydefault display.allWhere the value is shown (display.*).
formatconst formatdefault naThe number format (format.*).
precisionconst intdefault naDecimals shown.
force_overlayconst booldefault falseAccepted and ignored in this version.

Example

ChartScriptFragmentOpen in editor
plotcandle(open, high, low, close, "Candles", close > open ? color.up : color.down)

Since ChartScript 1

#plotcharfunction

Draws one character on bars where the series is true (or not na).

plotchar(series: bool, { title?: const string = "", char?: input string = "★", location?: input location = location.abovebar, color?: color = na, offset?: input int = 0, text?: input string = "", textcolor?: color = na, editable?: const bool = true, size?: input size = size.auto, show_last?: const int = na, display?: input display = display.all, format?: const format = na, precision?: const int = na, force_overlay?: const bool = false, role?: const string = "", look?: const string = "", variant?: const string = "", textstyle?: input string = "", text_formatting?: input int = text.format_none })
plotchar(series: float, { title?: const string = "", char?: input string = "★", location?: input location = location.abovebar, color?: color = na, offset?: input int = 0, text?: input string = "", textcolor?: color = na, editable?: const bool = true, size?: input size = size.auto, show_last?: const int = na, display?: input display = display.all, format?: const format = na, precision?: const int = na, force_overlay?: const bool = false, role?: const string = "", look?: const string = "", variant?: const string = "", textstyle?: input string = "", text_formatting?: input int = text.format_none })
ParameterTypeDescription
seriesboolThe value to draw on each bar.
titleconst stringdefault ""The name shown in the settings, legend and data window.
charinput stringdefault "★"One character to draw.
locationinput locationdefault location.abovebarWhere the shape sits (location.*).
colorcolordefault naThe colour.
offsetinput intdefault 0Shift the output this many bars to the right (negative: left).
textinput stringdefault ""Text drawn with the shape.
textcolorcolordefault naThe colour of the text.
editableconst booldefault trueAccepted and ignored (styles are always editable).
sizeinput sizedefault size.autoThe number of elements.
show_lastconst intdefault naAccepted and ignored in this version.
displayinput displaydefault display.allWhere the value is shown (display.*).
formatconst formatdefault naThe number format (format.*).
precisionconst intdefault naDecimals shown.
force_overlayconst booldefault falseAccepted and ignored in this version.
roleconst stringdefault ""What the color of this output means, for the color presets of the Colors tab: "up", "down", "neutral" or "accent". Empty = guessed from the role of its style (look), the theme color, the title and the hue (a teal line counts as up). Another value is error CS2014.
lookconst stringdefault ""A style made with style.plot / style.line / style.marker / style.fill (its look, shared and user-editable).
variantconst stringdefault ""The name of one of the style's variants (style.variant).
textstyleinput stringdefault ""The text's style (textstyle.new or input.textstyle): size, font, weight, italic, colour, halo, background.
text_formattinginput intdefault text.format_nonetext.format_bold, text.format_italic or both added.

Example

ChartScriptFragmentOpen in editor
plotchar(close > open, "Up", "*", location.top, color.up)

Since ChartScript 1

#plotshapefunction

Draws a shape on bars where the series is true (or not na).

plotshape(series: bool, { title?: const string = "", style?: input shape_style = shape.xcross, location?: input location = location.abovebar, color?: color = na, offset?: input int = 0, text?: input string = "", textcolor?: color = na, editable?: const bool = true, size?: input size = size.auto, show_last?: const int = na, display?: input display = display.all, format?: const format = na, precision?: const int = na, force_overlay?: const bool = false, role?: const string = "", look?: const string = "", variant?: const string = "", textstyle?: input string = "", text_formatting?: input int = text.format_none })
plotshape(series: float, { title?: const string = "", style?: input shape_style = shape.xcross, location?: input location = location.abovebar, color?: color = na, offset?: input int = 0, text?: input string = "", textcolor?: color = na, editable?: const bool = true, size?: input size = size.auto, show_last?: const int = na, display?: input display = display.all, format?: const format = na, precision?: const int = na, force_overlay?: const bool = false, role?: const string = "", look?: const string = "", variant?: const string = "", textstyle?: input string = "", text_formatting?: input int = text.format_none })
ParameterTypeDescription
seriesboolThe value to draw on each bar.
titleconst stringdefault ""The name shown in the settings, legend and data window.
styleinput shape_styledefault shape.xcrossThe style constant.
locationinput locationdefault location.abovebarWhere the shape sits (location.*).
colorcolordefault naThe colour.
offsetinput intdefault 0Shift the output this many bars to the right (negative: left).
textinput stringdefault ""Text drawn with the shape.
textcolorcolordefault naThe colour of the text.
editableconst booldefault trueAccepted and ignored (styles are always editable).
sizeinput sizedefault size.autoThe number of elements.
show_lastconst intdefault naAccepted and ignored in this version.
displayinput displaydefault display.allWhere the value is shown (display.*).
formatconst formatdefault naThe number format (format.*).
precisionconst intdefault naDecimals shown.
force_overlayconst booldefault falseAccepted and ignored in this version.
roleconst stringdefault ""What the color of this output means, for the color presets of the Colors tab: "up", "down", "neutral" or "accent". Empty = guessed from the role of its style (look), the theme color, the title and the hue (a teal line counts as up). Another value is error CS2014.
lookconst stringdefault ""A style made with style.plot / style.line / style.marker / style.fill (its look, shared and user-editable).
variantconst stringdefault ""The name of one of the style's variants (style.variant).
textstyleinput stringdefault ""The text's style (textstyle.new or input.textstyle): size, font, weight, italic, colour, halo, background.
text_formattinginput intdefault text.format_nonetext.format_bold, text.format_italic or both added.

Example

ChartScriptFragmentOpen in editor
plotshape(ta.crossover(close, ta.sma(close, 20)), "Cross", shape.triangleup, location.belowbar, color.up)

Since ChartScript 1

#secondfunction

The second of the bar open (UTC). The second of a time in a time zone.

second(time: int, { timezone?: string = "UTC" }): int
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns int.

Example

ChartScriptFragmentOpen in editor
const v = second(time, "UTC")

Since ChartScript 1

#stringfunction

Types a string value (string(na)).

string(x: string): string
ParameterTypeDescription
xstringThe value.

Returns string.

Example

ChartScriptFragmentOpen in editor
const s = string(na)

Since ChartScript 1

#timefunction

The open time of the bar (ms, UTC). The open time of the bar in a timeframe, or na outside the session; bars_back reads a chart bar that many bars ago, timeframe_bars_back steps back whole periods of the timeframe.

time({ timeframe?: simple string = "", session?: simple string = "", timezone?: simple string = "UTC", bars_back?: int = 0, timeframe_bars_back?: int = 0 }): int
ParameterTypeDescription
timeframesimple stringdefault ""A timeframe such as "60", "240", "1D" or "1W"; "" is the chart's.
sessionsimple stringdefault ""A session such as "0930-1600" (UTC unless timezone is given).
timezonesimple stringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".
bars_backintdefault 0Chart bars back (0 = this bar).
timeframe_bars_backintdefault 0Periods of the timeframe back (0 = this period).

Returns int.

Example

ChartScriptFragmentOpen in editor
const t = time("1D")

Since ChartScript 1

#time_closefunction

The close time of the bar (ms, UTC). The close time of the bar in a timeframe.

time_close({ timeframe?: simple string = "", session?: simple string = "", timezone?: simple string = "UTC", bars_back?: int = 0, timeframe_bars_back?: int = 0 }): int
ParameterTypeDescription
timeframesimple stringdefault ""A timeframe such as "60", "240", "1D" or "1W"; "" is the chart's.
sessionsimple stringdefault ""A session such as "0930-1600" (UTC unless timezone is given).
timezonesimple stringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".
bars_backintdefault 0Chart bars back (0 = this bar).
timeframe_bars_backintdefault 0Periods of the timeframe back (0 = this period).

Returns int.

Example

ChartScriptFragmentOpen in editor
const t = time_close("1D")

Since ChartScript 1

#timestampfunction

A time in milliseconds (UTC unless a time zone is given).

timestamp(year: int, month: int, day: int, { hour?: int = 0, minute?: int = 0, second?: int = 0 }): int
timestamp(timezone: string, year: int, month: int, day: int, { hour?: int = 0, minute?: int = 0, second?: int = 0 }): int
timestamp(dateString: string): int
ParameterTypeDescription
yearintThe year.
monthintThe month (1-12).
dayintThe day of the month.
hourintdefault 0The hour (0-23).
minuteintdefault 0The minute.
secondintdefault 0The second.
timezonestringAn IANA time zone such as "UTC" or "America/New_York".
dateStringstringA date such as "2024-01-31" or "2024-01-31T09:30:00Z".

Returns int.

Example

ChartScriptFragmentOpen in editor
const t0 = timestamp(2024, 1, 31)

Since ChartScript 1

#weekofyearfunction

The ISO week of the bar open (UTC). The weekofyear of a time in a time zone.

weekofyear(time: int, { timezone?: string = "UTC" }): int
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns int.

Example

ChartScriptFragmentOpen in editor
const v = weekofyear(time, "UTC")

Since ChartScript 1

#yearfunction

The year of the bar open (UTC). The year of a time in a time zone.

year(time: int, { timezone?: string = "UTC" }): int
ParameterTypeDescription
timeintA time in milliseconds since 1970 (UTC).
timezonestringdefault "UTC"An IANA time zone such as "UTC" or "America/New_York".

Returns int.

Example

ChartScriptFragmentOpen in editor
const v = year(time, "UTC")

Since ChartScript 1

#Variables

#bar_indexvariable

The bar number: 0 = the first bar of the run.

bar_index: int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = bar_index

Since ChartScript 1

#closevariable

The close of the bar (the last price on the live bar).

close: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = close

Since ChartScript 1

#dayofmonthvariable

The day of the month of the bar open (UTC). The dayofmonth of a time in a time zone.

dayofmonth(time: int, { timezone?: string = "UTC" }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = dayofmonth

Since ChartScript 1

#highvariable

The high of the bar.

high: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = high

Since ChartScript 1

#hl2variable

(high + low) / 2.

hl2: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = hl2

Since ChartScript 1

#hlc3variable

(high + low + close) / 3.

hlc3: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = hlc3

Since ChartScript 1

#hlcc4variable

(high + low + close + close) / 4.

hlcc4: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = hlcc4

Since ChartScript 1

#hourvariable

The hour of the bar open (UTC). The hour of a time in a time zone.

hour(time: int, { timezone?: string = "UTC" }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = hour

Since ChartScript 1

#last_bar_indexvariable

The bar_index of the last bar.

last_bar_index: int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = last_bar_index

Since ChartScript 1

#last_bar_timevariable

The open time of the last bar of the chart (ms, UTC).

last_bar_time: int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = last_bar_time

Since ChartScript 1

#lowvariable

The low of the bar.

low: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = low

Since ChartScript 1

#minutevariable

The minute of the bar open (UTC). The minute of a time in a time zone.

minute(time: int, { timezone?: string = "UTC" }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = minute

Since ChartScript 1

#monthvariable

The month of the bar open (1-12, UTC). The month of a time in a time zone.

month(time: int, { timezone?: string = "UTC" }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = month

Since ChartScript 1

#ohlc4variable

(open + high + low + close) / 4.

ohlc4: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = ohlc4

Since ChartScript 1

#openvariable

The open of the bar.

open: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = open

Since ChartScript 1

#secondvariable

The second of the bar open (UTC). The second of a time in a time zone.

second(time: int, { timezone?: string = "UTC" }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = second

Since ChartScript 1

#timevariable

The open time of the bar (ms, UTC). The open time of the bar in a timeframe, or na outside the session; bars_back reads a chart bar that many bars ago, timeframe_bars_back steps back whole periods of the timeframe.

time({ timeframe?: simple string = "", session?: simple string = "", timezone?: simple string = "UTC", bars_back?: int = 0, timeframe_bars_back?: int = 0 }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = time

Since ChartScript 1

#time_closevariable

The close time of the bar (ms, UTC). The close time of the bar in a timeframe.

time_close({ timeframe?: simple string = "", session?: simple string = "", timezone?: simple string = "UTC", bars_back?: int = 0, timeframe_bars_back?: int = 0 }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = time_close

Since ChartScript 1

#time_tradingdayvariable

The start of the trading day of the bar (crypto: 00:00 UTC of the bar's day).

time_tradingday: int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = time_tradingday

Since ChartScript 1

#timenowvariable

The current time (ms, UTC); differs between runs.

timenow: int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = timenow

Since ChartScript 1

#volumevariable

The volume of the bar (base units).

volume: float

Type series float.

Example

ChartScriptFragmentOpen in editor
const v = volume

Since ChartScript 1

#weekofyearvariable

The ISO week of the bar open (UTC). The weekofyear of a time in a time zone.

weekofyear(time: int, { timezone?: string = "UTC" }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = weekofyear

Since ChartScript 1

#yearvariable

The year of the bar open (UTC). The year of a time in a time zone.

year(time: int, { timezone?: string = "UTC" }): int

Type series int.

Example

ChartScriptFragmentOpen in editor
const v = year

Since ChartScript 1

#Not supported

#alertconditionfunction

Not supported in ChartScript.

Use alert.on(condition, title, message).

Since ChartScript 1

#studyfunction

Not supported in ChartScript.

Use indicator(...).

Since ChartScript 1

#varipvariable

Not supported in ChartScript.

Not supported: use live state (same meaning: not rolled back between ticks).

Since ChartScript 1

The ChartScript documentation is in English for now; translations will follow.