Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/PineTS.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class PineTS {
public hlcc4: any = [];
public openTime: any = [];
public closeTime: any = [];
public bar_index: any = [];
//#endregion

//#region run context
Expand Down Expand Up @@ -82,6 +83,7 @@ export class PineTS {
const _hlcc4 = marketData.map((d) => (d.high + d.low + d.close + d.close) / 4);
const _openTime = marketData.map((d) => d.openTime);
const _closeTime = marketData.map((d) => d.closeTime);
const _bar_index = marketData.map((d, index) => index);

this.open = _open;
this.close = _close;
Expand All @@ -94,6 +96,7 @@ export class PineTS {
this.hlcc4 = _hlcc4;
this.openTime = _openTime;
this.closeTime = _closeTime;
this.bar_index = _bar_index;

if (source && (source as IProvider).getSymbolInfo) {
const symbolInfo = (source as IProvider)
Expand Down Expand Up @@ -482,6 +485,7 @@ export class PineTS {
this.hlcc4[index] = (candle.high + candle.low + candle.close + candle.close) / 4;
this.openTime[index] = candle.openTime;
this.closeTime[index] = candle.closeTime;
this.bar_index[index] = index;
}

/**
Expand All @@ -501,6 +505,7 @@ export class PineTS {
this.hlcc4.push((candle.high + candle.low + candle.close + candle.close) / 4);
this.openTime.push(candle.openTime);
this.closeTime.push(candle.closeTime);
this.bar_index.push(this.bar_index.length)
}

/**
Expand Down Expand Up @@ -587,6 +592,7 @@ export class PineTS {
context.data.hlcc4 = new Series([]);
context.data.openTime = new Series([]);
context.data.closeTime = new Series([]);
context.data.bar_index = new Series([]);

context.length = this.data.length;

Expand Down
3 changes: 1 addition & 2 deletions src/transpiler/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ASYNC_METHODS = ['request.security', 'request.security_lower_tf'];
export const FACTORY_METHODS = ['line.new', 'line.copy', 'label.new', 'label.copy', 'polyline.new', 'box.new', 'box.copy', 'table.new'];

// All known data variables in the context
export const CONTEXT_DATA_VARS = ['open', 'high', 'low', 'close', 'volume', 'hl2', 'hlc3', 'ohlc4', 'hlcc4', 'openTime', 'closeTime'];
export const CONTEXT_DATA_VARS = ['open', 'high', 'low', 'close', 'volume', 'hl2', 'hlc3', 'ohlc4', 'hlcc4', 'openTime', 'closeTime', 'bar_index'];

// All known Pine variables in the context
export const CONTEXT_PINE_VARS = [
Expand Down Expand Up @@ -69,7 +69,6 @@ export const CONTEXT_PINE_VARS = [
'barstate',

//builtin variables
'bar_index',
'last_bar_index',
'last_bar_time',
'inputs',
Expand Down