Sidechair

Pine Script functions

Browse the reference

472 built-in functions, grouped by namespace.

Open the Pine Editor

Top-level functions

alert()
Sends an alert message when the line runs on a bar, if an alert on the script is active.
alertcondition()
Declares a named alert condition that can be picked when creating an alert on an indicator.
barcolor()
Recolors the chart's own price bars or candles, evaluated per bar.
bgcolor()
Colors the background behind a bar, evaluated per bar, with transparency to keep the price visible.
bool()
Converts a number to true or false: 0 and na give false, everything else gives true.
box()
Casts a value to the box type, mainly to give a variable a typed na before its first rectangle exists.
color()
Converts a value to the color type; color(na) gives a na that is typed as a colour.
dayofmonth()
Returns the day of the month of a UNIX timestamp, from 1 to 31, in the exchange or a chosen time zone.
dayofweek()
Returns the weekday of a UNIX timestamp, from 1 for Sunday to 7 for Saturday, in the exchange or a chosen time zone.
fill()
Shades the area between two plots or two horizontal lines with a solid or gradient color.
fixnan()
Fills each na in a series with the most recent value that was not na.
float()
Converts a value to a float; float(na) gives a na that is typed as a float.
hline()
Draws a horizontal line across the whole pane at a fixed price, and returns a handle that fill can use.
hour()
Returns the hour of day of a UNIX timestamp, from 0 to 23, in the exchange or a chosen time zone.
indicator()
Declares the script as an indicator and sets its title, pane placement, display format and drawing limits.
input()
Adds a setting to the script and returns its value; the setting's type follows the type of the default.
int()
Converts a number to an int by dropping the fraction, and keeps na as na.
label()
Gives a label-typed na that a variable can start from before any label exists.
library()
Declares the script as a library: a collection of exported functions, types and constants other scripts import.
line()
Casts a value to the line type, mainly so that na can be given a line type.
linefill()
Casts a value to the linefill type, mainly so that na can be given a linefill type.
max_bars_back()
Sets how many past bars of a variable's history the script keeps available for the [] operator.
minute()
Returns the minute of the hour of a UNIX timestamp, from 0 to 59, in the exchange or a chosen time zone.
month()
Returns the month number of a UNIX timestamp, from 1 for January to 12, in the exchange or a chosen time zone.
na()
Tests a value for na and returns true when it is missing, the only reliable way to check.
nz()
Replaces na with 0, or with a value you give, and returns any other value unchanged.
plot()
Draws a series on the chart as a line, histogram, columns, area, circles or steps, and returns a plot handle that fill can use.
plotarrow()
Draws an up arrow where series is positive and a down arrow where it is negative, with length scaled by the value.
plotbar()
Draws OHLC bars from four series for open, high, low and close, colored per bar.
plotcandle()
Draws candlesticks from four series for open, high, low and close, with separate colors for body, wick and border.
plotchar()
Marks bars with a single character, drawn where a condition is true or at an absolute price.
plotshape()
Marks bars with a symbol such as a triangle, label or cross, drawn where a condition is true or at an absolute price.
second()
Returns the second of the minute of a UNIX timestamp, from 0 to 59, in the exchange or a chosen time zone.
string()
Converts a value to the string type; string(na) gives a na that is typed as a string.
table()
table(x) gives na a table type, so a variable can be declared as a table before table.new() fills it.
time()
Returns the opening time of the current bar or period, or na outside the trading session you give.
time_close()
Returns the closing time of the current bar or period, or na outside the trading session you give.
timestamp()
Returns the UNIX timestamp in milliseconds for a date and time, or parsed from a date string.
weekofyear()
Returns the week number of the year of a UNIX timestamp, in the exchange or a chosen time zone.
year()
Returns the calendar year of a UNIX timestamp in milliseconds, in the exchange or a chosen time zone.

array.*

