Skip to main content
Home

Built and signed on GitHub Actions

OakScriptJS is a TypeScript/JavaScript library that mirrors PineScript's calculation and indicator API, maintaining exact function signatures and behavior. This library focuses on the computational core of PineScript

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
a week ago (0.1.3)
f
abs

Returns the absolute value of a number.

N
array
No documentation available
f
array.abs

Absolute value of array elements

f
array.avg

Returns the average of all elements (numeric arrays only)

f
array.binary_search_leftmost

Binary Search Leftmost

f
array.binary_search_rightmost

Binary Search Rightmost

f
array.clear

Removes all elements from the array

f
array.concat

Concatenates two arrays

f
array.copy

Returns a shallow copy of the array

f
array.covariance

Covariance

f
array.every

Tests whether all elements in the array pass the test implemented by the provided function

f
array.fill

Fills the array with the specified value

f
array.first

Returns the first element of the array

f
array.from

Creates a new array from existing one (alias for copy)

f
array.get

Returns the element at the specified index

f
array.includes

Returns true if the array contains the value

f
array.indexof

Returns the index of the first occurrence of the value

f
array.insert

Inserts a value at the specified index

f
array.join

Joins all elements into a string

f
array.last

Returns the last element of the array

f
array.lastindexof

Returns the index of the last occurrence of the value

f
array.max

Returns the maximum value (numeric arrays only)

f
array.median

Returns the median value (numeric arrays only)

f
array.min

Returns the minimum value (numeric arrays only)

f
array.mode

Returns the mode (most frequent value)

f
array.new_array

Creates a new array with initial size and default value

f
array.new_bool

Create new boolean array

f
array.new_box

Create new box array

f
array.new_color

Create new color array

f
array.new_float

Create new float array

f
array.new_int

Create new integer array

f
array.new_label

Create new label array

f
array.new_line

Create new line array

f
array.new_linefill

Create new linefill array

f
array.new_string

Create new string array

f
array.newtype

New Type (User-Defined Type Array)

f
array.percentile_linear_interpolation

Percentile Linear Interpolation

f
array.percentile_nearest_rank

Percentile Nearest Rank

f
array.percentrank

Percent Rank

f
array.pop

Removes and returns the last element of the array

f
array.push

Appends a value to the end of the array

f
array.range

Range of array values

f
array.remove

Removes the element at the specified index

f
array.reverse

Reverses the array in place

f
array.set

Sets the value of the element at the specified index

f
array.shift

Removes and returns the first element of the array

f
array.size

Returns the number of elements in an array

f
array.slice

Returns a slice of the array

f
array.some

Tests whether at least one element in the array passes the test implemented by the provided function

f
array.sort

Sorts array elements (numeric)

f
array.sort_indices

Sort Indices

f
array.standardize

Standardize

f
array.stdev

Returns the standard deviation

f
array.sum

Returns the sum of all elements (numeric arrays only)

f
array.unshift

Inserts a value at the beginning of the array

f
array.variance

Returns the variance

f
atr

Average True Range - returns the RMA (Relative Moving Average) of true range.

f
avg

Returns the average (arithmetic mean) of the arguments.

I
Bar
No documentation available
v
bar_index

Bar index series (0, 1, 2, ...) Equivalent to PineScript's bar_index

f
bb

Bollinger Bands - a technical analysis tool defined by lines plotted two standard deviations away from a simple moving average.

T
bool
No documentation available
N
box
No documentation available
f
box.copy

Creates a copy of the box object.

f
box.delete_box

Deletes the box object.

f
box.get_bottom

Returns the bottom border price level.

f
box.get_left

Returns the left border x coordinate.

f
box.get_right

Returns the right border x coordinate.

f
box.get_top

Returns the top border price level.

f
box.new_box

Creates a new box object.

f
box.set_bgcolor

Sets the background fill color.

f
box.set_border_color

Sets the border color.

f
box.set_border_style

Sets the border style.

f
box.set_border_width

Sets the border width.

f
box.set_bottom

Sets the bottom border price level.

f
box.set_extend

Sets the horizontal extension mode.

f
box.set_left

Sets the left border x coordinate.

f
box.set_lefttop

Sets the left and top coordinates.

f
box.set_right

Sets the right border x coordinate.

f
box.set_rightbottom

Sets the right and bottom coordinates.

f
box.set_text

Sets the text content.

f
box.set_text_color

Sets the text color.

f
box.set_text_font_family

