Skip to main content

Interface: PineJSStd

Charting Library.PineJSStd

PineJS standard library functions.

Properties

isZero

isZero: (v: number) => number

Check if a value is zero.

Type declaration

▸ (v): number

Parameters
NameTypeDescription
vnumberthe value to test.
Returns

number


max_series_default_size

max_series_default_size: 10001

Default maximum size of a pine series.

Methods

abs

abs(x): number

Absolute value of x is x if x >= 0, or -x otherwise.

Parameters

NameType
xnumber

Returns

number

The absolute value of x


accdist

accdist(context): number

Accumulation/distribution index.

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Accumulation/distribution index.


acos

acos(x): number

The acos function returns the arccosine (in radians) of number such that cos(acos(y)) = y for y in range [-1, 1].

Parameters

NameTypeDescription
xnumberAngle, in radians.

Returns

number

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].


add_days_considering_dst

add_days_considering_dst(timezone, utcTime, daysCount): Date

Get time in daysCount number of days while taking Daylight savings time into account.

Parameters

NameTypeDescription
timezonestringTimezone
utcTimeDateDate (JS built-in)
daysCountnumberNumber of days

Returns

Date

The time is daysCount number of days, taking into account Daylight savings time.


add_years_considering_dst

add_years_considering_dst(timezone, utcTime, yearsCount): Date

Get time in yearsCount number of years while taking Daylight savings time into account.

Parameters

NameTypeDescription
timezonestringTimezone
utcTimeDateDate (JS built-in)
yearsCountnumberNumber of years

Returns

Date

The time is yearsCount number of years, taking into account Daylight savings time.


alma

alma(series, length, offset, sigma): number

Arnaud Legoux Moving Average. It uses Gaussian distribution as weights for moving average.

Parameters

NameTypeDescription
seriesIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
offsetnumberControls tradeoff between smoothness (closer to 1) and responsiveness (closer to 0).
sigmanumberChanges the smoothness of ALMA. The larger sigma the smoother ALMA.

Returns

number


and

and(n_0, n_1): number

Logical AND.

Parameters

NameType
n_0number
n_1number

Returns

number

1 if both values are truthy, 0 otherwise.


asin

asin(x): number

The asin function returns the arcsine (in radians) of number such that sin(asin(y)) = y for y in range [-1, 1].

Parameters

NameTypeDescription
xnumberAngle, in radians.

Returns

number

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].


atan

atan(x): number

The atan function returns the arctangent (in radians) of number such that tan(atan(y)) = y for any y.

Parameters

NameTypeDescription
xnumberAngle, in radians.

Returns

number

The arc tangent of a value; the returned angle is in the range [-Pi/2, Pi/2].


atr

atr(length, context): number

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]))

Parameters

NameTypeDescription
lengthnumberLength (number of bars back).
contextIContextPineJS execution context.

Returns

number

Average true range.


avg

avg(...values): number

Calculates average of all given series (elementwise).

Parameters

NameType
...valuesnumber[]

Returns

number

the average of the values


ceil

ceil(x): number

The ceil function returns the smallest (closest to negative infinity) integer that is greater than or equal to the argument.

Parameters

NameType
xnumber

Returns

number

The smallest integer greater than or equal to the given number.


change

change(source): number

Difference between current value and previous, x - x[1].

Parameters

NameTypeDescription
sourceIPineSeriesSeries to process.

Returns

number

The result of subtraction.


close

close(context): number

Close Price

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Current close price.


compare

compare(n1, n2, eps?): -1 | 0 | 1

Compare the values of n1 and n2

Parameters

NameTypeDescription
n1number
n2number
eps?numberEpsilon (Optional).

Returns

-1 | 0 | 1

0 if values are equal. 1 if x1 is greater than x2. -1 if x1 is less than x2


correlation

correlation(sourceA, sourceB, length, context): number

Correlation coefficient. Describes the degree to which two series tend to deviate from their sma values.

Parameters

NameTypeDescription
sourceAIPineSeriesSource series.
sourceBIPineSeriesTarget series.
lengthnumberLength (number of bars back).
contextIContextPineJS execution context.

Returns

number

Correlation coefficient.


cos

cos(x): number

The cos function returns the trigonometric cosine of an angle.