array.abs()
Returns a new array holding the absolute value of every item in a numeric array.
array.avg()
Returns the arithmetic mean of the numbers in an array.
array.binary_search()
Looks up a value in an array sorted from low to high and returns its index, or -1 when it is missing.
array.binary_search_leftmost()
Searches an ascending array and returns the index of the first copy of a value, or of the nearest smaller item.
array.binary_search_rightmost()
Searches an ascending array and returns the index of the last copy of a value, or of the nearest larger item.
array.clear()
Removes every item from an array, leaving it empty.
array.concat()
Appends all items of a second array to the end of the first and returns the first array.
array.copy()
Returns a new array with the same items as the given one, so later changes to either do not affect the other.
array.covariance()
Returns the covariance of two equally long numeric arrays: how much their items move together.
array.every()
Returns true when every item in a bool array is true.
array.fill()
Sets every item in an array, or in a range of it, to one value.
array.first()
Returns the first item of an array without removing it.
array.from()
Builds an array from the values you list, taking the item type from them.
array.get()
Returns the item stored at a position in an array, counting from 0, or from the end when the index is negative.
array.includes()
Returns true when a value occurs anywhere in an array.
array.indexof()
Finds the first position holding a value and returns it, or -1 when the value is not in the array.
array.insert()
Inserts a value at a chosen position in an array, pushing the items from that position onward up by one.
array.join()
Combines the items of an array into one string, with a separator between them.
array.last()
Returns the last item of an array without removing it.
array.lastindexof()
Finds the last position holding a value and returns it, or -1 when the value is not in the array.
array.max()
Returns the largest number in an array, or the nth largest when you pass nth.
array.median()
Returns the middle value of the numbers in an array once they are sorted.
array.min()
Returns the smallest number in an array, or the nth smallest when you pass nth.
array.mode()
Returns the number that occurs most often in an array.
array.new()
Builds an array of any element type named in angle brackets, filled to a chosen size with one starting value.
array.new_bool()
Builds an array of true and false flags, with every slot off unless a starting value says otherwise.
array.new_box()
Builds an array to hold references to drawn boxes, so later bars can extend, recolor or retire each zone.
array.new_color()
Builds an array of colors that works as a palette, read back by index to color plots and backgrounds.
array.new_float()
Builds an array of floats for prices, ratios and other decimal values, empty by default or pre-filled to a size.
array.new_int()
Builds an array of whole numbers for counters, bar indexes and timestamps, empty by default or pre-filled to a size.
array.new_label()
Builds an array to hold references to drawn labels, so later bars can recolor, retext or remove them.
array.new_line()
Builds an array to hold references to drawn lines, so later bars can stretch, recolor or delete them.
array.new_linefill()
Builds an array to hold references to line fills, kept beside the lines each fill joins.
array.new_string()
Builds an array of text items, with na as the default so blank slots need an explicit empty string.
array.new_table()
Builds an array to hold references to tables, so a script can reach each dashboard by index.
array.percentile_linear_interpolation()
Returns the value at a given percentage of the sorted numbers, interpolating between neighbouring items.
array.percentile_nearest_rank()
Returns the value at a given percentage of the sorted numbers, always one of the items in the array.
array.percentrank()
Returns the share of the other items that are at or below the item at a given index, as a percentage.
array.pop()
Removes the last item of an array and returns it.
array.push()
Appends a value at the end of an array, so the array grows by one item.
array.range()
Returns the gap between the largest and the smallest number in an array.
array.remove()
Deletes the item at a position and returns it; later items move down to fill the gap.
array.reverse()
Reverses the order of the items in an array, in place.
array.set()
Replaces the item at a position in an array with a new value.
array.shift()
Removes the first item of an array and returns it; every other item moves down one position.
array.size()
Returns how many items an array holds right now.
array.slice()
Returns the items from index_from up to, but not including, index_to as a smaller array.
array.some()
Returns true when at least one item in a bool array is true.
array.sort()
Sorts an array of numbers or strings in place, ascending by default or descending when asked.
array.sort_indices()
Returns the positions of an array's items in sorted order, leaving the array itself untouched.
array.standardize()
Returns a new array where each number is expressed as its distance from the mean in standard deviations.
array.stdev()
Returns the standard deviation of the numbers in an array, in the same unit as the numbers.
array.sum()
Adds up all numbers in an array and returns the total.
array.unshift()
Inserts a value at the start of an array; every existing item moves up one position.
array.variance()
Returns how widely the numbers in an array spread around their mean, as the average squared distance.

box.*

box.copy()
Draws a second box with the same edges, fill, outline, extension and text as an existing one, and returns it.
box.delete()
Removes a box from the chart; the variable that held it keeps pointing at the removed rectangle.
box.get_bottom()
Returns the price of the bottom edge of a box, exactly as it was last stored.
box.get_left()
Returns the left edge of a box: a bar index, or a timestamp in milliseconds for a box placed with xloc.bar_time.
box.get_right()
Returns the right edge of a box: a bar index, or a timestamp in milliseconds for a box placed with xloc.bar_time.
box.get_top()
Returns the price of the top edge of a box, exactly as it was last stored.
box.new()
Draws a rectangle from two bar positions and two prices, with optional fill, outline, extension and centred text, and returns a handle to it.
box.set_bgcolor()
Changes the fill color of a box, or removes the fill when na is passed.
box.set_border_color()
Changes the color of a box's outline, or removes the outline when na is passed.
box.set_border_style()
Changes a box's outline to solid, dashed or dotted.
box.set_border_width()
Changes the thickness of a box's outline in pixels, with 0 hiding the outline.
box.set_bottom()
Moves the bottom edge of a box to a new price, leaving the top edge and both sides unchanged.
box.set_bottom_right_point()
Moves the bottom-right corner of a box to a position held in a chart.point.
box.set_extend()
Stretches a box to the left edge, the right edge or both edges of the chart pane, or switches the stretch off.
box.set_left()
Moves the left edge of a box to a new bar or timestamp and leaves the other three edges where they are.
box.set_lefttop()
Moves the top-left corner of a box in one call, changing the left edge and the top edge together.
box.set_right()
Moves the right edge of a box to a new bar or timestamp, so the zone ends earlier or later.
box.set_rightbottom()
Moves the bottom-right corner of a box in one call, changing the right edge and the bottom edge together.
box.set_text()
Replaces the text drawn inside a box; an empty string clears it.
box.set_text_color()
Changes the color of the text inside a box without touching its fill or outline.
box.set_text_font_family()
Chooses a proportional or a monospace typeface for the text inside a box.
box.set_text_formatting()
Makes the text inside a box bold, italic, both or plain.
box.set_text_halign()
Sets where text sits across a box's width: against the left edge, in the middle or against the right edge.
box.set_text_size()
Changes the type size of the text inside a box to one of the named size constants.
box.set_text_valign()
Sets where text sits along a box's height: under the top border, in the middle or above the bottom border.
box.set_text_wrap()
Chooses whether text inside a box breaks into lines to fit the box's width or stays on one line.
box.set_top()
Moves the top edge of a box to a new price, so the box grows taller or shorter from above.
box.set_top_left_point()
Moves the top-left corner of a box to a position held in a chart.point.
box.set_xloc()
Replaces both horizontal edges of a box and switches them between bar indexes and millisecond timestamps in one call.