Sets the text font family.

f
box.set_text_halign

Sets the horizontal text alignment.

f
box.set_text_size

Sets the text size.

f
box.set_text_valign

Sets the vertical text alignment.

f
box.set_text_wrap

Sets the text wrapping mode.

f
box.set_top

Sets the top border price level.

f
box.set_xloc

Sets the coordinate system for the box.

f
ceil

Returns the smallest integer greater than or equal to a given number (rounds up).

f
change

Change - calculates the difference between the current value and its value length bars ago.

I
ChartData

Chart data required for technical analysis functions.

v
close

Close price series Equivalent to PineScript's close

I
Color

Color object with hex representation

N
color
No documentation available
v
color.aqua

Aqua/Cyan color constant

f
color.b

Extracts the blue component from a color.

v
color.black

Black color constant

v
color.blue

Blue color constant

f
color.from_gradient

Creates a color from a gradient based on value position.

f
color.from_hex

Creates a color from a hexadecimal string with optional transparency.

v
color.fuchsia

Fuchsia/Magenta color constant

f
color.g

Extracts the green component from a color.

v
color.gray

Gray color constant

v
color.green

Green color constant (same as lime)

v
color.lime

Lime color constant (same as green)

v
color.maroon

Maroon color constant

v
color.navy

Navy color constant

f
color.new_color

Creates a new color with modified transparency, preserving RGB components.

v
color.olive

Olive color constant

v
color.orange

Orange color constant

v
color.purple

Purple color constant

f
color.r

Extracts the red component from a color.

v
color.red

Red color constant

f
color.rgb

Creates a color from RGB values with optional transparency.

v
color.silver

Silver color constant

f
color.t

Extracts the transparency component from a color.

v
color.teal

Teal color constant

v
color.white

White color constant

v
color.yellow

Yellow color constant

N
colorDSL
No documentation available
I
colorDSL.Color

Color object with hex representation

v
colorDSL.color

Pine color constants Exported as simple strings for compatibility with IndicatorController

f
compile

Compile registered indicator into chart-bindable object

I
CompiledIndicator

Compiled indicator object that can be bound to a chart

I
ContextConfig

Configuration for creating a context with implicit data. Can accept either explicit ChartData or an array of Bars.

f
cos

Returns the cosine of an angle in radians.

f
createContext

Creates a context with implicit data for cleaner function calls.

f
createIndicator

Factory function to create an indicator controller

f
crossover

Crossover - returns true when series1 crosses over series2 (moves from below to above).

f
crossunder

Crossunder - returns true when series1 crosses under series2 (moves from above to below).

f
ema

Exponential Moving Average - returns the exponentially weighted moving average.

f
exp