Parameters

NameTypeDescription
xnumberAngle, in radians.

Returns

number

The trigonometric cosine of an angle.


createNewSessionCheck

createNewSessionCheck(context): (time: number) => boolean

checks whether a new session can be created

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

fn

checks whether a new session can be created

▸ (time): boolean

Parameters
NameType
timenumber
Returns

boolean


cross

cross(n_0, n_1, context): boolean

Crossing of series.

Parameters

NameTypeDescription
n_0numberFirst value.
n_1numberSecond value.
contextIContextPineJS execution context.

Returns

boolean

true if two series have crossed each other, otherwise false.


cum

cum(n_value, context): number

Cumulative (total) sum. The function tracks the previous values internally.

Parameters

NameTypeDescription
n_valuenumberValue to add to the sum.
contextIContextPineJS execution context.

Returns

number

The sum.


currencyCode

currencyCode(ctx): string

Get the symbol currency code.

Parameters

NameTypeDescription
ctxIContextPineJS execution context.

Returns

string

Symbol currency code.


dayofmonth

dayofmonth(context, time?): number

Day of month for current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Day of month for current bar time in exchange timezone.


dayofweek

dayofweek(context, time?): number

Day of week for current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Day of week for current bar time in exchange timezone.


dev

dev(source, length, context): number

Measure of difference between the series and its sma.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Deviation of source for length bars back.


dmi

dmi(diLength, adxSmoothingLength, context): [number, number, number, number, number]

Calculates the directional movement values +DI, -DI, DX, ADX, and ADXR.

Parameters

NameTypeDescription
diLengthnumberNumber of bars (length) used when calculating the +DI and -DI values.
adxSmoothingLengthnumberNumber of bars (length) used when calculating the ADX value.
contextIContextPineJS execution context.

Returns

[number, number, number, number, number]

An array of the +DI, -DI, DX, ADX, and ADXR values with diLength smoothing for the (+/-)DI values and adxSmoothingLength for the ADX value.


ema

ema(source, length, context): number

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).

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Exponential moving average of x with alpha = 2 / (y + 1)


eps

eps(): number

Epsilon (machine precision)

Returns

number

Epsilon (machine precision). Upper bound on the relative approximation error due to rounding in floating point arithmetic.


eq

eq(n1, n2): number

Checks if n1 is equal to n2.

Parameters

NameType
n1number
n2number

Returns

number

1 if n1 is equal to n2, 0 otherwise.


equal

equal(n1, n2, eps?): boolean

Checks if n1 is equal to n2 (within the accuracy of epsilon).

Parameters

NameTypeDescription
n1number
n2number
eps?numberEpsilon (Optional).

Returns

boolean

True if n1 is equal to n2.


error

error(message): never

Display an error message.

Parameters

NameTypeDescription
messagestringmessage to display for error

Returns

never


exp

exp(x): number

The exp function of x is e^x, where x is the argument and e is Euler's number.

Parameters

NameType
xnumber

Returns

number

A number representing e^x.


falling

falling(series, length): number

Test if the series is now falling for length bars long.

Parameters

NameTypeDescription
seriesIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).

Returns

number

true if current x is less than any previous x for length bars back, false otherwise.


fixnan

fixnan(n_current, context): number

For a given series replaces NaN values with previous nearest non-NaN value.

Parameters

NameTypeDescription
n_currentnumberSeries of values to process.
contextIContextPineJS execution context.

Returns

number

Series without na gaps.


floor

floor(x): number

Round the number down to the closest integer

Parameters

NameType
xnumber

Returns

number

The largest integer less than or equal to the given number.


ge

ge(n1, n2): number

Checks if n1 is greater than or equal to n2

Parameters

NameType
n1number
n2number

Returns

number

1 if n1 is greater than or equal to n2, 0 otherwise.


greater

greater(n1, n2, eps?): boolean

Checks if n1 is greater than n2

Parameters

NameTypeDescription
n1number
n2number
eps?numberEpsilon (Optional).

Returns

boolean

True if n1 is greater than n2.


greaterOrEqual

greaterOrEqual(n1, n2, eps?): boolean

Checks if n1 is greater than or equal to n2

Parameters

NameTypeDescription
n1number
n2number
eps?numberEpsilon (Optional).