chart.*

chart.copy()
Method-call spelling of chart.point.copy(): point.copy() returns a new chart.point with the same three fields.
chart.point.copy()
Returns a new chart point with the same index, time and price as an existing one.
chart.point.from_index()
Creates a chart point from a bar index and a price, with the time left empty.
chart.point.from_time()
Creates a chart point from a timestamp and a price, with the bar index left empty.
chart.point.new()
Creates a chart point from a time, a bar index and a price you supply.
chart.point.now()
Creates a chart point at the bar being processed, priced at the close unless you pass a price.

color.*

color.b()
Returns the blue channel of a color as a number from 0 to 255.
color.from_gradient()
Returns a color blended between two colors according to where a value falls between two limits.
color.g()
Returns the green channel of a color as a number from 0 to 255.
color.new()
Returns a color with the same red, green and blue as the one you pass but a new transparency.
color.r()
Returns the red channel of a color as a number from 0 to 255.
color.rgb()
Builds a color from red, green and blue values from 0 to 255, with optional transparency.
color.t()
Returns how transparent a color is, from 0 for solid to 100 for invisible.

footprint.*

footprint.buy_volume()
The buy volume of a footprint bar: volume traded at the ask, summed over every price row.
footprint.delta()
The delta of a footprint bar: buy volume minus sell volume over the whole bar.
footprint.get_row_by_price()
Returns the volume row that contains a given price on a footprint bar.
footprint.poc()
The point of control of a footprint bar: the price row that traded the most volume.
footprint.rows()
Returns every price row of a footprint bar as an array of volume_row values.
footprint.sell_volume()
The sell volume of a footprint bar: volume traded at the bid, summed over every price row.
footprint.total_volume()
The total volume traded on a footprint bar: the sum of the buy and sell volume across every price row.
footprint.vah()
The value area high of a footprint bar: the top row of the area holding the chosen share of the bar's volume.
footprint.val()
The value area low of a footprint bar: the bottom row of the area holding the chosen share of the bar's volume.

input.*

input.bool()
Adds a checkbox setting to the script and returns true or false.
input.color()
Adds a color setting to the script and returns the chosen color, including its transparency.
input.enum()
Adds a dropdown setting built from an enum type and returns the chosen enum member.
input.float()
Adds a decimal-number setting to the script, optionally limited by minimum, maximum and step or chosen from a list.
input.int()
Adds an integer setting to the script, optionally limited by minimum, maximum and step or chosen from a list.
input.price()
Adds a price-level setting to the script and returns the chosen number.
input.session()
Adds a session setting to the script and returns it as text such as "0930-1600".
input.source()
Adds a price-source dropdown to the script and returns the chosen series, such as close or hl2.
input.string()
Adds a text setting to the script, either free text or a dropdown of fixed choices.
input.symbol()
Adds a symbol setting to the script and returns the ticker text the user entered.
input.text_area()
Adds a multi-line text setting to the script and returns its content as one string.
input.time()
Adds a date and time setting to the script and returns it as a timestamp in milliseconds since 1970.
input.timeframe()
Adds a timeframe setting to the script and returns it as a string such as "D" or "60".

label.*

label.copy()
Makes a second label with the position, text, colors, style, size and tooltip of an existing one.
label.delete()
Removes a label from the chart, and does nothing when the handle is na or already deleted.
label.get_text()
Returns the text a label currently shows, so a script can test or extend it without a second string variable.
label.get_x()
Returns a label's x coordinate: a bar index, or a millisecond timestamp for a label placed by time.
label.get_y()
Returns the price a label was given, which is the level it points at when the label sits at a price.
label.new()
Draws a text label at a bar and price, with a chosen shape, colors and size, and returns a handle to it.
label.set_color()
Changes the fill color of a label's bubble or marker.
label.set_point()
Moves a label to a position given as a chart.point, replacing x and y in one value.
label.set_size()
Changes the size of a label's text, and of its marker when the style is a shape.
label.set_style()
Switches a label between bubbles with a pointer, markers and bare text.
label.set_text()
Replaces the words in a label, leaving its position, colors and style as they were.
label.set_text_font_family()
Chooses a proportional or a monospace typeface for a label's text.
label.set_text_formatting()
Makes a label's text bold, italic, both, or plain.
label.set_textalign()
Sets how the lines of a multi-line label line up with each other: left, center or right.
label.set_textcolor()
Changes the color of a label's text without touching its fill.
label.set_tooltip()
Sets the pop-up text that appears when the pointer rests on a label.
label.set_x()
Moves a label sideways to a new bar or time, keeping its price where it is.
label.set_xloc()
Re-aims a label's x at a bar index or a timestamp, setting the position and the scale together.
label.set_xy()
Moves a label to a new bar and a new price in one call.
label.set_y()
Moves a label up or down to a new price, keeping its bar where it is.
label.set_yloc()
Switches a label between sitting at a price and hugging the bar's high or low.

line.*

