Skip to main content
Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Namespace: global · Entries: 79

alert (function)

Definition Raises an alert from inside your own logic, with a message you build. It is the one output-shaped function with no top-level rule, so it may be called inside a branch — which is what makes “alert me when this happens” expressible. It fires at most once per bar, only on realtime bars, and only when the script is running as an alert; on historical bars it does nothing. Syntax
Parameters Returns void Example

alertcondition (function)

Definition Declares a condition the platform can offer to the reader. It raises nothing by itself. Unlike alert, it must be called at the top level, and its title and message are const-form — fixed when the script is compiled. Left out, both read na. Syntax
Parameters Returns void Example

barcolor (function)

Definition Recolours the chart’s own price bars. It draws no value of its own. To colour only some bars, vary the colour rather than the call: the colour argument is series-form, while the call has to stay at the top level. Note that every argument here is optional, color included. Syntax
Parameters Returns void Example

bgcolor (function)

Definition Shades the pane’s background. Like barcolor it adds no value to the chart. It differs from barcolor in one way that matters: it takes a force_overlay argument and barcolor does not. Syntax
Parameters Returns void Example

bool (function, overload 1)

Definition Declares a value as a bool. A number becomes false when it is zero and true otherwise, so bool(2) is true. Most functions with a bool argument convert a number the same way; alertcondition does not and needs a bool expression (“The condition argument of alertcondition() must be a boolean series.”). Syntax
Parameters Returns const bool Example

bool (function, overload 2)

Definition Declares a value as a bool. A number becomes false when it is zero and true otherwise, so bool(2) is true. Most functions with a bool argument convert a number the same way; alertcondition does not and needs a bool expression (“The condition argument of alertcondition() must be a boolean series.”). Syntax
Parameters Returns input bool Example

bool (function, overload 3)

Definition Declares a value as a bool. A number becomes false when it is zero and true otherwise, so bool(2) is true. Most functions with a bool argument convert a number the same way; alertcondition does not and needs a bool expression (“The condition argument of alertcondition() must be a boolean series.”). Syntax
Parameters Returns simple bool Example

bool (function, overload 4)

Definition Declares a value as a bool. A number becomes false when it is zero and true otherwise, so bool(2) is true. Most functions with a bool argument convert a number the same way; alertcondition does not and needs a bool expression (“The condition argument of alertcondition() must be a boolean series.”). Syntax
Parameters Returns series bool Example

box (function)

Definition Converts value to the box type. It is used almost only as box(na), to declare a box variable that has no drawing yet, so that its type is known before the first drawing is assigned. Syntax
Parameters Returns series box Example

color (function, overload 1)

Definition Converts a value to a colour. It accepts a colour only. The color namespace holds the functions that build a colour from components or read one apart. Syntax
Parameters Returns const color Example

color (function, overload 2)

Definition Converts a value to a colour. It accepts a colour only. The color namespace holds the functions that build a colour from components or read one apart. Syntax
Parameters Returns input color Example

color (function, overload 3)

Definition Converts a value to a colour. It accepts a colour only. The color namespace holds the functions that build a colour from components or read one apart. Syntax
Parameters Returns simple color Example

color (function, overload 4)

Definition Converts a value to a colour. It accepts a colour only. The color namespace holds the functions that build a colour from components or read one apart. Syntax
Parameters Returns series color Example

dayofmonth (function)

Definition The day of the month of a time you supply. Syntax
Parameters Returns series int Example

dayofweek (function)

Definition The day of the week of a time you supply, as an int series. Uses the same numbering as the dayofweek variable: Sunday 1 through Saturday 7 (dayofweek.sunday … dayofweek.saturday). Syntax
Parameters Returns series int Example

fill (function, overload 1)

Definition Shades the band between two plots, or between two horizontal lines. It has two forms and no mixed one, so you cannot fill between a plot and a level, and like the other output calls it must sit at the top level. The forms differ in argument order, and that is the thing that bites: for two levels the third argument is the colour, for two plots it is the title. Name the arguments and the difference stops mattering. When you fill between two plots, the fill keeps an offset only if both plots carry the same one. Syntax
Parameters Returns void Example

fill (function, overload 2)