Returns

boolean

True if n1 is greater than or equal to n2.


gt

gt(n1, n2): number

Checks if n1 is greater than n2

Parameters

NameType
n1number
n2number

Returns

number

1 if n1 is greater than n2, 0 otherwise.


high

high(context): number

High Price

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Current high price.


highest

highest(source, length, context): number

Highest value for a given number of bars back.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Highest value.


highestbars

highestbars(source, length, context): number

Highest value offset for a given number of bars back.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Offset to the highest bar.


hl2

hl2(context): number

Is a shortcut for (high + low)/2

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Calculated average of the current HL values


hlc3

hlc3(context): number

Is a shortcut for (high + low + close)/3

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Calculated average of the current HLC values


hour

hour(context, time?): number

Hour of current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Current bar hour in exchange timezone.


iff

iff(condition, thenValue, elseValue): number

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 ?:

Parameters

NameTypeDescription
conditionnumbercondition to check
thenValuenumbervalue to use if condition is true
elseValuenumbervalue to use if condition is false

Returns

number

either thenValue or elseValue


interval

interval(ctx): number

Get the symbol interval. For example: if the symbol has a resolution of 1D then this function would return 1.

Parameters

NameTypeDescription
ctxIContextPineJS execution context.

Returns

number

Symbol interval.


isdaily

isdaily(context): boolean

Determines whether the current resolution is a daily resolution.

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

boolean

true if current resolution is a daily resolution


isdwm

isdwm(context): boolean

Determines whether the current resolution is a daily, weekly, or monthly resolution.

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

boolean

true if current resolution is a daily or weekly or monthly resolution


isintraday

isintraday(context): boolean

Determines whether the current resolution is an intraday (minutes or seconds) resolution.

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

boolean

true if current resolution is an intraday (minutes or seconds) resolution


ismonthly

ismonthly(context): boolean

Determines whether the current resolution is a monthly resolution.

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

boolean

true if current resolution is a monthly resolution


isweekly

isweekly(context): boolean

Determines whether the current resolution is a weekly resolution.

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

boolean

true if current resolution is a weekly resolution


le

le(n1, n2): number

Checks if n1 is less than or equal to n2

Parameters

NameType
n1number
n2number

Returns

number

1 if n1 is greater than or equal to n2, 0 otherwise.


less

less(n1, n2, eps?): boolean

Checks if n1 is less than n2

Parameters

NameTypeDescription
n1number
n2number
eps?numberEpsilon (Optional).

Returns

boolean

True if n1 is less than n2.


lessOrEqual

lessOrEqual(n1, n2, eps?): boolean

Checks if n1 is less than or equal to n2

Parameters

NameTypeDescription
n1number
n2number
eps?numberEpsilon (Optional).

Returns

boolean

True if n1 is less than or equal to n2.


linreg

linreg(source, length, offset): number

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).

Parameters

NameTypeDescription
sourceIPineSeriesSource series.
lengthnumberLength (number of bars back).
offsetnumberOffset (number of bars)

Returns

number

Linear regression curve point.


log

log(x): number

Natural logarithm of any x > 0 is the unique y such that e^y = x

Parameters

NameType
xnumber

Returns

number

The natural logarithm of x.


log10

log10(x): number

Base 10 logarithm of any x > 0 is the unique y such that 10^y = x

Parameters

NameType
xnumber

Returns

number

The base 10 logarithm of x.


low

low(context): number

Low Price

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Current low price.


lowest

lowest(source, length, context): number

Lowest value for a given number of bars back.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Lowest value.


lowestbars

lowestbars(source, length, context): number

Lowest value offset for a given number of bars back.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Offset to the lowest bar.


lt

lt(n1, n2): number

Checks if n1 is less than n2

Parameters

NameType
n1number
n2number

Returns

number

1 if n1 is less than n2, 0 otherwise.


max

max(...values): number

Maximum number in the array

Parameters

NameType
...valuesnumber[]

Returns

number

The greatest of multiple given values


min

min(...values): number

Minimum number in the array

Parameters

NameType
...valuesnumber[]

Returns

number

The smallest of multiple given values


minute

minute(context, time?): number

Minute of current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Current bar minute in exchange timezone.


month