line.copy()
Duplicates a line, with its points, extend, color, style and width, as a new independent line.
line.delete()
Takes a line off the chart and frees its place in the drawing limit.
line.get_price()
Evaluates the straight line through two points at any bar and returns its price there.
line.get_x1()
Returns where a line starts on the x axis, as a bar index or a millisecond timestamp.
line.get_x2()
Returns where a line ends on the x axis, as a bar index or a millisecond timestamp.
line.get_y1()
Returns the price stored for the first end point of a line.
line.get_y2()
Returns the price stored for the second end point of a line.
line.new()
Draws a straight segment, ray or full line between two points and returns the line object.
line.set_color()
Recolors a whole line, or hides it with na.
line.set_extend()
Chooses how far a line runs past its points: not at all, left, right or both.
line.set_first_point()
Replaces the start of a line with a chart.point, bar and price together.
line.set_second_point()
Replaces the end of a line with a chart.point, bar and price together.
line.set_style()
Switches a line between solid, dashed, dotted and arrow-headed drawing.
line.set_width()
Changes the stroke thickness of a line in pixels.
line.set_x1()
Moves only the start of a line sideways, along the bar axis.
line.set_x2()
Moves only the end of a line sideways, along the bar axis.
line.set_xloc()
Rewrites both x values of a line and switches them between bar indexes and timestamps.
line.set_xy1()
Relocates the start of a line to a new bar and price in one call.
line.set_xy2()
Relocates the end of a line to a new bar and price in one call.
line.set_y1()
Moves only the starting price of a line, up or down.
line.set_y2()
Moves only the ending price of a line, up or down.

linefill.*

linefill.delete()
Clears the shading between two lines and leaves the lines themselves on the chart.
linefill.get_line1()
Returns the line that forms the first edge of a fill.
linefill.get_line2()
Returns the line that forms the second edge of a fill.
linefill.new()
Shades the area between two existing lines and returns the fill object.
linefill.set_color()
Recolors the shaded band between a fill's two lines without touching the lines.

log.*

log.error()
Writes an error to the Pine Logs panel and lets the script keep running, unlike runtime.error.
log.info()
Writes an informational message to the Pine Logs panel, with the bar it came from. Nothing is drawn on the chart.
log.warning()
Writes a warning to the Pine Logs panel, for something unexpected that the script can carry on through.

map.*

map.clear()
Removes every pair from a map, leaving it empty.
map.contains()
Returns true when a key is present in a map.
map.copy()
Returns a new map with the same pairs, so changes to one map no longer affect the other.
map.get()
Returns the value stored under a key, or na when the key is not in the map.
map.keys()
Returns the keys of a map as a new array, in the order they were added.
map.new()
Creates an empty map for the key type and value type given in angle brackets.
map.put()
Stores a value under a key, adding the pair or replacing the old value, and returns the previous value.
map.put_all()
Copies every pair of a second map into the first, overwriting values for keys that both maps have.
map.remove()
Deletes a pair by key and returns the value it held, or na when the key was not there.
map.size()
Counts the key and value pairs a map holds at this moment.
map.values()
Returns the values of a map as a new array, in the order their keys were added.

math.*

math.abs()
Returns the absolute value of a number: its distance from zero, never negative.
math.acos()
Returns the arccosine of a number, an angle in radians whose cosine is that number.
math.asin()
Returns the arcsine of a number, an angle in radians whose sine is that number.
math.atan()
Returns the arctangent of a number, an angle in radians whose tangent is that number.
math.avg()
Returns the arithmetic mean of the numbers you pass.
math.ceil()
Rounds a number up to the next whole number; a number that is already whole stays as it is.
math.cos()
Returns the cosine of an angle given in radians.
math.exp()
Returns e raised to the power of a number, the inverse of math.log.
math.floor()
Rounds a number down to the whole number at or below it; a whole number stays as it is.
math.log()
Returns the natural logarithm of a number: the power e must be raised to in order to get it.
math.log10()
Returns the base-10 logarithm of a number: the power of 10 that gives it.
math.max()
Returns the largest of the numbers you pass; na if any of them is na.
math.min()
Returns the smallest of the numbers you pass; na if any of them is na.
math.pow()
Returns base raised to the power of exponent.
math.random()
Returns a pseudo-random number from min up to but not including max; a seed makes the sequence repeatable.
math.round()
Rounds a number to the nearest whole number, or to a given count of decimal places.
math.round_to_mintick()
Rounds a number to the nearest multiple of the symbol's minimum price step.
math.sign()
Returns -1 for a negative number, 1 for a positive number and 0 for zero.
math.sin()
Returns the sine of an angle given in radians.
math.sqrt()
Returns the square root of a number; na for a negative number.
math.sum()
Returns the sum of the last length values of source, na until the window is full.
math.tan()
Returns the tangent of an angle given in radians.
math.todegrees()
Converts an angle from radians to degrees.
math.toradians()
Converts an angle from degrees to radians.

matrix.*