Definition Shades the band between two plots, or between two horizontal lines. It has two forms and no mixed one, so you cannot fill between a plot and a level, and like the other output calls it must sit at the top level. The forms differ in argument order, and that is the thing that bites: for two levels the third argument is the colour, for two plots it is the title. Name the arguments and the difference stops mattering. When you fill between two plots, the fill keeps an offset only if both plots carry the same one. Syntax
Parameters Returns void Example

fill (function, overload 3)

Definition Shades the band between two plots, or between two horizontal lines. It has two forms and no mixed one, so you cannot fill between a plot and a level, and like the other output calls it must sit at the top level. The forms differ in argument order, and that is the thing that bites: for two levels the third argument is the colour, for two plots it is the title. Name the arguments and the difference stops mattering. When you fill between two plots, the fill keeps an offset only if both plots carry the same one. Syntax
Parameters Returns void Example

fill (function, overload 4)

Definition Shades the band between two plots, or between two horizontal lines. It has two forms and no mixed one, so you cannot fill between a plot and a level, and like the other output calls it must sit at the top level. The forms differ in argument order, and that is the thing that bites: for two levels the third argument is the colour, for two plots it is the title. Name the arguments and the difference stops mattering. When you fill between two plots, the fill keeps an offset only if both plots carry the same one. Syntax
Parameters Returns void Example

fixnan (function, overload 1)

Definition Takes a series and hands back a series of the same type, with na values dealt with. Four overloads cover bool, colour, float and int. Where nz lets you name the replacement, fixnan takes no second argument. Syntax
Parameters Returns series int Example

fixnan (function, overload 2)

Definition Takes a series and hands back a series of the same type, with na values dealt with. Four overloads cover bool, colour, float and int. Where nz lets you name the replacement, fixnan takes no second argument. Syntax
Parameters Returns series float Example

fixnan (function, overload 3)

Definition Takes a series and hands back a series of the same type, with na values dealt with. Four overloads cover bool, colour, float and int. Where nz lets you name the replacement, fixnan takes no second argument. Syntax
Parameters Returns series bool Example

fixnan (function, overload 4)

Definition Takes a series and hands back a series of the same type, with na values dealt with. Four overloads cover bool, colour, float and int. Where nz lets you name the replacement, fixnan takes no second argument. Syntax
Parameters Returns series color Example

float (function, overload 1)

Definition Converts a value to a float. It accepts an int as well as a float, so it is the conversion to use when a calculation must not round. Syntax
Parameters Returns const float Example

float (function, overload 2)

Definition Converts a value to a float. It accepts an int as well as a float, so it is the conversion to use when a calculation must not round. Syntax
Parameters Returns input float Example

float (function, overload 3)

Definition Converts a value to a float. It accepts an int as well as a float, so it is the conversion to use when a calculation must not round. Syntax
Parameters Returns simple float Example

float (function, overload 4)

Definition Converts a value to a float. It accepts an int as well as a float, so it is the conversion to use when a calculation must not round. Syntax
Parameters Returns series float Example

hline (function)

Definition Draws a horizontal line at a fixed price. The price is input-form, so it cannot follow the data — a line that has to move is a plot, not a level. hline returns a value, which is what lets you pass two levels to fill. Syntax
Parameters Returns series hline Example

hour (function)

Definition The hour of a time you supply. Because the timezone is an argument rather than an assumption, a script can ask the same question in two zones. Syntax
Parameters Returns series int Example

indicator (function)

Definition Declares the script and names it. Put it first. Only title is required, and every parameter is const-form, so none of them can be built from series data or handed a value that came out of an input. Syntax
Parameters Returns void Example

input (function, overload 1)

Definition Declares a setting the reader can change from the chart, picking its kind from the type of the default value you hand it. Six forms exist. Give it a bool and you get a bool back; give it a colour, a float, an int or a string and the same holds. The sixth takes a series and returns a series float, which is how you offer a choice of chart data without naming input.source. There are no bounds and no step here — for those, use input.int or input.float. Syntax
Parameters Returns input color Notes
  • The default defval must be a value: na is rejected with “Argument defval of input() cannot be na.” Any constant expression of type color is accepted, such as color.red or color.new(color.red, 0.5).
Example

