Skip to main content
Version: v27

IPineSeries

Interface

Methods

adopt

Map some values from one time scale to another.

Example

// A pine series with values [5, 5]
const sourceTimes = ctx.new_var();
// A pine series with values [4, 5]
const destinationTimes = ctx.new_var();
// A pine series with values [1, 2]
const values = ctx.new_var();

// Creates a pine series with values [2, 2]
const adopted1 = values.adopt(sourceTimes, destinationTimes, 0);

// Creates a pine series with values [NaN, 2]
const adopted2 = values.adopt(sourceTimes, destinationTimes, 1);

Example

Psuedocode of the adopt algorithm:

adopt(sourceSeries, destinationSeries, mode) =
destinationValue = most recent value in destinationSeries
sourceIndex = index of destinationValue in sourceSeries

if mode equals 1 then
previousDestinationValue = second most recent value in destinationSeries
previousSourceIndex = index of previousDestinationValue in sourceSeries

if sourceIndex equals previousSourceIndex
return NaN

return value at sourceIndex

Signature

adopt(source: IPineSeries, destination: IPineSeries, mode: 0 | 1) => number

Parameters

NameTypeDescription
sourceIPineSeriesSource times.
destinationIPineSeriesDestination times.
mode0 | 1Adopt mode. 0 for continuous, 1 for precise. In continuous mode (0) every source time will be mapped to a destination time if one exists. Multiple source times may be mapped to the same destination time. In precise mode (1) every source time will be mapped to a destination time AT MOST ONCE if one exists. Some source times may not be mapped.

Returns

number


get

Get the value at a specific index.

Note: The indices of a pine series is opposite.

Example:

  • s.get(1) returns second last,
  • s.get(2) - third last
  • and so on

Signature

get(n?: number) => number

Parameters

NameTypeDescription
n?numberindex

Returns

number


indexOf

Get the index for the bar at the specified timestamp

Signature

indexOf(time: number) => number

Parameters

NameTypeDescription
timenumbertimestamp

Returns

number


set

Set the value for the pine series at the current index interation.

Signature

set(value: number) => void

Parameters

NameTypeDescription
valuenumbervalue to be set

Returns

void