matrix.add_col()
Inserts an array as a new column of a matrix, at the end unless you give a position.
matrix.add_row()
Inserts an array as a new row of a matrix, at the end unless you give a position.
matrix.avg()
Returns the mean of all items in a matrix.
matrix.col()
Returns one column of a matrix as a new array.
matrix.columns()
Returns how many values each row of a matrix holds, which is the width of the matrix.
matrix.concat()
Appends the rows of a second matrix below the first and returns the first matrix.
matrix.copy()
Returns a new matrix with the same shape and items, independent of the original.
matrix.det()
Returns the determinant of a square matrix.
matrix.diff()
Subtracts one matrix from another item by item, or subtracts one number from every item.
matrix.eigenvalues()
Returns the eigenvalues of a square matrix as an array of floats.
matrix.eigenvectors()
Returns the eigenvectors of a square matrix, one in each column of a new matrix.
matrix.elements_count()
Returns how many items a matrix holds in total: rows times columns.
matrix.fill()
Sets every item of a matrix, or of a block inside it, to one value.
matrix.get()
Returns the item in a given row and column of a matrix.
matrix.inv()
Returns the inverse of a square matrix, the matrix that multiplies with it to give the identity.
matrix.is_antidiagonal()
Returns true when every item off the anti-diagonal, from top right to bottom left, is zero.
matrix.is_antisymmetric()
Returns true when a matrix equals the negative of its transpose.
matrix.is_binary()
Returns true when every item in a matrix is either 0 or 1.
matrix.is_diagonal()
Returns true when every item off the main diagonal is zero.
matrix.is_identity()
Returns true when a matrix is square with ones on the main diagonal and zeros everywhere else.
matrix.is_square()
Returns true when a matrix has as many rows as columns.
matrix.is_stochastic()
Returns true when a matrix has no negative items and every row adds up to 1.
matrix.is_symmetric()
Returns true when a matrix equals its own transpose.
matrix.is_triangular()
Returns true when all items above the main diagonal are zero, or all items below it are zero.
matrix.is_zero()
Returns true when every item in a matrix is 0.
matrix.kron()
Returns the Kronecker product of two matrices: a block matrix with a scaled copy of the second for every item of the first.
matrix.max()
Returns the largest item in a matrix.
matrix.median()
Returns the middle value of all items in a matrix once they are sorted.
matrix.min()
Returns the smallest item in a matrix.
matrix.mode()
Returns the value that occurs most often in a matrix.
matrix.mult()
Multiplies a matrix by another matrix, by an array of numbers, or by a single number.
matrix.new()
Creates a matrix with a given number of rows and columns, every cell holding the same starting value.
matrix.pinv()
Returns the pseudoinverse of a matrix of any shape, the closest thing to an inverse when none exists.
matrix.pow()
Raises a square matrix to a whole-number power by repeated multiplication.
matrix.rank()
Returns the rank of a matrix: how many of its rows or columns are independent of the others.
matrix.remove_col()
Deletes a column from a matrix and returns it as an array.
matrix.remove_row()
Deletes a row from a matrix and returns it as an array.
matrix.reshape()
Changes the number of rows and columns of a matrix without changing its items.
matrix.reverse()
Reverses a matrix in place so the first row becomes the last and each row reads backward.
matrix.row()
Returns one row of a matrix as a new array.
matrix.rows()
Returns how many rows a matrix has right now, which is also one more than the index of its last row.
matrix.set()
Stores a value in a given row and column of a matrix.
matrix.sort()
Reorders the rows of a matrix by the values in one column.
matrix.submatrix()
Returns a new matrix holding a block of an existing one.
matrix.sum()
Adds two matrices item by item, or adds one number to every item.
matrix.swap_columns()
Exchanges two columns of a matrix in place.
matrix.swap_rows()
Exchanges two rows of a matrix in place.
matrix.trace()
Adds up the entries that run from the top-left corner to the bottom-right corner of a square matrix.
matrix.transpose()
Returns a new matrix where rows and columns are swapped.

polyline.*

polyline.delete()
Wipes a polyline, stroke and fill, from the chart.
polyline.new()
Draws one path through an array of chart points, with optional curves, closing and fill.

request.*

request.currency_rate()
Requests the exchange rate from one currency to another as a series.
request.dividends()
Requests dividend data for a symbol, such as the gross or net amount of the latest payment.
request.earnings()
Requests earnings data for a symbol: reported, estimated or standardised earnings per share.
request.financial()
Requests a financial statement figure for a symbol, such as revenue or net income, for a chosen reporting period.
request.footprint()
Asks for the footprint of the current bar: traded volume at each price row, plus the value area and imbalances.
request.security()
Requests an expression evaluated on another symbol or timeframe and returns the result on the chart's bars.
request.security_lower_tf()
Requests an expression on a timeframe lower than the chart's and returns every intrabar value as an array.
request.splits()
Requests stock split data for a symbol: the numerator or denominator of the latest split ratio.

runtime.*

runtime.error()
Stops the script with an error message. Use it to reject inputs or states the script cannot handle.

str.*

str.contains()
Returns true when a string includes another string anywhere inside it.
str.endswith()
Returns true when a string finishes with the text you give.
str.format()
Builds a string from a template, replacing {0}, {1} and so on with the arguments that follow.
str.format_time()
Formats a UNIX timestamp in milliseconds as text, using a pattern and an optional time zone.
str.length()
Returns how many characters a string contains.
str.lower()
Returns a string with every letter converted to lower case.
str.match()
Returns the first part of a string that matches a regular expression, or an empty string.
str.pos()
Returns the index where a string first appears inside another, or na if it does not.
str.repeat()
Returns a string made of the source repeated a number of times, with an optional separator between copies.
str.replace()
Replaces one occurrence of a target text, the first by default, with a replacement.
str.replace_all()
Replaces every occurrence of a target text with a replacement.
str.split()
Splits a string at every separator and returns the pieces as an array of strings.
str.startswith()
Returns true when a string begins with the text you give.
str.substring()
Returns the part of a string from begin_pos up to, but not including, end_pos.
str.tonumber()
Converts a string of digits to a float, giving na when the text is not a number.
str.tostring()
Converts a number, boolean, string or array to text, optionally through a format pattern or a format.* constant.
str.trim()
Returns a string with spaces, tabs and line breaks removed from both ends.
str.upper()
Returns a string with every letter converted to upper case.