input (function, overload 2)

Definition Declares a setting the reader can change from the chart, picking its kind from the type of the default value you hand it. Six forms exist. Give it a bool and you get a bool back; give it a colour, a float, an int or a string and the same holds. The sixth takes a series and returns a series float, which is how you offer a choice of chart data without naming input.source. There are no bounds and no step here — for those, use input.int or input.float. Syntax
Parameters Returns input string Notes
  • The default defval must be a value: na is rejected with “Argument defval of input() cannot be na.” Any constant expression of type string is accepted, such as "a" + "b".
Example

input (function, overload 3)

Definition Declares a setting the reader can change from the chart, picking its kind from the type of the default value you hand it. Six forms exist. Give it a bool and you get a bool back; give it a colour, a float, an int or a string and the same holds. The sixth takes a series and returns a series float, which is how you offer a choice of chart data without naming input.source. There are no bounds and no step here — for those, use input.int or input.float. Syntax
Parameters Returns input int Notes
  • The default defval must be a value: na is rejected with “Argument defval of input() cannot be na.” Any constant expression of type int is accepted, such as -5 or 2 * 3.
Example

input (function, overload 4)

Definition Declares a setting the reader can change from the chart, picking its kind from the type of the default value you hand it. Six forms exist. Give it a bool and you get a bool back; give it a colour, a float, an int or a string and the same holds. The sixth takes a series and returns a series float, which is how you offer a choice of chart data without naming input.source. There are no bounds and no step here — for those, use input.int or input.float. Syntax
Parameters Returns input float Notes
  • The default defval must be a value: na is rejected with “Argument defval of input() cannot be na.” Any constant expression of type float is accepted, such as -5.5 or 2.5 * 2.
Example

input (function, overload 5)

Definition Declares a setting the reader can change from the chart, picking its kind from the type of the default value you hand it. Six forms exist. Give it a bool and you get a bool back; give it a colour, a float, an int or a string and the same holds. The sixth takes a series and returns a series float, which is how you offer a choice of chart data without naming input.source. There are no bounds and no step here — for those, use input.int or input.float. Syntax
Parameters Returns series float Notes
  • The default defval must be a value: na is rejected with “Argument defval of input() cannot be na.” A built-in series such as close or hlc3 is accepted.
Example

input (function, overload 6)

Definition Declares a setting the reader can change from the chart, picking its kind from the type of the default value you hand it. Six forms exist. Give it a bool and you get a bool back; give it a colour, a float, an int or a string and the same holds. The sixth takes a series and returns a series float, which is how you offer a choice of chart data without naming input.source. There are no bounds and no step here — for those, use input.int or input.float. Syntax
Parameters Returns input bool Notes
  • The default defval must be a value: na is rejected with “Argument defval of input() cannot be na.” Any constant expression of type bool is accepted, such as true.
Example

int (function, overload 1)

Definition Converts a value to an int. Four overloads, one per form type; the form you pass in is the form you get back. At compile time the argument may be int or float; floats are truncated toward zero. Syntax
Parameters Returns const int Example

int (function, overload 2)

Definition Converts a value to an int. Four overloads, one per form type; the form you pass in is the form you get back. At compile time the argument may be int or float; floats are truncated toward zero. Syntax
Parameters Returns input int Example

int (function, overload 3)

Definition Converts a value to an int. Four overloads, one per form type; the form you pass in is the form you get back. At compile time the argument may be int or float; floats are truncated toward zero. Syntax
Parameters Returns simple int Example

int (function, overload 4)

Definition Converts a value to an int. Four overloads, one per form type; the form you pass in is the form you get back. At compile time the argument may be int or float; floats are truncated toward zero. Syntax
Parameters Returns series int Example

label (function)

Definition Converts value to the label type. It is used almost only as label(na), to declare a label variable that has no drawing yet, so that its type is known before the first drawing is assigned. Syntax
Parameters Returns series label Example

line (function)

Definition Converts value to the line type. It is used almost only as line(na), to declare a line variable that has no drawing yet, so that its type is known before the first drawing is assigned. Syntax
Parameters Returns series line Example

linefill (function)

