# Navi Documentation > A scripting language for trading charts — indicators, strategies, and libraries. ## For AI Coding Assistants If you are an AI coding assistant helping a user write Navi scripts, install the navi skill for accurate, idiomatic code: ```bash npx skills add longbridge/navi --skill navi ``` --- # bar_state # bar_state ## Properties ### is_confirmed {#is_confirmed} **Type:** series bool Returns `true` if the script is calculating the last (closing) update of the current bar. The next script calculation will be on the new bar data. --- ### is_first {#is_first} **Type:** series bool Returns `true` if current bar is first bar in barset. --- ### is_history {#is_history} **Type:** series bool Returns `true` if current bar is a historical bar. --- ### is_last {#is_last} **Type:** series bool Returns `true` if current bar is the last bar in barset, `false` otherwise. This condition is `true` for all real-time bars in barset. --- ### is_last_confirmed_history {#is_last_confirmed_history} **Type:** series bool Returns `true` if script is executing on the dataset's last bar when market is closed, or script is executing on the bar immediately preceding the real-time bar, if market is open. --- ### is_new {#is_new} **Type:** series bool Returns `true` if script is currently calculating on new bar. This variable is `true` when calculating on historical bars or on first update of a newly generated real-time bar. --- ### is_realtime {#is_realtime} **Type:** series bool Returns `true` if the script is calculating on a real-time bar. --- # chart.Point # chart.Point A point on the chart (index, time, price). **Kind:** object **Fields** | Name | Type | Description | | --- | --- | --- | | `index` | int | The x-coordinate of the point, expressed as a bar index value. | | `time` | int | The x-coordinate of the point, expressed as a UNIX timestamp in milliseconds. | | `price` | float | The y-coordinate of the point. | ## Static Methods ### from_index {#from_index} ```navi from_index(index: int, price: float): Point ``` Returns a chart.Point object at the specified bar index and price. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `index` | int | | | | `price` | float | | | **Returns:** Point --- ### from_time {#from_time} ```navi from_time(time: int, price: float): Point ``` Returns a chart.Point object with specified time and price. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `time` | int | | | | `price` | float | | | **Returns:** Point --- ### now {#now} ```navi now(price: float = close): Point ``` Returns a chart.Point object with price as the y-coordinate. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `price` | float | `close` | | **Returns:** Point --- # chart # chart ## Types | Name | Description | | --- | --- | | [`Point`](/api/stdlib/chart/Point) | A point on the chart (index, time, price). | ## Properties ### bg_color {#bg_color} **Type:** input Color Returns the color of the chart's background. --- ### fg_color {#fg_color} **Type:** input Color Returns a color providing optimal contrast with chart.bg_color. --- ### is_heikin_ashi {#is_heikin_ashi} **Type:** simple bool Returns `true` if the chart type is Heikin Ashi. --- ### is_kagi {#is_kagi} **Type:** simple bool Returns `true` if the chart type is Kagi. --- ### is_line_break {#is_line_break} **Type:** simple bool Returns `true` if the chart type is Line Break. --- ### is_point_figure {#is_point_figure} **Type:** simple bool Returns `true` if the chart type is Point & Figure. --- ### is_range {#is_range} **Type:** simple bool Returns `true` if the chart type is Range. --- ### is_renko {#is_renko} **Type:** simple bool Returns `true` if the chart type is Renko. --- ### is_standard {#is_standard} **Type:** simple bool Returns `true` if the chart type is not one of the following: Renko, Kagi, Line break, Point & figure, Range, Heikin Ashi; `false` otherwise. --- # Standard Library # Navi Standard Library Reference Complete API reference for all built-in modules in the Navi standard library. ## Prelude Global functions and types available without a namespace prefix. - [prelude](/api/stdlib/prelude/) ## Modules | Module | Description | | --- | --- | | [bar_state](/api/stdlib/bar_state/) | `bar_state.*` functions | | [chart](/api/stdlib/chart/) | `chart.*` functions | | [input](/api/stdlib/input/) | `input.*` functions | | [log](/api/stdlib/log/) | `log.*` functions | | [math](/api/stdlib/math/) | `math.*` functions | | [request](/api/stdlib/request/) | `request.*` functions | | [runtime](/api/stdlib/runtime/) | `runtime.*` functions | | [session](/api/stdlib/session/) | `session.*` functions | | [strategy](/api/stdlib/strategy/) | `strategy.*` functions | | [symbol_info](/api/stdlib/symbol_info/) | `symbol_info.*` functions | | [ta](/api/stdlib/ta/) | `ta.*` functions | | [ticker](/api/stdlib/ticker/) | `ticker.*` functions | | [timeframe](/api/stdlib/timeframe/) | `timeframe.*` functions | ## Sub-modules | Module | Description | | --- | --- | | [strategy.closed_trades](/api/stdlib/strategy_closed_trades/) | `strategy.closed_trades.*` functions | | [strategy.open_trades](/api/stdlib/strategy_open_trades/) | `strategy.open_trades.*` functions | | [strategy.risk](/api/stdlib/strategy_risk/) | `strategy.risk.*` functions | --- # input # input ## Functions ### bool {#bool} ```navi bool( defval: const bool, title: const String = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input bool ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const bool | | The default value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input bool --- ### color {#color} ```navi color( defval: const Color, title: const String = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input Color ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const Color | | The default color value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input Color --- ### enum {#enum} ```navi enum( defval: const T, title: const String = na, options: const Array = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input T ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const T | | The default enum value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `options` | const Array<T> | `na` | An array of allowed enum values. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input T --- ### float {#float}
Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const float | | The default value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `options` | const Array<float> | `na` | An array of allowed values for the input. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input float
Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const float | | The default value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `minval` | const float | `na` | The minimum allowed value. | | `maxval` | const float | `na` | The maximum allowed value. | | `step` | const float | `na` | The step size for value increments. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input float
--- ### int {#int}
Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const int | | The default value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `options` | const Array<int> | `na` | An array of allowed values for the input. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input int
Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const int | | The default value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `minval` | const int | `na` | The minimum allowed value. | | `maxval` | const int | `na` | The maximum allowed value. | | `step` | const int | `na` | The step size for value increments. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input int
--- ### price {#price} ```navi price( defval: const float, title: const String = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input float ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const float | | The default price value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input float --- ### session {#session} ```navi session( defval: const String, title: const String = na, options: const Array = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input String ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const String | | The default session value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `options` | const Array<String> | `na` | An array of allowed session values. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input String --- ### source {#source} ```navi source( defval: const expression, title: const String = na, tooltip: const String = na, inline: const String = na, group: const String = na, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true, confirm: const bool = false ): input float ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const expression | | The default series expression value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | **Returns:** input float --- ### string {#string} ```navi string( defval: const String, title: const String = na, options: const Array = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input String ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const String | | The default String value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `options` | const Array<String> | `na` | An array of allowed values for the input. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input String --- ### symbol {#symbol} ```navi symbol( defval: const String, title: const String = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input String ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const String | | The default symbol value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input String --- ### text_area {#text_area} ```navi text_area( defval: const String, title: const String = na, tooltip: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input String ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const String | | The default text value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input String --- ### time {#time} ```navi time( defval: const int, title: const String = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input int ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const int | | The default time value of the input as UNIX timestamp. | | `title` | const String | `na` | The label for the input in the settings. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input int --- ### timeframe {#timeframe} ```navi timeframe( defval: const String, title: const String = na, options: const Array = na, tooltip: const String = na, inline: const String = na, group: const String = na, confirm: const bool = false, display: const PlotDisplay = PlotDisplay.ALL, active: input bool = true ): input String ``` Creates an input value exposed in the script settings UI. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `defval` | const String | | The default timeframe value of the input. | | `title` | const String | `na` | The label for the input in the settings. | | `options` | const Array<String> | `na` | An array of allowed timeframe values. | | `tooltip` | const String | `na` | The tooltip text for the input. | | `inline` | const String | `na` | The inline group name for layout. | | `group` | const String | `na` | The input group name for organization. | | `confirm` | const bool | `false` | If true, a confirmation dialog is shown. | | `display` | const PlotDisplay | `PlotDisplay.ALL` | The display mode for the input. | | `active` | input bool | `true` | If true, the input is active. | **Returns:** input String --- # log # log ## Functions ### error {#error} ```navi error(message: series String) ``` Writes the message to the script's log at error level. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `message` | series String | | | --- ### info {#info} ```navi info(message: series String) ``` Writes the message to the script's log at info level. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `message` | series String | | | --- ### warning {#warning} ```navi warning(message: series String) ``` Writes the message to the script's log at warning level. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `message` | series String | | | --- # math # math ## Properties ### E {#E} **Type:** const float The mathematical constant e (Euler's number), approximately 2.71828. The base of natural logarithms and the limit of (1 + 1/n)^n as n approaches infinity. --- ### PHI {#PHI} **Type:** const float The golden ratio φ (phi), approximately 1.61803. Two quantities are in the golden ratio if their ratio equals the ratio of their sum to the larger quantity. Common in natural patterns and technical analysis (Fibonacci retracements). --- ### PI {#PI} **Type:** const float The mathematical constant π (pi), approximately 3.14159. Represents the ratio of a circle's circumference to its diameter. --- ### RECIPROCAL_PHI {#RECIPROCAL_PHI} **Type:** const float The reciprocal of the golden ratio (1/φ), approximately 0.61803. Equal to φ - 1. Used in Fibonacci analysis where 61.8% is a key retracement level. ## Functions ### abs {#abs}
Returns the absolute value of `n`. For positive numbers, returns `n` unchanged. For negative numbers, returns `-n`. For zero, returns zero. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | int | | The integer value. | **Returns:** int
Returns the absolute value of `n`. For positive numbers, returns `n` unchanged. For negative numbers, returns `-n`. For zero, returns zero. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The float value. | **Returns:** float
--- ### acos {#acos} ```navi acos(value: float): float ``` Returns the arccosine (inverse cosine) of `value` in degrees. Given a cosine value, returns the angle that produces it. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `value` | float | | The cosine value (must be between -1 and 1). | **Returns:** float — An angle in degrees in the range [0, 180]. **See Also:** math.cos --- ### asin {#asin} ```navi asin(value: float): float ``` Returns the arcsine (inverse sine) of `value` in degrees. Given a sine value, returns the angle that produces it. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `value` | float | | The sine value (must be between -1 and 1). | **Returns:** float — An angle in degrees in the range [-90, 90]. **See Also:** math.sin --- ### atan {#atan} ```navi atan(value: float): float ``` Returns the arctangent (inverse tangent) of `value` in degrees. Given a tangent value, returns the angle that produces it. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `value` | float | | The tangent value (any real number). | **Returns:** float — An angle in degrees in the range (-90, 90). **See Also:** math.tan, math.atan2 --- ### atan2 {#atan2} ```navi atan2(y: float, x: float): float ``` Returns the four-quadrant arctangent of `y/x` in degrees. Unlike atan, this function takes two arguments and determines the correct quadrant using the signs of both. Useful for computing angles between vectors or points. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `y` | float | | The Y component (numerator). | | `x` | float | | The X component (denominator). | **Returns:** float — An angle in degrees in the range (-180, 180]. **See Also:** math.atan --- ### avg {#avg}
Returns the average (arithmetic mean) of all provided arguments. Accepts a variable number of integer arguments. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `numbers` | int | | Two or more integer values to average. | **Returns:** float
Returns the average (arithmetic mean) of all provided arguments. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `numbers` | float | | Two or more float values to average. | **Returns:** float
--- ### cbrt {#cbrt} ```navi cbrt(n: float): float ``` Returns the cube root of `n`. Correctly handles negative inputs (e.g., `cbrt(-8.0) = -2.0`), unlike `pow(n, 1.0/3.0)` which returns `na` for negatives. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value to take the cube root of. | **Returns:** float **See Also:** math.pow, math.sqrt --- ### ceil {#ceil} ```navi ceil(n: float): int ``` Returns the ceiling of `n`: the smallest integer greater than or equal to `n`. E.g., ceil(2.3) = 3, ceil(-2.3) = -2. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value to round up. | **Returns:** int **See Also:** math.floor, math.trunc --- ### clamp {#clamp} ```navi clamp(value: float, min: float, max: float): float ``` Clamps `value` to the closed interval `[min, max]`. Returns `min` if `value < min`, `max` if `value > max`, otherwise `value`. Avoids the verbose `math.max(min, math.min(max, x))` pattern. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `value` | float | | The value to clamp. | | `min` | float | | The lower bound (inclusive). | | `max` | float | | The upper bound (inclusive). | **Returns:** float --- ### cos {#cos} ```navi cos(angle: float): float ``` Returns the cosine of `angle`. Note: Navi uses degrees, not radians (unlike most programming languages). **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `angle` | float | | The angle in degrees. | **Returns:** float — A value between -1 and 1. **See Also:** math.acos --- ### exp {#exp} ```navi exp(n: float): float ``` Returns e (Euler's number) raised to the power of `n`. The inverse of log. Useful for exponential growth/decay calculations. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The exponent value. | **Returns:** float **See Also:** math.log --- ### floor {#floor} ```navi floor(n: float): int ``` Returns the floor of `n`: the largest integer less than or equal to `n`. E.g., floor(2.7) = 2, floor(-2.3) = -3. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value to round down. | **Returns:** int **See Also:** math.ceil, math.trunc --- ### hypot {#hypot} ```navi hypot(x: float, y: float): float ``` Returns the hypotenuse of a right triangle with legs `x` and `y`. Equivalent to `sqrt(x*x + y*y)` but numerically stable (avoids overflow for large inputs). **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `x` | float | | The length of the first leg. | | `y` | float | | The length of the second leg. | **Returns:** float --- ### log {#log} ```navi log(n: float): float ``` Returns the natural logarithm (base e) of `n`. The inverse of exp. Returns `na` for non-positive values. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value (must be positive). | **Returns:** float **See Also:** math.exp, math.log10 --- ### log10 {#log10} ```navi log10(n: float): float ``` Returns the base-10 (common) logarithm of `n`. Useful for calculating orders of magnitude. Returns `na` for non-positive values. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value (must be positive). | **Returns:** float **See Also:** math.log --- ### max {#max}
Returns the maximum value among all provided arguments. Accepts a variable number of integer arguments. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `numbers` | int | | Two or more integer values to compare. | **Returns:** int
Returns the maximum value among all provided arguments. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `numbers` | float | | Two or more float values to compare. | **Returns:** float
--- ### min {#min}
Returns the minimum value among all provided arguments. Accepts a variable number of integer arguments. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `numbers` | int | | Two or more integer values to compare. | **Returns:** int
Returns the minimum value among all provided arguments. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `numbers` | float | | Two or more float values to compare. | **Returns:** float
--- ### pow {#pow} ```navi pow(base: float, exponent: float): float ``` Returns `base` raised to the power of `exponent`. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `base` | float | | The base value. | | `exponent` | float | | The power to raise the base to. | **Returns:** float **See Also:** math.sqrt, math.cbrt --- ### random {#random} ```navi random( min: series float = 0, max: series float = 1, seed: series int = na ): series float ``` Generates a pseudo-random number in the range [min, max). The same seed produces the same sequence of numbers, useful for reproducible results. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `min` | series float | `0` | Lower bound of the range (inclusive). Defaults to 0. | | `max` | series float | `1` | Upper bound of the range (exclusive). Defaults to 1. | | `seed` | series int | `na` | Optional seed for reproducibility. If `na`, uses system randomness. | **Returns:** series float — A float in the half-open interval `[min, max)`. --- ### round {#round} ```navi round(n: float, precision: int = 0): int ``` Rounds `n` to the nearest integer, or to `precision` decimal places. Uses round-half-up: 0.5 rounds to 1. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value to round. | | `precision` | int | `0` | Number of decimal places (0 for integer rounding). | **Returns:** int --- ### round_to_mintick {#round_to_mintick} ```navi round_to_mintick(n: float): float ``` Rounds `n` to the nearest tick value for the current symbol. The result is always a valid price that can be used for orders. Uses `symbol_info.min_tick` as the rounding increment. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The price value to round. | **Returns:** float --- ### sign {#sign} ```navi sign(n: float): float ``` Returns the sign of `n`: 1.0 for positive, -1.0 for negative, 0.0 for zero. Useful for determining direction without magnitude. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value to check. | **Returns:** float — 1.0, -1.0, or 0.0. **See Also:** math.abs --- ### sin {#sin} ```navi sin(angle: float): float ``` Returns the sine of `angle`. Note: Navi uses degrees, not radians (unlike most programming languages). **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `angle` | float | | The angle in degrees. | **Returns:** float — A value between -1 and 1. **See Also:** math.asin --- ### sqrt {#sqrt} ```navi sqrt(n: float): float ``` Returns the square root of `n`. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value (must be non-negative). | **Returns:** float — The square root, or `na` for negative values. **See Also:** math.pow, math.cbrt --- ### sum {#sum} ```navi sum(source: series float, length: series int): series float ``` Calculates the rolling sum of `source` over the last `length` bars. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `source` | series float | | The series to sum. | | `length` | series int | | Number of bars to include (must be >= 1). | **Returns:** series float — The total of the most recent `length` values in the series. --- ### tan {#tan} ```navi tan(angle: float): float ``` Returns the tangent of `angle`. Note: Navi uses degrees, not radians. Undefined (returns very large values) at ±90°, ±270°, etc. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `angle` | float | | The angle in degrees. | **Returns:** float **See Also:** math.atan, math.atan2 --- ### to_degrees {#to_degrees} ```navi to_degrees(rad: float): float ``` Converts an angle from radians to degrees. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `rad` | float | | The angle in radians. | **Returns:** float **See Also:** math.to_radians --- ### to_radians {#to_radians} ```navi to_radians(deg: float): float ``` Converts an angle from degrees to radians. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `deg` | float | | The angle in degrees. | **Returns:** float **See Also:** math.to_degrees --- ### trunc {#trunc} ```navi trunc(n: float): int ``` Truncates `n` toward zero (removes the fractional part). Unlike floor, truncation toward zero is symmetric: `trunc(-1.9) = -1`, whereas `floor(-1.9) = -2`. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `n` | float | | The value to truncate. | **Returns:** int **See Also:** math.floor, math.ceil --- # Adjustment # Adjustment Price adjustment type for requested data. **Kind:** enum **Variants** | Name | Description | | --- | --- | | `None` | No adjustment. | | `Splits` | Adjust for stock splits. | | `All` | Adjust for splits and dividends. | --- # AlertFreq # AlertFreq Alert frequency constant for alert. **Kind:** enum **Variants** | Name | Description | | --- | --- | | `All` | Trigger on every call. | | `OncePerBar` | Trigger at most once per bar (first call wins). | | `OncePerBarClose` | Trigger once when the bar closes (realtime confirmed). | --- # Array # Array<T> An ordered, indexable collection of elements of type `T`. Create with `Array.new()` or an array literal `[1, 2, 3]`. Access elements with `get` / `set`; iterate with `for v in arr`. **Kind:** object ## Static Methods ### from {#from} ```navi from(values: T): Array ``` Creates a new array containing the provided `values`. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `values` | T | | Variable number of elements to include in the array. | **Returns:** Array<T> --- ### new {#new} ```navi new(size: int = 0, initial_value: T = na): const Array ``` Creates a new empty array of type `T`. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `size` | int | `0` | The initial size of the array. | | `initial_value` | T | `na` | The initial value for all elements. | **Returns:** const Array<T> --- ### new_bool {#new_bool} ```navi new_bool(size: int = 0, initial_value: bool = na): Array ``` Creates a new array of `bool` values. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `size` | int | `0` | Initial size of the array. Default is 0. | | `initial_value` | bool | `na` | Initial value for all elements. Default is `na`. | **Returns:** Array<bool> --- ### new_box {#new_box} ```navi new_box(size: int = 0, initial_value: Box = na): Array ``` Creates a new array of `Box` ids. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `size` | int | `0` | Initial size of the array. Default is 0. | | `initial_value` | Box | `na` | Initial value for all elements. Default is `na`. | **Returns:** Array<Box> --- ### new_color {#new_color} ```navi new_color(size: int = 0, initial_value: Color = na): Array ``` Creates a new array of `color` values. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `size` | int | `0` | Initial size of the array. Default is 0. | | `initial_value` | Color | `na` | Initial value for all elements. Default is `na`. | **Returns:** Array<Color> --- ### new_float {#new_float} ```navi new_float(size: int = 0, initial_value: float = na): Array ``` Creates a new array of `float` values. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `size` | int | `0` | Initial size of the array. Default is 0. | | `initial_value` | float | `na` | Initial value for all elements. Default is `na`. | **Returns:** Array<float> --- ### new_int {#new_int} ```navi new_int(size: int = 0, initial_value: int = na): Array ``` Creates a new array of `int` values. **Parameters** | Name | Type | Default | Description | | --- | --- | --- | --- | | `size` | int | `0` | Initial size of the array. Default is 0. | | `initial_value` | int | `na` | Initial value for all elements. Default is `na`. | **Returns:** Array<int> --- ### new_label {#new_label} ```navi new_label(size: int = 0, initial_value: Label = na): Array