PineJSStd
PineJS standard library functions.
Properties
isZero
Check if a value is zero.
Type
(v: number) => number
Type declaration
Check if a value is zero.
Signature
(v: number) => number
Parameters
Name | Type | Description |
---|---|---|
v | number | the value to test. |
Returns
true
if the value is zero, false
otherwise.
number
max_series_default_size
Default maximum size of a pine series.
Type
10001
Methods
abs
Absolute value of x is x if x >= 0, or -x otherwise.
Signature
abs(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The absolute value of x
number
accdist
Accumulation/distribution index.
Signature
accdist(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Accumulation/distribution index.
number
acos
The acos function returns the arccosine (in radians) of number such that cos(acos(y)) = y
for y
in range [-1, 1]
.
Signature
acos(x: number) => number
Parameters
Name | Type | Description |
---|---|---|
x | number | Angle, in radians. |
Returns
The arc cosine of a value; the returned angle is in the range [0, Pi]
, or na if y is outside of range [-1, 1]
.
number
add_days_considering_dst
Get time in daysCount
number of days while taking Daylight savings time into account.
Signature
add_days_considering_dst(timezone: string, utcTime: Date, daysCount: number) => Date
Parameters
Name | Type | Description |
---|---|---|
timezone | string | Timezone |
utcTime | Date | Date (JS built-in) |
daysCount | number | Number of days |
Returns
The time is daysCount
number of days, taking into account Daylight savings time.
Date
add_years_considering_dst
Get time in yearsCount
number of years while taking Daylight savings time into account.
Signature
add_years_considering_dst(timezone: string, utcTime: Date, yearsCount: number) => Date
Parameters
Name | Type | Description |
---|---|---|
timezone | string | Timezone |
utcTime | Date | Date (JS built-in) |
yearsCount | number | Number of years |
Returns
The time is yearsCount
number of years, taking into account Daylight savings time.
Date
alma
Arnaud Legoux Moving Average. It uses Gaussian distribution as weights for moving average.
Signature
alma(series: IPineSeries, length: number, offset: number, sigma: number) => number
Parameters
Name | Type | Description |
---|---|---|
series | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
offset | number | Controls tradeoff between smoothness (closer to 1) and responsiveness (closer to 0). |
sigma | number | Changes the smoothness of ALMA. The larger sigma the smoother ALMA. |
Returns
number
and
Logical AND.
Signature
and(n_0: number, n_1: number) => number
Parameters
Name | Type |
---|---|
n_0 | number |
n_1 | number |
Returns
1
if both values are truthy, 0
otherwise.
number
asin
The asin function returns the arcsine (in radians) of number such that sin(asin(y)) = y
for y
in range [-1, 1]
.
Signature
asin(x: number) => number
Parameters
Name | Type | Description |
---|---|---|
x | number | Angle, in radians. |
Returns
The arcsine of a value; the returned angle is in the range [-Pi/2, Pi/2]
, or na if y is outside of range [-1, 1]
.
number
atan
The atan function returns the arctangent (in radians) of number such that tan(atan(y)) = y
for any y
.
Signature
atan(x: number) => number
Parameters
Name | Type | Description |
---|---|---|
x | number | Angle, in radians. |
Returns
The arc tangent of a value; the returned angle is in the range [-Pi/2, Pi/2]
.
number
atr
Function atr (average true range) returns the RMA of true range. True range is max(high - low, abs(high - close[1]), abs(low - close[1]))
Signature
atr(length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
length | number | Length (number of bars back). |
context | IContext | PineJS execution context. |
Returns
Average true range.
number
avg
Calculates average of all given series (elementwise).
Signature
avg(...values: number[]) => number
Parameters
Name | Type |
---|---|
...values | number[] |
Returns
the average of the values
number
ceil
The ceil function returns the smallest (closest to negative infinity) integer that is greater than or equal to the argument.
Signature
ceil(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The smallest integer greater than or equal to the given number.
number
change
Difference between current value and previous, x - x[1]
.
Signature
change(source: IPineSeries) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series to process. |
Returns
The result of subtraction.
number
close
Close Price
Signature
close(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Current close price.
number
compare
Compare the values of n1
and n2
Signature
compare(n1: number, n2: number, eps?: number) => 0 | 1 | -1
Parameters
Name | Type | Description |
---|---|---|
n1 | number | |
n2 | number | |
eps? | number | Epsilon (Optional). |
Returns
0
if values are equal. 1
if x1 is greater than x2. -1
if x1 is less than x2
0 | 1 | -1
correlation
Correlation coefficient. Describes the degree to which two series tend to deviate from their sma
values.
Signature
correlation(sourceA: IPineSeries, sourceB: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
sourceA | IPineSeries | Source series. |
sourceB | IPineSeries | Target series. |
length | number | Length (number of bars back). |
context | IContext | PineJS execution context. |
Returns
Correlation coefficient.
number
cos
The cos function returns the trigonometric cosine of an angle.
Signature
cos(x: number) => number
Parameters
Name | Type | Description |
---|---|---|
x | number | Angle, in radians. |
Returns
The trigonometric cosine of an angle.
number
createNewSessionCheck
checks whether a new session can be created
Signature
createNewSessionCheck(context: IContext) => (time: number) => boolean
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
checks whether a new session can be created
fn
Signature
(time: number) => boolean
Parameters
Name | Type |
---|---|
time | number |
Returns
boolean
cross
Crossing of series.
Signature
cross(n_0: number, n_1: number, context: IContext) => boolean
Parameters
Name | Type | Description |
---|---|---|
n_0 | number | First value. |
n_1 | number | Second value. |
context | IContext | PineJS execution context. |
Returns
true
if two series have crossed each other, otherwise false
.
boolean
cum
Cumulative (total) sum. The function tracks the previous values internally.
Signature
cum(n_value: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
n_value | number | Value to add to the sum. |
context | IContext | PineJS execution context. |
Returns
The sum.
number
currencyCode
Get the symbol currency code.
Signature
currencyCode(ctx: IContext) => string
Parameters
Name | Type | Description |
---|---|---|
ctx | IContext | PineJS execution context. |
Returns
Symbol currency code.
string
dayofmonth
Day of month for current bar time in exchange timezone.
Signature
dayofmonth(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Day of month for current bar time in exchange timezone.
number
dayofweek
Day of week for current bar time in exchange timezone.
Signature
dayofweek(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Day of week for current bar time in exchange timezone.
number
dev
Measure of difference between the series and its sma.
Signature
dev(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Deviation of source for length bars back.
number
dmi
Calculates the directional movement values +DI, -DI, DX, ADX, and ADXR.
Signature
dmi(diLength: number, adxSmoothingLength: number, context: IContext) => [number, number, number, number, number]
Parameters
Name | Type | Description |
---|---|---|
diLength | number | Number of bars (length) used when calculating the +DI and -DI values. |
adxSmoothingLength | number | Number of bars (length) used when calculating the ADX value. |
context | IContext | PineJS execution context. |
Returns
An array of the +DI, -DI, DX, ADX, and ADXR values with diLength smoothing for the (+/-)DI values and adxSmoothingLength for the ADX value.
[number, number, number, number, number]
ema
Exponential Moving Average. In EMA weighting factors decrease exponentially.
It calculates by using a formula: EMA = alpha * x + (1 - alpha) * EMA[1]
, where alpha = 2 / (y + 1)
.
Signature
ema(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Exponential moving average of x
with alpha = 2 / (y + 1)
number
eps
Epsilon (machine precision)
Signature
eps() => number
Returns
Epsilon (machine precision). Upper bound on the relative approximation error due to rounding in floating point arithmetic.
number
eq
Checks if n1
is equal to n2
.
Signature
eq(n1: number, n2: number) => number
Parameters
Name | Type |
---|---|
n1 | number |
n2 | number |
Returns
1
if n1
is equal to n2
, 0
otherwise.
number
equal
Checks if n1
is equal to n2
(within the accuracy of epsilon).
Signature
equal(n1: number, n2: number, eps?: number) => boolean
Parameters
Name | Type | Description |
---|---|---|
n1 | number | |
n2 | number | |
eps? | number | Epsilon (Optional). |
Returns
True if n1
is equal to n2
.
boolean
error
Display an error message.
Signature
error(message: string) => never
Parameters
Name | Type | Description |
---|---|---|
message | string | message to display for error |
Returns
never
exp
The exp function of x
is e^x
, where x
is the argument and e
is Euler's number.
Signature
exp(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
A number representing e^x
.
number
falling
Test if the series is now falling for length bars long.
Signature
falling(series: IPineSeries, length: number) => number
Parameters
Name | Type | Description |
---|---|---|
series | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
Returns
true
if current x
is less than any previous x
for length bars back, false
otherwise.
number
fixnan
For a given series replaces NaN values with previous nearest non-NaN value.
Signature
fixnan(n_current: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
n_current | number | Series of values to process. |
context | IContext | PineJS execution context. |
Returns
Series without na gaps.
number
floor
Round the number down to the closest integer
Signature
floor(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The largest integer less than or equal to the given number.
number
ge
Checks if n1
is greater than or equal to n2
Signature
ge(n1: number, n2: number) => number
Parameters
Name | Type |
---|---|
n1 | number |
n2 | number |
Returns
1
if n1
is greater than or equal to n2
, 0
otherwise.
number
greater
Checks if n1
is greater than n2
Signature
greater(n1: number, n2: number, eps?: number) => boolean
Parameters
Name | Type | Description |
---|---|---|
n1 | number | |
n2 | number | |
eps? | number | Epsilon (Optional). |
Returns
True if n1
is greater than n2
.
boolean
greaterOrEqual
Checks if n1
is greater than or equal to n2
Signature
greaterOrEqual(n1: number, n2: number, eps?: number) => boolean
Parameters
Name | Type | Description |
---|---|---|
n1 | number | |
n2 | number | |
eps? | number | Epsilon (Optional). |
Returns
True if n1
is greater than or equal to n2
.
boolean
gt
Checks if n1
is greater than n2
Signature
gt(n1: number, n2: number) => number
Parameters
Name | Type |
---|---|
n1 | number |
n2 | number |
Returns
1
if n1
is greater than n2
, 0
otherwise.
number
high
High Price
Signature
high(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Current high price.
number
highest
Highest value for a given number of bars back.
Signature
highest(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Highest value.
number
highestbars
Highest value offset for a given number of bars back.
Signature
highestbars(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Offset to the highest bar.
number
hl2
Is a shortcut for (high + low)/2
Signature
hl2(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Calculated average of the current HL values
number
hlc3
Is a shortcut for (high + low + close)/3
Signature
hlc3(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Calculated average of the current HLC values
number
hour
Hour of current bar time in exchange timezone.
Signature
hour(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Current bar hour in exchange timezone.
number
iff
If ... then ... else ...
iff
does exactly the same thing as ternary conditional operator ?:
but in a functional style. Also iff
is slightly less efficient than operator ?:
Signature
iff(condition: number, thenValue: number, elseValue: number) => number
Parameters
Name | Type | Description |
---|---|---|
condition | number | condition to check |
thenValue | number | value to use if condition is true |
elseValue | number | value to use if condition is false |
Returns
either thenValue or elseValue
number
interval
Get the symbol interval. For example: if the symbol has a resolution of 1D
then this function would return 1
.
Signature
interval(ctx: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
ctx | IContext | PineJS execution context. |
Returns
Symbol interval.
number
isdaily
Determines whether the current resolution is a daily resolution.
Signature
isdaily(context: IContext) => boolean
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
true if current resolution is a daily resolution
boolean
isdwm
Determines whether the current resolution is a daily, weekly, or monthly resolution.
Signature
isdwm(context: IContext) => boolean
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
true if current resolution is a daily or weekly or monthly resolution
boolean
isintraday
Determines whether the current resolution is an intraday (minutes or seconds) resolution.
Signature
isintraday(context: IContext) => boolean
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
true if current resolution is an intraday (minutes or seconds) resolution
boolean
ismonthly
Determines whether the current resolution is a monthly resolution.
Signature
ismonthly(context: IContext) => boolean
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
true if current resolution is a monthly resolution
boolean
isweekly
Determines whether the current resolution is a weekly resolution.
Signature
isweekly(context: IContext) => boolean
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
true if current resolution is a weekly resolution
boolean
le
Checks if n1
is less than or equal to n2
Signature
le(n1: number, n2: number) => number
Parameters
Name | Type |
---|---|
n1 | number |
n2 | number |
Returns
1
if n1
is greater than or equal to n2
, 0
otherwise.
number
less
Checks if n1
is less than n2
Signature
less(n1: number, n2: number, eps?: number) => boolean
Parameters
Name | Type | Description |
---|---|---|
n1 | number | |
n2 | number | |
eps? | number | Epsilon (Optional). |
Returns
True if n1
is less than n2
.
boolean
lessOrEqual
Checks if n1
is less than or equal to n2
Signature
lessOrEqual(n1: number, n2: number, eps?: number) => boolean
Parameters
Name | Type | Description |
---|---|---|
n1 | number | |
n2 | number | |
eps? | number | Epsilon (Optional). |
Returns
True if n1
is less than or equal to n2
.
boolean
linreg
Linear regression curve. A line that best fits the prices specified over a user-defined time period.
It is calculated using the least squares method. The result of this function is calculated using the formula:
linreg = intercept + slope * (length - 1 - offset)
, where intercept and slope are the values calculated with
the least squares method on source series (x argument).
Signature
linreg(source: IPineSeries, length: number, offset: number) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Source series. |
length | number | Length (number of bars back). |
offset | number | Offset (number of bars) |
Returns
Linear regression curve point.
number
log
Natural logarithm of any x > 0
is the unique y
such that e^y = x
Signature
log(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The natural logarithm of x
.
number
log10
Base 10 logarithm of any x > 0
is the unique y
such that 10^y = x
Signature
log10(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The base 10 logarithm of x
.
number
low
Low Price
Signature
low(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Current low price.
number
lowest
Lowest value for a given number of bars back.
Signature
lowest(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Lowest value.
number
lowestbars
Lowest value offset for a given number of bars back.
Signature
lowestbars(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Offset to the lowest bar.
number
lt
Checks if n1
is less than n2
Signature
lt(n1: number, n2: number) => number
Parameters
Name | Type |
---|---|
n1 | number |
n2 | number |
Returns
1
if n1
is less than n2
, 0
otherwise.
number
max
Maximum number in the array
Signature
max(...values: number[]) => number
Parameters
Name | Type |
---|---|
...values | number[] |
Returns
The greatest of multiple given values
number
min
Minimum number in the array
Signature
min(...values: number[]) => number
Parameters
Name | Type |
---|---|
...values | number[] |
Returns
The smallest of multiple given values
number
minute
Minute of current bar time in exchange timezone.
Signature
minute(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Current bar minute in exchange timezone.
number
month
Month of current bar time in exchange timezone.
Signature
month(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Current bar month in exchange timezone.
number
n
Current bar index
Signature
n(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Current bar index. Numbering is zero-based, index of the first historical bar is 0.
number
na
Test value if it's a NaN.
Signature
na(n?: number) => number
Parameters
Name | Type | Description |
---|---|---|
n? | number | value to test |
Returns
1
if n
is not a valid number ( n
is NaN
), otherwise 0
. Returns NaN
if n
is undefined.
number
neq
Checks if n1
is not equal to n2
.
Signature
neq(n1: number, n2: number) => number
Parameters
Name | Type |
---|---|
n1 | number |
n2 | number |
Returns
1
if n1
is not equal to n2
, 0
otherwise.
number
not
Logical negation (NOT).
Signature
not(n_0: number) => number
Parameters
Name | Type |
---|---|
n_0 | number |
Returns
1
if value is falsy, 0
if value is truthy.
number
nz
Replaces NaN values with zeros (or given value) in a series.
Signature
nz(x: number, y?: number) => number
Parameters
Name | Type | Description |
---|---|---|
x | number | value to test (and potentially replace) |
y? | number | fallback value. 0 by default. |
Returns
x
if it's a valid (not NaN) number, otherwise y
number
ohlc4
Is a shortcut for (open + high + low + close)/4
Signature
ohlc4(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Calculated average of the current OHLC values
number
open
Open Price
Signature
open(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Current open price.
number
or
Logical OR.
Signature
or(n_0: number, n_1: number) => number
Parameters
Name | Type |
---|---|
n_0 | number |
n_1 | number |
Returns
1
if either value is truthy, 0
otherwise.
number
percentrank
Percent rank is the percentage of how many previous values were less than or equal to the current value of given series.
Signature
percentrank(source: IPineSeries, length: number) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
Returns
Percent rank of source
for length
bars back.
number
period
Resolution string, e.g. 60 - 60 minutes, D - daily, W - weekly, M - monthly, 5D - 5 days, 12M - one year, 3M - one quarter
Signature
period(context: IContext) => string
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
The resolution string for the current context
string
pow
Mathematical power function.
Signature
pow(base: number, exponent: number) => number
Parameters
Name | Type | Description |
---|---|---|
base | number | Specify the base to use. |
exponent | number | Specifies the exponent. |
Returns
x
raised to the power of y
.
number
rising
Test if the series is now rising for length bars long.
Signature
rising(series: IPineSeries, length: number) => number
Parameters
Name | Type | Description |
---|---|---|
series | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
Returns
true
if current x
is greater than any previous x
for length bars back, false
otherwise.
number
rma
Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length
.
Signature
rma(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Exponential moving average of x
with alpha = 1 / y
.
number
roc
Rate of Change.
Function roc (rate of change) showing the difference between current value of source
and the value of source
that was length
days ago. It is calculated by the formula: 100 * change(src, length) / src[length]
.
Signature
roc(source: IPineSeries, length: number) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
Returns
The rate of change of source
for length
bars back.
number
round
Round the number to the nearest integer
Signature
round(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The value of x
rounded to the nearest integer, with ties rounding up. If the precision parameter is used, returns a float value rounded to that number of decimal places.
number
rsi
Relative strength index. It is calculated based on rma's of upward and downward change of x.
Signature
rsi(upper: number, lower: number) => number
Parameters
Name | Type | Description |
---|---|---|
upper | number | upward change |
lower | number | downward change |
Returns
Relative strength index.
number
sar
Parabolic SAR (parabolic stop and reverse) is a method devised by J. Welles Wilder, Jr., to find potential reversals in the market price direction of traded goods.
Signature
sar(start: number, inc: number, max: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
start | number | Start. |
inc | number | Increment. |
max | number | Maximum. |
context | IContext | PineJS execution context. |
Returns
Parabolic SAR value.
number
second
Second of current bar time in exchange timezone.
Signature
second(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Current bar second in exchange timezone.
number
selectSessionBreaks
select session breaks for intraday resolutions only
Signature
selectSessionBreaks(context: IContext, times: number[]) => number[]
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
times | number[] | An array of numbers representing the times to select session breaks from. |
Returns
session breaks for intraday resolutions only.
number[]
sign
Sign (signum) of x
is 0
if the x is zero, 1.0
if the x
is greater than zero, -1.0
if the x
is less than zero.
Signature
sign(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The sign of x
number
sin
The sin function returns the trigonometric sine of an angle.
Signature
sin(x: number) => number
Parameters
Name | Type | Description |
---|---|---|
x | number | Angle, in radians. |
Returns
The trigonometric sine of an angle.
number
sma
Simple Moving Average. The sum of last length
values of source
, divided by length
.
Signature
sma(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Simple moving average of x for y bars back.
number
smma
Smoothed Moving Average.
Signature
smma(n_value: number, n_length: number, ctx: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
n_value | number | Next value in the series to calculate. |
n_length | number | Smoothing length. |
ctx | IContext | PineJS execution context. |
Returns
The smoothed moving average value.
number
sqrt
Square root of any x >= 0
is the unique y >= 0
such that y^2 = x
Signature
sqrt(x: number) => number
Parameters
Name | Type |
---|---|
x | number |
Returns
The square root of x
number
stdev
Standard deviation. Note: This is a biased estimation of standard deviation.
Signature
stdev(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Standard deviation.
number
stoch
Stochastic. It is calculated by a formula: 100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length))
Signature
stoch(source: IPineSeries, high: IPineSeries, low: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Source series. |
high | IPineSeries | Series of high. |
low | IPineSeries | Series of low. |
length | number | Length (number of bars back). |
context | IContext | PineJS execution context. |
Returns
Stochastic value.
number
sum
The sum function returns the sliding sum of last y values of x.
Signature
sum(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Sum of x for y bars back.
number
swma
Symmetrically weighted moving average with fixed length: 4. Weights: [1/6, 2/6, 2/6, 1/6]
.
Signature
swma(source: IPineSeries, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
context | IContext | PineJS execution context. |
Returns
Symmetrically weighted moving average
number
tan
The tan function returns the trigonometric tangent of an angle.
Signature
tan(x: number) => number
Parameters
Name | Type | Description |
---|---|---|
x | number | Angle, in radians. |
Returns
The trigonometric tangent of an angle.
number
ticker
Ticker ID for the current symbol
Signature
ticker(context: IContext) => string
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Ticker ID for the current symbol
string
tickerid
Ticker ID
Signature
tickerid(context: IContext) => string
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Ticker ID for the current symbol
string
time
Current bar time
Signature
time(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
UNIX time of current bar
number
Current bar time
Signature
time(context: IContext, period: string, spec: unknown) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
period | string | Period |
spec | unknown |
Returns
UNIX time of current bar
number
toBool
Convert a number to a boolean.
Signature
toBool(v: number) => boolean
Parameters
Name | Type | Description |
---|---|---|
v | number | the value to convert. |
Returns
true
if the number is finite and non-zero, false
otherwise.
boolean
tr
True Range
Signature
tr(n_handleNaN: number, ctx: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
n_handleNaN | number | How NaN values are handled. If truthy, and previous bar's close is NaN then tr would be calculated as current bar high-low . Otherwise tr would return NaN in such cases. Also note, that atr uses tr(true) . |
ctx | IContext | PineJS execution context. |
Returns
True range. It is max(high - low, abs(high - close[1]), abs(low - close[1]))
number
tsi
True strength index. It uses moving averages of the underlying momentum of a financial instrument.
Signature
tsi(source: IPineSeries, shortLength: number, longLength: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Source series. |
shortLength | number | Length (number of bars back). |
longLength | number | Length (number of bars back). |
context | IContext | PineJS execution context. |
Returns
True strength index. A value in range [-1, 1]
number
unitId
Get the symbol unit ID.
Signature
unitId(ctx: IContext) => string
Parameters
Name | Type | Description |
---|---|---|
ctx | IContext | PineJS execution context. |
Returns
Symbol unit ID.
string
updatetime
Time of the current update
Signature
updatetime(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
symbol update time
number
variance
Variance is the expectation of the squared deviation of a series from its mean sma
, and it informally measures how far a set of numbers are spread out from their mean. Note: This is a biased estimation of sample variance.
Signature
variance(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Variance of source
for length
bars back.
number
volume
Current bar volume
Signature
volume(context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
Returns
Current bar volume
number
vwma
The vwma function returns volume-weighted moving average of source
for length
bars back. It is the same as: sma(x * volume, y) / sma(volume, y)
Signature
vwma(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Volume-weighted moving average of source
for length
bars back.
number
weekofyear
Week number of current bar time in exchange timezone.
Signature
weekofyear(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Week number of current bar in exchange timezone.
number
wma
The wma function returns weighted moving average of source
for length
bars back. In wma weighting factors decrease in arithmetical progression.
Signature
wma(source: IPineSeries, length: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
source | IPineSeries | Series of values to process. |
length | number | Number of bars (length). |
context | IContext | PineJS execution context. |
Returns
Weighted moving average of series
for length
bars back.
number
year
Year of current bar time in exchange timezone.
Signature
year(context: IContext, time?: number) => number
Parameters
Name | Type | Description |
---|---|---|
context | IContext | PineJS execution context. |
time? | number | optional time. Current bar time will be used by default. |
Returns
Current bar year in exchange timezone.
number
zigzag
Zig-zag pivot points
Signature
zigzag(n_deviation: number, n_depth: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
n_deviation | number | Deviation |
n_depth | number | Depth (integer) |
context | IContext | PineJS execution context. |
Returns
the zig-zag pivot points
number
zigzagbars
Zig-zag pivot points
Signature
zigzagbars(n_deviation: number, n_depth: number, context: IContext) => number
Parameters
Name | Type | Description |
---|---|---|
n_deviation | number | Deviation |
n_depth | number | Depth (integer) |
context | IContext | PineJS execution context. |
Returns
the zig-zag pivot points (for bars)
number