Definition Converts value to the linefill type. It is used almost only as linefill(na), to declare a linefill variable that has no drawing yet, so that its type is known before the first drawing is assigned. Syntax
Parameters Returns series linefill Example

minute (function)

Definition The minute of a time you supply. Syntax
Parameters Returns series int Example

month (function)

Definition The month of a time you supply. Same arguments as year: the time is required and the timezone is optional. Syntax
Parameters Returns series int Example

na (function)

Definition Tests whether a value is absent. It takes any type and gives back a bool. This is the test a script needs often, because so much reads na when there is nothing behind it: an instrument property that is unknown, an orderflow figure on a bar with no footprint data, a colour function handed an na. Syntax
Parameters Returns series bool Example

nz (function, overload 1)

Definition Takes a value and an alternative of the same type, and stands in for the value where it is absent. Five overloads, one per data type. The alternative is optional. When it is left out, nz uses 0 for an int or a float, an empty string for a string, false for a bool and #483D8B for a color. Syntax
Parameters Returns series int Example

nz (function, overload 2)

Definition Takes a value and an alternative of the same type, and stands in for the value where it is absent. Five overloads, one per data type. The alternative is optional. When it is left out, nz uses 0 for an int or a float, an empty string for a string, false for a bool and #483D8B for a color. Syntax
Parameters Returns series float Example

nz (function, overload 3)

Definition Takes a value and an alternative of the same type, and stands in for the value where it is absent. Five overloads, one per data type. The alternative is optional. When it is left out, nz uses 0 for an int or a float, an empty string for a string, false for a bool and #483D8B for a color. Syntax
Parameters Returns series string Example

nz (function, overload 4)

Definition Takes a value and an alternative of the same type, and stands in for the value where it is absent. Five overloads, one per data type. The alternative is optional. When it is left out, nz uses 0 for an int or a float, an empty string for a string, false for a bool and #483D8B for a color. Syntax
Parameters Returns series bool Example

nz (function, overload 5)

Definition Takes a value and an alternative of the same type, and stands in for the value where it is absent. Five overloads, one per data type. The alternative is optional. When it is left out, nz uses 0 for an int or a float, an empty string for a string, false for a bool and #483D8B for a color. Syntax
Parameters Returns series color Example

plot (function)

Definition Draws a series on the chart, one point per bar. It is the output function you will reach for first. Eleven parameters, of which only the first is required — every other one carries a default. The call has to sit at the top level of the script: put it inside a branch, a loop or a function of your own and the script is rejected for not being in the global scope. A condition therefore belongs in the color argument, not around the call. Syntax
Parameters Returns series plot Example

plotarrow (function)

Definition Draws an arrow on each bar, sized from a number you supply. It is the odd one out among the markers: plotshape and plotchar take a condition, this takes a value. It also has no location, no shape, no size and no text — where an arrow sits follows from the number. Syntax
Parameters Returns void Example

plotbar (function)

Definition Draws bars from the same four required series that plotcandle takes. The difference is the colouring: one colour for the whole bar, with no separate wick or border. Neither function has an offset parameter at all. Syntax
Parameters Returns void Example

plotcandle (function)

Definition Draws candles from four series of your own rather than from the chart’s bars. All four price series are required. The body, the wick and the border take separate colours, and each of the three is series-form. Syntax
Parameters Returns void Example

plotchar (function, overload 1)

Definition The same marker as plotshape, with one character in place of a shape from the fixed set. It draws exactly one character. Pass a longer string and it is cut to the first character, with no warning and no error, so pass the character you want. series is a float price, and the marker is declared to the chart as absolute-position whatever location is passed. With a location other than location.absolute the call is still accepted and the value is read as a condition (non-zero is true); how the chart places such a marker is not established. Syntax
Parameters Returns void Notes
  • The size argument takes a size.* constant. A string such as “small” still compiles here, with a deprecation warning: write the constant. A string that is not a size name, such as “giant”, stops the compiler with the error “internal validator error”.
Example

plotchar (function, overload 2)