strategy.*

strategy.cancel()
Cancels the pending entry, order or exit orders that carry an id, before they fill.
strategy.cancel_all()
Cancels every pending order of the strategy: entries, orders and exits that have not filled.
strategy.close()
Exits the trades opened by one entry id with a market order on the next bar.
strategy.close_all()
Closes the whole open position with a market order on the next bar, whatever entry ids opened it.
strategy.closedtrades.commission()
The commission a closed trade paid in total, on both its entry and its exit.
strategy.closedtrades.entry_bar_index()
The bar_index of the bar on which a closed trade's entry order filled.
strategy.closedtrades.entry_comment()
The comment attached to the order that opened a closed trade.
strategy.closedtrades.entry_id()
The id of the order that opened a closed trade, as passed to strategy.entry.
strategy.closedtrades.entry_price()
The price at which a closed trade was entered.
strategy.closedtrades.entry_time()
The time a closed trade was entered, as a UNIX timestamp in milliseconds.
strategy.closedtrades.exit_bar_index()
The bar_index of the bar on which a closed trade's exit order filled.
strategy.closedtrades.exit_comment()
The comment attached to the order that closed a closed trade.
strategy.closedtrades.exit_id()
The id of the order that closed a closed trade, as passed to strategy.exit or strategy.close.
strategy.closedtrades.exit_price()
The price at which a closed trade was exited.
strategy.closedtrades.exit_time()
The time a closed trade was exited, as a UNIX timestamp in milliseconds.
strategy.closedtrades.max_drawdown()
The worst unrealised loss a closed trade suffered while it was open, in the account currency.
strategy.closedtrades.max_drawdown_percent()
The worst unrealised loss a closed trade suffered, as a percentage of its entry value.
strategy.closedtrades.max_runup()
The best unrealised profit a closed trade reached while it was open, in the account currency.
strategy.closedtrades.max_runup_percent()
The best unrealised profit a closed trade reached, as a percentage of its entry value.
strategy.closedtrades.profit()
Net profit or loss of a closed trade, after commission, in the account currency.
strategy.closedtrades.profit_percent()
Profit or loss of a closed trade as a percentage of the value it was entered at.
strategy.closedtrades.size()
The quantity of a closed trade; positive for a long trade, negative for a short trade.
strategy.convert_to_account()
Converts an amount from the symbol's currency into the strategy's account currency.
strategy.convert_to_symbol()
Converts an amount from the strategy's account currency into the symbol's currency.
strategy.default_entry_qty()
The order quantity the strategy's default sizing would give for a fill at a chosen price.
strategy.entry()
Places an order to open or add to a position; an opposite entry reverses the position.
strategy.exit()
Places stop-loss, take-profit and trailing-stop orders that close trades opened by strategy.entry.
strategy.opentrades.commission()
The commission an open trade has paid so far, which is the fee charged on its entry.
strategy.opentrades.entry_bar_index()
The bar_index of the bar on which an open trade's entry order filled.
strategy.opentrades.entry_comment()
The comment attached to the order that opened an open trade.
strategy.opentrades.entry_id()
The id of the order that opened an open trade, as passed to strategy.entry.
strategy.opentrades.entry_price()
The price at which an open trade was entered.
strategy.opentrades.entry_time()
The time an open trade was entered, as a UNIX timestamp in milliseconds.
strategy.opentrades.max_drawdown()
The worst unrealised loss an open trade has suffered so far, in the account currency.
strategy.opentrades.max_drawdown_percent()
The worst unrealised loss an open trade has suffered so far, as a percentage of its entry value.
strategy.opentrades.max_runup()
The best unrealised profit an open trade has reached so far, in the account currency.
strategy.opentrades.max_runup_percent()
The best unrealised profit an open trade has reached so far, as a percentage of its entry value.
strategy.opentrades.profit()
Unrealised profit or loss of an open trade, valued at the current bar's close.
strategy.opentrades.profit_percent()
Unrealised profit or loss of an open trade as a percentage of its entry value.
strategy.opentrades.size()
The quantity of an open trade; positive for a long trade, negative for a short trade.
strategy.order()
Places a buy or sell order that adds to or reduces the net position, ignoring pyramiding and reversal rules.
strategy.risk.allow_entry_in()
Restricts strategy.entry to opening only long or only short positions.
strategy.risk.max_cons_loss_days()
Stops the strategy after a set number of losing trading days in a row.
strategy.risk.max_drawdown()
Stops the strategy when its equity falls a set amount below its highest value.
strategy.risk.max_intraday_filled_orders()
Limits how many orders may fill in one trading day, then stops trading until the next day.
strategy.risk.max_intraday_loss()
Stops trading for the rest of the day once the day's loss reaches a set amount.
strategy.risk.max_position_size()
Caps the position size that strategy.entry orders may build, in contracts or shares.