month(context, time?): number

Month of current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Current bar month in exchange timezone.


n

n(context): number

Current bar index

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Current bar index. Numbering is zero-based, index of the first historical bar is 0.


na

na(n?): number

Test value if it's a NaN.

Parameters

NameTypeDescription
n?numbervalue to test

Returns

number

1 if n is not a valid number (n is NaN), otherwise 0. Returns NaN if n is undefined.


neq

neq(n1, n2): number

Checks if n1 is not equal to n2.

Parameters

NameType
n1number
n2number

Returns

number

1 if n1 is not equal to n2, 0 otherwise.


not

not(n_0): number

Logical negation (NOT).

Parameters

NameType
n_0number

Returns

number

1 if value is falsy, 0 if value is truthy.


nz

nz(x, y?): number

Replaces NaN values with zeros (or given value) in a series.

Parameters

NameTypeDescription
xnumbervalue to test (and potentially replace)
y?numberfallback value. 0 by default.

Returns

number

x if it's a valid (not NaN) number, otherwise y


ohlc4

ohlc4(context): number

Is a shortcut for (open + high + low + close)/4

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Calculated average of the current OHLC values


open

open(context): number

Open Price

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Current open price.


or

or(n_0, n_1): number

Logical OR.

Parameters

NameType
n_0number
n_1number

Returns

number

1 if either value is truthy, 0 otherwise.


percentrank

percentrank(source, length): number

Percent rank is the percentage of how many previous values were less than or equal to the current value of given series.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).

Returns

number

Percent rank of source for length bars back.


period

period(context): string

Resolution string, e.g. 60 - 60 minutes, D - daily, W - weekly, M - monthly, 5D - 5 days, 12M - one year, 3M - one quarter

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

string

The resolution string for the current context


pow

pow(base, exponent): number

Mathematical power function.

Parameters

NameTypeDescription
basenumberSpecify the base to use.
exponentnumberSpecifies the exponent.

Returns

number

x raised to the power of y.


rising

rising(series, length): number

Test if the series is now rising for length bars long.

Parameters

NameTypeDescription
seriesIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).

Returns

number

true if current x is greater than any previous x for length bars back, false otherwise.


rma

rma(source, length, context): number

Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Exponential moving average of x with alpha = 1 / y.


roc

roc(source, length): number

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].

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).

Returns

number

The rate of change of source for length bars back.


round

round(x): number

Round the number to the nearest integer

Parameters

NameType
xnumber

Returns

number

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.


rsi

rsi(upper, lower): number

Relative strength index. It is calculated based on rma's of upward and downward change of x.

Parameters

NameTypeDescription
uppernumberupward change
lowernumberdownward change

Returns

number

Relative strength index.


sar

sar(start, inc, max, context): number

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.

Parameters

NameTypeDescription
startnumberStart.
incnumberIncrement.
maxnumberMaximum.
contextIContextPineJS execution context.

Returns

number

Parabolic SAR value.


second

second(context, time?): number

Second of current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Current bar second in exchange timezone.


selectSessionBreaks

selectSessionBreaks(context, times): number[]

select session breaks for intraday resolutions only

Parameters

NameTypeDescription
contextIContextPineJS execution context.
timesnumber[]An array of numbers representing the times to select session breaks from.

Returns

number[]

session breaks for intraday resolutions only.


sign

sign(x): number

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.

Parameters

NameType
xnumber

Returns

number

The sign of x


sin

sin(x): number

The sin function returns the trigonometric sine of an angle.

Parameters

NameTypeDescription
xnumberAngle, in radians.

Returns

number

The trigonometric sine of an angle.


sma

sma(source, length, context): number

Simple Moving Average. The sum of last length values of source, divided by length.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Simple moving average of x for y bars back.


smma

smma(n_value, n_length, ctx): number

Smoothed Moving Average.

Parameters

NameTypeDescription
n_valuenumberNext value in the series to calculate.
n_lengthnumberSmoothing length.
ctxIContextPineJS execution context.

Returns

number

The smoothed moving average value.


sqrt

sqrt(x): number

Square root of any x >= 0 is the unique y >= 0 such that y^2 = x

Parameters

NameType
xnumber

Returns

number

The square root of x


stdev

