Skip to content

Series

Series

An indexed, time-ordered stream of values. Read it with at(0) for the current bar and at(n) for n bars ago — indexing is bounded to the past, so there is no look-ahead. highest(period) and lowest(period) scan the trailing window, and length reports how many values are available. Indicators return a Series<T>.

Signature

export interface Series<T = number> {
at(back: number): T;
readonly length: number;
highest(period: number): number;
lowest(period: number): number;
}

Example

indicators/sma-trend
import { defineStrategy, SMA } from '@nexpips/sdk-trading';
/**
* Filtre de tendance : n'acheter que lorsque la clôture est au-dessus de
* la moyenne mobile simple SMA(50).
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 },
setup: (api) => {
const sma = api.use(SMA, { source: 'close', period: 50 });
return {
onBar(ctx) {
if (!ctx.position.isFlat || ctx.position.hasPendingOrder) return;
if (ctx.series.close.at(0) > sma.at(0)) {
ctx.order.marketBuy({
riskPercent: 1,
stopLoss: { type: 'atr', period: 14, multiple: 2 },
takeProfit: { type: 'rr', value: 2 },
});
}
},
};
},
});

Read the latest indicator value with at(0).

See also