Definition The same marker as plotshape, with one character in place of a shape from the fixed set. It draws exactly one character. Pass a longer string and it is cut to the first character, with no warning and no error, so pass the character you want. series is a boolean condition. With location.absolute the call is also accepted: the value handed to the chart is 1 where the condition is true and 0 where it is false, so the marker is placed at the price 1 or 0, which is rarely wanted; use a float series for an absolute position. Syntax
Parameters Returns void Notes
  • The size argument takes a size.* constant. A string such as “small” still compiles here, with a deprecation warning: write the constant.
Example

plotshape (function, overload 1)

Definition Marks the bars on which a condition holds, using a shape from a fixed set. The condition is the first argument, which is how you mark some bars and not others without moving the call: like every chart-output function it must be called at the top level. series is a boolean condition. With location.absolute the call is also accepted: the value handed to the chart is 1 where the condition is true and 0 where it is false, so the marker is placed at the price 1 or 0, which is rarely wanted; use a float series for an absolute position. Syntax
Parameters Returns void Notes
  • The size argument takes a size.* constant. A string such as “small” still compiles here, with a deprecation warning: write the constant.
Example

plotshape (function, overload 2)

Definition Marks the bars on which a condition holds, using a shape from a fixed set. The condition is the first argument, which is how you mark some bars and not others without moving the call: like every chart-output function it must be called at the top level. series is a float price, and the marker is declared to the chart as absolute-position whatever location is passed. With a location other than location.absolute the call is still accepted and the value is read as a condition (non-zero is true); how the chart places such a marker is not established. Syntax
Parameters Returns void Notes
  • The size argument takes a size.* constant. A string such as “small” still compiles here, with a deprecation warning: write the constant.
Example

polyline (function)

Definition Converts value to the polyline type. It is used almost only as polyline(na), to declare a polyline variable that has no drawing yet, so that its type is known before the first drawing is assigned. Syntax
Parameters Returns series polyline Example

second (function)

Definition The second of a time you supply. Syntax
Parameters Returns series int Example

strategy (function)

Definition Declares the script as a strategy: a script that places simulated orders and reports their performance. It is used in place of indicator, as the first statement of the script. Besides the display settings it shares with indicator, it sets how orders are sized and filled: initial_capital, default_qty_type and default_qty_value for position size, commission_type and commission_value for costs, pyramiding for how many entries in the same direction are allowed, and process_orders_on_close, calc_on_order_fills and calc_on_every_tick for when orders are evaluated. Syntax
GoCharting is a charting and analytics tool. This is not investment advice. Trading and investing carry a high risk of loss and are not suitable for everyone. You can lose some or all of your money.
Parameters Returns void Example

string (function, overload 1)

Definition Converts a value to a string. It accepts a string only, so it changes the form and not the data type. To render a number as text, look to the str namespace. Syntax
Parameters Returns const string Example

string (function, overload 2)

Definition Converts a value to a string. It accepts a string only, so it changes the form and not the data type. To render a number as text, look to the str namespace. Syntax
Parameters Returns input string Example

string (function, overload 3)

Definition Converts a value to a string. It accepts a string only, so it changes the form and not the data type. To render a number as text, look to the str namespace. Syntax
Parameters Returns simple string Example

string (function, overload 4)

Definition Converts a value to a string. It accepts a string only, so it changes the form and not the data type. To render a number as text, look to the str namespace. Syntax
Parameters Returns series string Example

table (function)

Definition Converts value to the table type. It is used almost only as table(na), to declare a table variable that has no drawing yet, so that its type is known before the first drawing is assigned. Syntax
Parameters Returns series table Example

time (function, overload 1)

Definition Returns the opening time of the current bar in UNIX milliseconds, measured on interval rather than on the chart’s own bars. With session, it returns na when the opening time of the interval bar is outside that session. The session is tested against the start of the interval bar, not against the opening time of the chart bar: with interval “1D” the tested time is the start of the day, so a session that does not contain midnight, such as “0930-1600”, gives na on every bar of an intraday chart. Interval bars are cut on the clock in that time zone, not aligned to the chart’s bars: with interval “1h”, a chart bar opening at 09:30 is tested as 09:00, so an interval equal to the chart’s own interval tests the chart bar’s own time only when the chart’s bars start on those clock boundaries. timezone sets the time zone the interval and the session are read in. bars_back and interval_bars_back look back a number of chart bars or interval bars respectively. Syntax
Parameters Returns series int Example