Returns e (Euler's number) raised to the power of value.

T
float
No documentation available
f
floor

Returns the largest integer less than or equal to a given number (rounds down).

f
from_hex

Creates a color from a hexadecimal string with optional transparency.

f
getClose

Gets close prices from OHLC

f
getDSLContext

Get the current runtime context

f
getHigh

Gets high prices from OHLC

f
getLow

Gets low prices from OHLC

f
getOpen

Gets open prices from OHLC

v
high

High price series Equivalent to PineScript's high

v
hl2

(high + low) / 2 Equivalent to PineScript's hl2

v
hlc3

(high + low + close) / 3 Equivalent to PineScript's hlc3

v
hlcc4

(high + low + close + close) / 4 Equivalent to PineScript's hlcc4

f
hline

Draw a horizontal line at a specific price level

I
T
IChartApi

Type definition for Lightweight Charts IChartApi

f
indicator

Declare an indicator

I
IndicatorControllerInterface

Interface for controlling an indicator's lifecycle

I
IndicatorMetadata

Complete metadata describing an indicator

T
input_bool
No documentation available
T
input_color
No documentation available
T
input_float
No documentation available
T
input_int
No documentation available
T
input_string
No documentation available
T
int

Core types for OakScriptJS These types mirror the PineScript type system

T
ISeriesApi

Type definition for Lightweight Charts ISeriesApi

I
Label

Label object - Represents a label/annotation on the chart

N
label
No documentation available
f
label.copy

Creates a copy of the label object.

f
label.delete_label

Deletes the label object.

f
label.get_text

Returns the label text content.

f
label.get_x

Returns the x coordinate.

f
label.get_y

Returns the y coordinate (price level).

f
label.new_label

Creates a new label object.

f
label.set_color

Sets the label color (border and arrow).

f
label.set_size

Sets the label size.

f
label.set_style

Sets the label style.

f
label.set_text

Sets the text content.

f
label.set_text_font_family

Sets the text font family.

f
label.set_textalign

Sets the text alignment.

f
label.set_textcolor

Sets the text color.

f
label.set_tooltip

Sets the tooltip text.

f
label.set_x

Sets the x coordinate.

f
label.set_xloc

Sets the x-axis coordinate system.

f
label.set_xy

Sets both x and y coordinates.

f
label.set_y

Sets the y coordinate (price level).

f
label.set_yloc

Sets the y-axis positioning mode.

I
Line

Line object - Represents a line on the chart

N
line
No documentation available
f
line.copy

Creates a copy of the line object.

f
line.delete_line

Deletes the line object.

f
line.get_price

Returns the price level of a line at a given bar index.

f
line.get_x1

Returns the first point's x coordinate.

f
line.get_x2

Returns the second point's x coordinate.

f
line.get_y1

Returns the first point's y coordinate (price level).

f
line.get_y2

Returns the second point's y coordinate (price level).

f
line.new_line

Creates a new line object.

f
line.set_color

Sets the line color.

f
line.set_extend

Sets the extension mode of the line.

f
line.set_style

Sets the line style.

f
line.set_width

Sets the line width.

f
line.set_x1

Sets the first point's x coordinate.

f
line.set_x2

Sets the second point's x coordinate.

f
line.set_xloc

Sets the coordinate system for the line.

f
line.set_xy1

Sets both coordinates of the first point.

f
line.set_xy2

Sets both coordinates of the second point.

f
line.set_y1

Sets the first point's y coordinate (price level).

f
line.set_y2

Sets the second point's y coordinate (price level).

I
Linefill

Linefill object - Represents a filled area between two lines

N
linefill
No documentation available
f
linefill.delete_linefill

Deletes the linefill object.

f
linefill.get_line1

Returns the first line reference.

f
linefill.get_line2

Returns the second line reference.

f
linefill.new_linefill

Creates a new linefill object that fills the area between two lines.

f
linefill.set_color

Sets the fill color.

f
log

Returns the natural logarithm (base e) of a number.

v
low

Low price series Equivalent to PineScript's low

f
macd

Moving Average Convergence Divergence - trend-following momentum indicator showing relationship between two moving averages.

N
math
No documentation available
f
math.abs

Returns the absolute value of a number.

f
math.acos

Returns the arccosine (inverse cosine) of a number.

f
math.asin

Returns the arcsine (inverse sine) of a number.

f
math.atan

Returns the arctangent (inverse tangent) of a number.

f
math.avg

Returns the average (arithmetic mean) of the arguments.

f
math.ceil

Returns the smallest integer greater than or equal to a given number (rounds up).

f
math.cos

Returns the cosine of an angle in radians.

v
math.e
No documentation available
f
math.exp

Returns e (Euler's number) raised to the power of value.

f
math.floor

Returns the largest integer less than or equal to a given number (rounds down).

f
math.log

Returns the natural logarithm (base e) of a number.

f
math.log10

Returns the base-10 logarithm of a number.

f
math.max

Returns the maximum value from the arguments.

f
math.min

Returns the minimum value from the arguments.

v
math.phi
No documentation available
v
math.pi
No documentation available
f
math.pow

Returns base raised to the power of exponent.

f
math.random

Returns a pseudo-random number.

f
math.round

Returns the value rounded to the nearest integer or to a specified precision.

f
math.round_to_mintick

Rounds a value to the nearest mintick.

v
math.rphi
No documentation available
f
math.sign

Returns the sign of a number.

f
math.sin

Returns the sine of an angle in radians.

f
math.sqrt

Returns the square root of a number.

f
math.sum

Returns the sum of values over a sliding window.

f
math.tan

Returns the tangent of an angle in radians.

f
math.todegrees

Converts an angle from radians to degrees.

f
math.toradians

Converts an angle from degrees to radians.

N
matrix
No documentation available
f
matrix.new_matrix

Creates a new matrix

f
max

Returns the maximum value from the arguments.

f
min

Returns the minimum value from the arguments.

T
v
na
No documentation available
f
new_color

Creates a new color with modified transparency, preserving RGB components.

I
OakContext

Type representing the return value of createContext. Useful for TypeScript users who want to type their context variables.

I
OHLC
No documentation available
v
ohlc4

(open + high + low + close) / 4 Equivalent to PineScript's ohlc4

f
ohlcFromBars

Creates OHLC data from bar array

v
open

Open price series Equivalent to PineScript's open

I
PineArray
No documentation available
I
PineMatrix
No documentation available
f
plot

Plot a series on the chart

I
PlotMetadata

Metadata for a single plot line in an indicator

f
pow

Returns base raised to the power of exponent.

f
resetDSLContext

Reset the global context Used when re-executing indicator script

f
rgb

Creates a color from RGB values with optional transparency.

f
round

Returns the value rounded to the nearest integer or to a specified precision.

f
rsi

Relative Strength Index - momentum oscillator measuring speed and magnitude of price changes.

T
series
No documentation available
T
series_bool
No documentation available
T
series_box
No documentation available
T
series_color
No documentation available
T
series_float
No documentation available
T
series_int
No documentation available
T
series_label
No documentation available
T
series_line
No documentation available
T
series_linefill
No documentation available
T
series_string
No documentation available
T
series_table
No documentation available
T
simple_bool
No documentation available
T
simple_color
No documentation available
T
simple_float
No documentation available
T
simple_int
No documentation available
T
simple_string
No documentation available
f
sin

Returns the sine of an angle in radians.

f
sma

Simple Moving Average - returns the moving average (sum of last y values divided by y).

T
Source
No documentation available
f
sqrt

Returns the square root of a number.

f
stdev

Standard Deviation - measures the amount of variation or dispersion of values.

N
str
No documentation available
f
str.charAt

Returns the character at a specific position in a string.

f
str.concat

Concatenates multiple strings into one.

f
str.contains

Checks if a string contains a substring.

f
str.endswith

Checks if a string ends with a specific suffix.

f
str.format

Formats a string by replacing numbered placeholders with values.

f
str.format_time

Formats a timestamp as a string according to the specified format.

f
str.length

Returns the length of a string.

f
str.lower

Converts all characters in a string to lowercase.

f
str.match

Tests if a string matches a regular expression pattern.

f
str.pos

Returns the position of the first occurrence of a substring.

f
str.replace

Replaces occurrences of a substring with another string.

f
str.replace_all

Replaces all occurrences of a target string with a replacement string.

f
str.split

Splits a string into an array of substrings using a separator.

f
str.startswith

Checks if a string starts with a specific prefix.

f
str.substring

Extracts a substring from a string.

f
str.tonumber

Converts a string to a number (float).

f
str.tostring

Converts a value to its string representation.

f
str.trim

Removes whitespace from both ends of a string.

f
str.trimLeft

Removes whitespace from the left (start) of a string.

f
str.trimRight

Removes whitespace from the right (end) of a string.

f
str.upper

Converts all characters in a string to uppercase.

f
sum

Returns the sum of values over a sliding window.

I
SymbolInfo

Symbol information that can be used by various functions.

N
ta
No documentation available
f
ta.alma

Arnaud Legoux Moving Average (ALMA)

f
ta.atr

Average True Range - returns the RMA (Relative Moving Average) of true range.

f
ta.barssince

Bars Since - returns number of bars since condition was true.

f
ta.bb

Bollinger Bands - a technical analysis tool defined by lines plotted two standard deviations away from a simple moving average.

f
ta.bbw

Bollinger Bands Width - measures the width of Bollinger Bands.

f
ta.cci

Commodity Channel Index (CCI) - measures deviation from average price.

f
ta.change

Change - calculates the difference between the current value and its value length bars ago.

f
ta.cmo

Chande Momentum Oscillator - momentum indicator similar to RSI.

f
ta.cog

Center of Gravity (COG)

f
ta.correlation

Correlation Coefficient - measures degree to which two series deviate from their means together.

f
ta.cross

Cross - returns true when two series cross each other (either direction).

f
ta.crossover

Crossover - returns true when series1 crosses over series2 (moves from below to above).

f
ta.crossunder

Crossunder - returns true when series1 crosses under series2 (moves from above to below).

f
ta.cum

Cumulative Sum - returns the total sum of all elements from the beginning.

f
ta.dev

Mean Absolute Deviation - measure of difference between series and its SMA.

f
ta.dmi

Directional Movement Index - returns Directional Movement indicators.

f
ta.ema

Exponential Moving Average - returns the exponentially weighted moving average.

f
ta.falling

Falling - returns true if source is falling for length bars.

f
ta.highest

Highest Value - returns the highest value over a specified number of bars.

f
ta.highestbars

Highest Bars

f
ta.hma

Hull Moving Average (HMA) - improved moving average with reduced lag.

f
ta.kc

Keltner Channels - volatility-based envelope indicator.

f
ta.kcw

Keltner Channels Width (KCW)

f
ta.linreg

Linear Regression - line that best fits prices using least squares method.

f
ta.lowest

Lowest Value - returns the lowest value over a specified number of bars.

f
ta.lowestbars

Lowest Bars

f
ta.macd

Moving Average Convergence Divergence - trend-following momentum indicator showing relationship between two moving averages.

f
ta.max

Maximum of Two Values

f
ta.median

Median - returns the median (middle value) of the series.

f
ta.mfi

Money Flow Index (MFI) - volume-weighted RSI measuring buying and selling pressure.

f
ta.min

Minimum of Two Values

f
ta.mode

Mode (Most Frequent Value)

f
ta.mom

Momentum (MOM) - difference between current value and value length bars ago.

f
ta.percentile_linear_interpolation

Percentile (Linear Interpolation Method)

f
ta.percentile_nearest_rank

Percentile (Nearest Rank Method)

f
ta.percentrank

Percent Rank - percentage of how many previous values were less than or equal to current value.

f
ta.pivot_point_levels

Pivot Point Levels

f
ta.pivothigh

Pivot High - detects pivot high points in the price series.

f
ta.pivotlow

Pivot Low - detects pivot low points in the price series.

f
ta.range

Range (High - Low)

f
ta.rci

Rank Correlation Index (RCI)

f
ta.rising

Rising - returns true if source is rising for length bars.

f
ta.rma

Relative Moving Average (RMA) - exponentially weighted moving average with alpha = 1 / length.

f
ta.roc

Rate of Change (ROC) - percentage change between current value and value length bars ago.

f
ta.rsi

Relative Strength Index - momentum oscillator measuring speed and magnitude of price changes.

f
ta.sar

Parabolic SAR (Stop and Reverse) - trend-following indicator.

f
ta.sma

Simple Moving Average - returns the moving average (sum of last y values divided by y).

f
ta.stdev

Standard Deviation - measures the amount of variation or dispersion of values.

f
ta.stoch

Stochastic Oscillator - momentum indicator comparing closing price to price range.

f
ta.supertrend

SuperTrend Indicator - a trend-following indicator that helps identify trend direction.

f
ta.swma

Symmetrically Weighted Moving Average (SWMA) - fixed length 4 with symmetric weights.

f
ta.tr

True Range - measures market volatility by calculating the greatest of three price ranges.

f
ta.tsi

True Strength Index - momentum oscillator based on double smoothed momentum.

f
ta.valuewhen

Value When - returns the value when condition was true.

f
ta.variance

Variance - expectation of squared deviation from mean.

f
ta.vwap

Volume Weighted Average Price (VWAP)

f
ta.vwma

Volume Weighted Moving Average (VWMA) - moving average weighted by volume.

f
ta.wma

Weighted Moving Average (WMA) - moving average with linearly decreasing weights.

f
ta.wpr

Williams %R (Williams Percent Range)

I
Table

Table object - Represents a table for displaying data

N
taDSL
No documentation available
f
taDSL.atr

Average True Range

f
taDSL.bb

Bollinger Bands

f
taDSL.change

Change (difference from previous value)

f
taDSL.crossover

Crossover detection

f
taDSL.crossunder

Crossunder detection

f
taDSL.ema

Exponential Moving Average

f
taDSL.macd

Moving Average Convergence Divergence

f
taDSL.mom

Momentum

f
taDSL.roc

Rate of Change

f
taDSL.rsi

Relative Strength Index

f
taDSL.sma

Simple Moving Average

f
taDSL.stdev

Standard Deviation

f
taDSL.tr

True Range

f
taDSL.wma

Weighted Moving Average

f
tan

Returns the tangent of an angle in radians.

N
time
No documentation available
f
time.now

Returns the current time in milliseconds

f
time.timestamp

Returns timestamp for a specific date/time

v
timeSeriesDSL

Time series (timestamp in milliseconds) Equivalent to PineScript's time

f
tr

True Range - measures market volatility by calculating the greatest of three price ranges.

v
VERSION
No documentation available
v
volume

Volume series Equivalent to PineScript's volume

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.