syminfo.*

syminfo.prefix()
Returns the exchange prefix of a ticker id you pass, so syminfo.prefix("NASDAQ:AAPL") gives NASDAQ.
syminfo.ticker()
Returns the symbol name of a ticker id you pass, without its exchange prefix, so "NASDAQ:AAPL" gives AAPL.

ta.*

ta.alma()
Returns the Arnaud Legoux moving average, a Gaussian-weighted average whose peak can be shifted toward recent or older bars.
ta.atr()
Returns the average true range: the running average of each bar's true range, a measure of how far price typically moves per bar.
ta.barssince()
Returns the bars elapsed since condition was last true: 0 on a true bar, na before the first one.
ta.bb()
Returns the Bollinger Bands as three series: the moving-average basis and the bands mult standard deviations above and below it.
ta.bbw()
Returns the Bollinger Band width: the gap between the upper and lower band divided by the basis.
ta.cci()
Returns the commodity channel index: how far source sits from its moving average, in units of 0.015 times the mean deviation.
ta.change()
Returns the difference between the current value of source and its value length bars ago; for a bool source, whether it differs.
ta.cmo()
Returns the Chande momentum oscillator: the sum of up moves minus the sum of down moves, as a percentage of their total.
ta.cog()
Returns the center of gravity oscillator: a weighted position of price inside the window, negative and shifting with each new bar.
ta.correlation()
Returns the Pearson correlation coefficient between two series over the last length bars, from -1 to 1.
ta.cross()
Returns true on any bar where the two series cross, in either direction.
ta.crossover()
Returns true on the bar where source1 moves from at or below source2 to above it.
ta.crossunder()
Returns true on the bar where source1 moves from at or above source2 to below it.
ta.cum()
Returns the running total of source from the first bar to the current one.
ta.dev()
Returns the mean absolute deviation of source over length bars: the average distance of each value from the window's mean.
ta.dmi()
Returns the directional movement system as three series: +DI, -DI and ADX, computed from the chart's highs, lows and closes.
ta.ema()
Returns the exponential moving average of source over length bars, weighting recent values by a smoothing factor of 2 / (length + 1).
ta.falling()
Returns true when source has fallen on each of the last length bars.
ta.highest()
Returns the highest value of source over the last length bars, including the current one.
ta.highestbars()
Returns how many bars back the highest value of source in the last length bars occurred, as 0 or a negative number.
ta.hma()
Returns the Hull moving average, built from weighted averages to cut lag while staying smooth.
ta.kc()
Returns the Keltner Channels as three series: an EMA basis with bands mult times an averaged range above and below.
ta.kcw()
Returns the Keltner Channel width: the distance between the upper and lower channel divided by the basis.
ta.linreg()
Returns the value of the least-squares regression line fitted to the last length values of source, read offset bars back from the newest bar.
ta.lowest()
Returns the lowest value of source over the last length bars, including the current one.
ta.lowestbars()
Returns how many bars back the lowest value of source in the last length bars occurred, as 0 or a negative number.
ta.macd()
Returns three series: the MACD line (fast EMA minus slow EMA), its signal line, and the histogram between them.
ta.max()
Returns the largest value source has taken from the first bar to the current one.
ta.median()
Returns the median of source over the last length bars: the middle value of the sorted window.
ta.mfi()
Returns the money flow index: a volume-weighted relative strength reading from 0 to 100 over length bars.
ta.min()
Returns the smallest value source has taken from the first bar to the current one.
ta.mode()
Returns the most frequent value of source in the last length bars; when values tie, the smallest of them.
ta.mom()
Returns momentum: the current value of source minus its value length bars ago.
ta.percentile_linear_interpolation()
Returns the value a given percentage of the way up the sorted last length bars, blending the two nearest ranks.
ta.percentile_nearest_rank()
Returns the value at the given percentile of the last length bars using the nearest-rank method, always an actual value from the window.
ta.percentrank()
Returns the percentage of the previous length values of source that are less than or equal to the current value.
ta.pivot_point_levels()
Returns an array of pivot point levels (pivot, resistances and supports) computed from the previous period's open, high, low and close.
ta.pivothigh()
Returns the price of a pivot high once rightbars bars have confirmed it, otherwise na.
ta.pivotlow()
Returns the price of a pivot low once rightbars bars have confirmed it, otherwise na.
ta.range()
Returns the difference between the highest and lowest value of source over the last length bars.
ta.rci()
Returns the rank correlation index: how closely the price ranking in the window follows time order, from -100 to 100.
ta.rising()
Returns true when source has risen on each of the last length bars.
ta.rma()
Returns the running moving average, the smoothing used inside ta.rsi and ta.atr, with a factor of 1 / length.
ta.roc()
Returns the rate of change: the percentage change of source over the last length bars.
ta.rsi()
Returns the relative strength index: average gains against average losses over length bars, scaled from 0 to 100.
ta.sar()
Returns the Parabolic SAR: a stop-and-reverse level that accelerates toward price while a trend lasts and flips when price touches it.
ta.sma()
Returns the simple moving average: the plain mean of the last length values of source, na until length bars exist.
ta.stdev()
Returns the standard deviation of source over the last length bars, dividing by length unless biased is false.
ta.stoch()
Returns the raw stochastic: where source sits between the lowest low and highest high of the last length bars, from 0 to 100.
ta.supertrend()
Returns the Supertrend line and its direction: a trailing stop built from the average true range that flips when price closes through it.
ta.swma()
Returns a four-bar symmetrically weighted moving average with fixed weights 1, 2, 2 and 1 from oldest to newest.
ta.tr()
Returns the true range of the current bar; the handle_na argument decides what the first bar gives.
ta.tsi()
Returns the true strength index: double-smoothed momentum divided by double-smoothed absolute momentum, between -1 and 1.
ta.valuewhen()
Returns the value of source from the bar where condition was last true, or from an earlier true bar chosen by occurrence.
ta.variance()
Returns the variance of source over the last length bars: the mean squared distance from the window's average.
ta.vwap()
Returns the volume-weighted average price of source, restarting whenever anchor is true, with optional standard deviation bands.
ta.vwma()
Returns the volume-weighted moving average: the mean of price times volume over length bars divided by the mean volume.
ta.wma()
Returns the weighted moving average, giving the newest bar a weight of length and each older bar one less, down to 1.
ta.wpr()
Returns Williams %R: where the close sits in the last length bars' high-low range, from -100 to 0.