stdev(source, length, context): number

Standard deviation. Note: This is a biased estimation of standard deviation.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Standard deviation.


stoch

stoch(source, high, low, length, context): number

Stochastic. It is calculated by a formula: 100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length))

Parameters

NameTypeDescription
sourceIPineSeriesSource series.
highIPineSeriesSeries of high.
lowIPineSeriesSeries of low.
lengthnumberLength (number of bars back).
contextIContextPineJS execution context.

Returns

number

Stochastic value.


sum

sum(source, length, context): number

The sum function returns the sliding sum of last y values of x.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Sum of x for y bars back.


swma

swma(source, context): number

Symmetrically weighted moving average with fixed length: 4. Weights: [1/6, 2/6, 2/6, 1/6].

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
contextIContextPineJS execution context.

Returns

number

Symmetrically weighted moving average


tan

tan(x): number

The tan function returns the trigonometric tangent of an angle.

Parameters

NameTypeDescription
xnumberAngle, in radians.

Returns

number

The trigonometric tangent of an angle.


ticker

ticker(context): string

Ticker ID for the current symbol

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

string

Ticker ID for the current symbol


tickerid

tickerid(context): string

Ticker ID

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

string

Ticker ID for the current symbol


time

time(context): number

Current bar time

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

UNIX time of current bar according to the symbol timezone and not UTC.

time(context, period): number

Current bar time

Parameters

NameTypeDescription
contextIContextPineJS execution context.
periodstringPeriod

Returns

number

UNIX time of current bar according to the symbol timezone and not UTC.


toBool

toBool(v): boolean

Convert a number to a boolean.

Parameters

NameTypeDescription
vnumberthe value to convert.

Returns

boolean

true if the number is finite and non-zero, false otherwise.


tr

tr(n_handleNaN, ctx): number

True Range

Parameters

NameTypeDescription
n_handleNaNnumberHow 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).
ctxIContextPineJS execution context.

Returns

number

True range. It is max(high - low, abs(high - close[1]), abs(low - close[1]))


tsi

tsi(source, shortLength, longLength, context): number

True strength index. It uses moving averages of the underlying momentum of a financial instrument.

Parameters

NameTypeDescription
sourceIPineSeriesSource series.
shortLengthnumberLength (number of bars back).
longLengthnumberLength (number of bars back).
contextIContextPineJS execution context.

Returns

number

True strength index. A value in range [-1, 1]


unitId

unitId(ctx): string

Get the symbol unit ID.

Parameters

NameTypeDescription
ctxIContextPineJS execution context.

Returns

string

Symbol unit ID.


updatetime

updatetime(context): number

Time of the current update

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

symbol update time


variance

variance(source, length, context): number

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.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Variance of source for length bars back.


volume

volume(context): number

Current bar volume

Parameters

NameTypeDescription
contextIContextPineJS execution context.

Returns

number

Current bar volume


vwma

vwma(source, length, context): number

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)

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Volume-weighted moving average of source for length bars back.


weekofyear

weekofyear(context, time?): number

Week number of current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Week number of current bar in exchange timezone.


wma

wma(source, length, context): number

The wma function returns weighted moving average of source for length bars back. In wma weighting factors decrease in arithmetical progression.

Parameters

NameTypeDescription
sourceIPineSeriesSeries of values to process.
lengthnumberNumber of bars (length).
contextIContextPineJS execution context.

Returns

number

Weighted moving average of series for length bars back.


year

year(context, time?): number

Year of current bar time in exchange timezone.

Parameters

NameTypeDescription
contextIContextPineJS execution context.
time?numberoptional time. Current bar time will be used by default.

Returns

number

Current bar year in exchange timezone.


zigzag

zigzag(n_deviation, n_depth, context): number

Zig-zag pivot points

Parameters

NameTypeDescription
n_deviationnumberDeviation
n_depthnumberDepth (integer)
contextIContextPineJS execution context.

Returns

number

the zig-zag pivot points


zigzagbars

zigzagbars(n_deviation, n_depth, context): number

Zig-zag pivot points

Parameters

NameTypeDescription
n_deviationnumberDeviation
n_depthnumberDepth (integer)
contextIContextPineJS execution context.

Returns

number

the zig-zag pivot points (for bars)