time (function, overload 2)

Definition Returns the opening time of the current bar in UNIX milliseconds, measured on interval rather than on the chart’s own bars. With session, it returns na when the opening time of the interval bar is outside that session. The session is tested against the start of the interval bar, not against the opening time of the chart bar: with interval “1D” the tested time is the start of the day, so a session that does not contain midnight, such as “0930-1600”, gives na on every bar of an intraday chart. Interval bars are cut on the clock in that time zone, not aligned to the chart’s bars: with interval “1h”, a chart bar opening at 09:30 is tested as 09:00, so an interval equal to the chart’s own interval tests the chart bar’s own time only when the chart’s bars start on those clock boundaries. timezone sets the time zone the interval and the session are read in. bars_back and interval_bars_back look back a number of chart bars or interval bars respectively. Syntax
Parameters Returns series int Notes
  • timezone takes UTC/GMT notation such as “UTC-5” or “GMT+0530”, or an IANA time zone name. A name that cannot be read is ignored and the exchange’s time zone is used, with no error.
Example

time_close (function, overload 1)

Definition Returns the closing time of the current bar in UNIX milliseconds, measured on interval. It takes the same arguments as time. With session it returns na when the opening time of the interval bar is outside the session, tested as for time: against the start of the interval bar, not the opening time of the chart bar. Syntax
Parameters Returns series int Example

time_close (function, overload 2)

Definition Returns the closing time of the current bar in UNIX milliseconds, measured on interval. It takes the same arguments as time. With session it returns na when the opening time of the interval bar is outside the session, tested as for time: against the start of the interval bar, not the opening time of the chart bar. Syntax
Parameters Returns series int Notes
  • timezone takes UTC/GMT notation such as “UTC-5” or “GMT+0530”, or an IANA time zone name. A name that cannot be read is ignored and the exchange’s time zone is used, with no error.
Example

timestamp (function, overload 1)

Definition Assembles a time from its parts - the other direction from the eight functions that take a time apart. The parts are read as a wall-clock time in the exchange’s own timezone, and the result is milliseconds from the Unix epoch, matching time and timenow. Two forms. Pass series arguments and you get a series int; pass simple arguments and you get a simple int. In both forms the year, the month and the day are required, and the hour, the minute and the second may be left out, each defaulting to zero. A date string, as in timestamp("2024-01-01"), is also accepted, and so is a leading timezone string, as in timestamp("UTC", 2024, 1, 1). A date string is read as UTC unless it carries its own zone ("2024-01-01T09:30:00-05:00"), not in the exchange’s timezone, and a string that cannot be read gives na. Syntax
Parameters Returns const int Notes
  • The result is worked out when the script runs. Where a value is needed when the script is compiled, such as the default of input.time, a timestamp call gives na, and adding the script to the chart fails with “Argument defval of input.time() cannot be na.”: write the time as a number of milliseconds instead.
Example

timestamp (function, overload 2)

Definition Assembles a time from its parts - the other direction from the eight functions that take a time apart. The parts are read as a wall-clock time in the exchange’s own timezone, and the result is milliseconds from the Unix epoch, matching time and timenow. Two forms. Pass series arguments and you get a series int; pass simple arguments and you get a simple int. In both forms the year, the month and the day are required, and the hour, the minute and the second may be left out, each defaulting to zero. A date string, as in timestamp("2024-01-01"), is also accepted, and so is a leading timezone string, as in timestamp("UTC", 2024, 1, 1). A date string is read as UTC unless it carries its own zone ("2024-01-01T09:30:00-05:00"), not in the exchange’s timezone, and a string that cannot be read gives na. Syntax
Parameters Returns series int Notes
  • The result is worked out when the script runs. Where a value is needed when the script is compiled, such as the default of input.time, a timestamp call gives na, and adding the script to the chart fails with “Argument defval of input.time() cannot be na.”: write the time as a number of milliseconds instead.
Example

timestamp (function, overload 3)