table.*

table.cell()
Writes one cell's text and style, replacing everything that cell held, including colors set earlier.
table.cell_set_bgcolor()
Sets the fill of a single cell, painting over the table's own background.
table.cell_set_height()
Sets a cell's height as a percent of the chart height; 0 lets the text decide.
table.cell_set_text()
Replaces the text of one cell while leaving its colors, size, alignment and tooltip alone.
table.cell_set_text_color()
Recolors the text of one cell without changing its fill, size or wording.
table.cell_set_text_font_family()
Switches one cell between the default typeface and a monospace face with equal-width digits.
table.cell_set_text_formatting()
Sets bold, italic, both or neither on the text of one cell.
table.cell_set_text_halign()
Places a cell's text against its left edge, center or right edge.
table.cell_set_text_size()
Picks the text size of one cell, from size.tiny up to size.huge, or size.auto to scale with the cell.
table.cell_set_text_valign()
Places a cell's text against its top edge, center or bottom edge.
table.cell_set_tooltip()
Attaches hover text to one cell, so a short value can carry a longer explanation.
table.cell_set_width()
Sets a cell's width as a percent of the chart width; 0 lets the text decide.
table.clear()
Empties every cell in a block of a table while the grid keeps its size, position and frame.
table.delete()
Takes a table off the chart and frees its screen position.
table.merge_cells()
Fuses a rectangular block of cells into one cell that spans several columns, rows or both.
table.new()
Creates an empty grid of columns by rows at one of nine screen positions and returns it as a table.
table.set_bgcolor()
Sets the fill behind the whole table, which shows wherever a cell has no fill of its own.
table.set_border_color()
Sets the color of the inner grid lines that separate the cells of a table.
table.set_border_width()
Sets how many pixels thick the inner grid lines are; 0 turns the grid off.
table.set_frame_color()
Sets the color of the rectangle drawn around the outer edge of a table.
table.set_frame_width()
Sets the pixel thickness of the outline around a table; 0 draws no outline.
table.set_position()
Re-anchors an existing table to a different one of the nine screen positions without touching its cells.

ticker.*

ticker.heikinashi()
Builds a ticker id that serves Heikin Ashi candles for a symbol, to pass to request.security.
ticker.inherit()
Gives a symbol the settings of another ticker id: its session, adjustments and chart type.
ticker.kagi()
Builds a ticker id that serves a Kagi chart for a symbol, reversing after a set price move.
ticker.linebreak()
Builds a ticker id that serves a Line Break chart for a symbol, using a set number of lines.
ticker.modify()
Returns a copy of a ticker id with its session, adjustment, back-adjustment or settlement settings changed.
ticker.new()
Builds a ticker id from a prefix and a symbol name, with optional session, adjustment and back-adjustment settings.
ticker.pointfigure()
Builds a ticker id that serves a Point and Figure chart for a symbol, from a box size and a reversal count.
ticker.renko()
Builds a ticker id that serves Renko bricks for a symbol, sized by ATR or by a fixed box size.
ticker.standard()
Returns a ticker id for the plain, unmodified version of a symbol: standard candles, regular session, no adjustment or currency conversion.

timeframe.*

timeframe.change()
True on the first bar of a new period of the given timeframe, such as a new day, week or hour.
timeframe.from_seconds()
Converts a number of seconds to a timeframe string such as "5" for 300 seconds or "60" for 3600.
timeframe.in_seconds()
Converts a timeframe string to the number of seconds in one of its bars; with no argument it uses the chart's timeframe.

volume_row.*

volume_row.buy_volume()
The buy volume in one footprint row: volume traded at the ask between the row's two prices.
volume_row.delta()
The delta of one footprint row: its buy volume minus its sell volume.
volume_row.down_price()
The lower price of one footprint row: the bottom edge of the band the row covers.
volume_row.has_buy_imbalance()
True when one footprint row shows a buy imbalance: buying far outweighs the selling it is compared with.
volume_row.has_sell_imbalance()
True when one footprint row shows a sell imbalance: selling far outweighs the buying it is compared with.
volume_row.sell_volume()
The sell volume in one footprint row: volume traded at the bid between the row's two prices.
volume_row.total_volume()
The total volume traded in one footprint row: its buy volume plus its sell volume.
volume_row.up_price()
The upper price of one footprint row: the top edge of the band the row covers.