Definition Assembles a time from its parts - the other direction from the eight functions that take a time apart. The parts are read as a wall-clock time in the exchange’s own timezone, and the result is milliseconds from the Unix epoch, matching time and timenow. Two forms. Pass series arguments and you get a series int; pass simple arguments and you get a simple int. In both forms the year, the month and the day are required, and the hour, the minute and the second may be left out, each defaulting to zero. A date string, as in timestamp("2024-01-01"), is also accepted, and so is a leading timezone string, as in timestamp("UTC", 2024, 1, 1). A date string is read as UTC unless it carries its own zone ("2024-01-01T09:30:00-05:00"), not in the exchange’s timezone, and a string that cannot be read gives na. Syntax
Parameters Returns simple int Notes
  • The result is worked out when the script runs. Where a value is needed when the script is compiled, such as the default of input.time, a timestamp call gives na, and adding the script to the chart fails with “Argument defval of input.time() cannot be na.”: write the time as a number of milliseconds instead.
Example

timestamp (function, overload 4)

Definition Assembles a time from its parts - the other direction from the eight functions that take a time apart. The parts are read as a wall-clock time in the exchange’s own timezone, and the result is milliseconds from the Unix epoch, matching time and timenow. Two forms. Pass series arguments and you get a series int; pass simple arguments and you get a simple int. In both forms the year, the month and the day are required, and the hour, the minute and the second may be left out, each defaulting to zero. A date string, as in timestamp("2024-01-01"), is also accepted, and so is a leading timezone string, as in timestamp("UTC", 2024, 1, 1). A date string is read as UTC unless it carries its own zone ("2024-01-01T09:30:00-05:00"), not in the exchange’s timezone, and a string that cannot be read gives na. Syntax
Parameters Returns series int Notes
  • The result is worked out when the script runs. Where a value is needed when the script is compiled, such as the default of input.time, a timestamp call gives na, and adding the script to the chart fails with “Argument defval of input.time() cannot be na.”: write the time as a number of milliseconds instead.
Example

timestamp (function, overload 5)

Definition Assembles a time from its parts - the other direction from the eight functions that take a time apart. The parts are read as a wall-clock time in the exchange’s own timezone, and the result is milliseconds from the Unix epoch, matching time and timenow. Two forms. Pass series arguments and you get a series int; pass simple arguments and you get a simple int. In both forms the year, the month and the day are required, and the hour, the minute and the second may be left out, each defaulting to zero. A date string, as in timestamp("2024-01-01"), is also accepted, and so is a leading timezone string, as in timestamp("UTC", 2024, 1, 1). A date string is read as UTC unless it carries its own zone ("2024-01-01T09:30:00-05:00"), not in the exchange’s timezone, and a string that cannot be read gives na. Syntax
Parameters Returns simple int Notes
  • The result is worked out when the script runs. Where a value is needed when the script is compiled, such as the default of input.time, a timestamp call gives na, and adding the script to the chart fails with “Argument defval of input.time() cannot be na.”: write the time as a number of milliseconds instead.
Example

timestamp (function, overload 6)

Definition Assembles a time from its parts - the other direction from the eight functions that take a time apart. The parts are read as a wall-clock time in the exchange’s own timezone, and the result is milliseconds from the Unix epoch, matching time and timenow. Two forms. Pass series arguments and you get a series int; pass simple arguments and you get a simple int. In both forms the year, the month and the day are required, and the hour, the minute and the second may be left out, each defaulting to zero. A date string, as in timestamp("2024-01-01"), is also accepted, and so is a leading timezone string, as in timestamp("UTC", 2024, 1, 1). A date string is read as UTC unless it carries its own zone ("2024-01-01T09:30:00-05:00"), not in the exchange’s timezone, and a string that cannot be read gives na. Syntax
Parameters Returns series int Notes
  • The result is worked out when the script runs. Where a value is needed when the script is compiled, such as the default of input.time, a timestamp call gives na, and adding the script to the chart fails with “Argument defval of input.time() cannot be na.”: write the time as a number of milliseconds instead.
Example

weekofyear (function)

Definition The week of the year of a time you supply. It is the one member of this family with no variable form: to get the current bar’s week, pass the bar’s time. Syntax
Parameters Returns series int Example

year (function)

Definition The year of a time you supply. Eight functions of this shape exist, each taking a time and an optional timezone, so only the time is required. The variable of the same name reads the current bar instead. Syntax
Parameters Returns series int Example