Skip to main content

Series And Bars Reference

HyperionX series use bars-ago indexing. Close[0] is the current bar, Close[1] is the previous bar, and Close[10] is ten bars ago.

Bar Counts And Absolute Indexes

CurrentBar is the number of primary bars processed by the script, not a zero-based absolute index. On the first processed bar, CurrentBar is 1, while the corresponding absolute storage index is 0.

The bars-ago mapping is:

absolute index = CurrentBar - 1 - barsAgo

This is why a read of Close[1] requires CurrentBar >= 2. CurrentBars[seriesIndex] follows the same count convention for each configured series.

Out-of-range reads can look valid

Primary OHLCV series return 0 when a bars-ago request falls outside the available candles. Generic Series<T> reads and invalid GetValueAt(...) calls return default(T). Do not use those fallback values as evidence that a series is ready; guard every read with CurrentBar, CurrentBars, or IsValidPoint(...). Some specialized secondary-series accessors can reject an invalid index instead of returning a fallback.

Series Interface

Common series methods and properties:

MemberPurpose
series[0]Get or set the current bars-ago value.
CountNumber of values in the series.
GetValueAt(index)Reads by zero-based absolute internal index; the core Series<T> implementation returns default(T) when the index is invalid.
GetRange(startIndex, count)Reads a range by absolute index.
IsValidPoint(index)Checks whether an absolute index is valid.
SetValid(index)Marks a point as valid.

For normal script logic, prefer bars-ago access.

Custom Output Series

Indicators should register custom series before writing to them.

[Browsable(false)]
[XmlIgnore]
public Series<double> Signal { get; set; }

public override void OnStateChanged()
{
if (State == State.Configured)
{
Signal = new Series<double>();
AddSeries(Signal);
}
}

Write the current value in OnBarUpdate().

Signal[0] = Close[0] - Close[1];

Extra Data Series

Use AddDataSeries(...) in State.Configured.

AddDataSeries(DataSeriesType.Minute, 60);
AddDataSeries(DataSeriesType.Day, 1, "BTC");

Available data series types:

TypeDescription
DataSeriesType.TickTick bars.
DataSeriesType.SecondSecond bars.
DataSeriesType.MinuteMinute bars.
DataSeriesType.HourHour bars.
DataSeriesType.DayDaily bars.
DataSeriesType.WeekWeekly bars.
DataSeriesType.MonthMonthly bars.

Multi-Series Access

After an extra series is configured:

double primaryClose = Closes[0][0];
double hourlyClose = Closes[1][0];
double hourlyVolume = Volumes[1][0];
System.DateTime hourlyTime = DateTimes[1][0];

Guard both primary and secondary series.

if (CurrentBars[0] < 50 || CurrentBars[1] < 10)
return;

Use BarsInProgress when logic should only run for one series.

if (BarsInProgress != 0)
return;

During a secondary-series callback, BarsInProgress identifies the series being processed, while CurrentBar remains the primary-series count. Route reads through the plural collections and guard the active count explicitly:

int seriesIndex = BarsInProgress;
if (CurrentBars[seriesIndex] < 2)
return;

double current = Closes[seriesIndex][0];
double previous = Closes[seriesIndex][1];

Bar Timing Context

Ctx.MarketData exposes time-based helpers:

System.TimeSpan? duration = Ctx.MarketData.GetCurrentBarDuration();
System.TimeSpan? remaining = Ctx.MarketData.GetTimeRemainingInBar();
System.DateTime? openTime = Ctx.MarketData.GetCurrentBarOpenTime();
System.DateTime? closeTime = Ctx.MarketData.GetCurrentBarCloseTime();

Tick series may not have a predictable close time. These helpers can return null.

Common Mistakes

ProblemFix
Reading Close[1] on the first barGuard with if (CurrentBar < 2) return;.
Treating an out-of-range numeric read as real zero dataGuard the bar count before reading; standard numeric series use 0 as their fallback.
Using DateTime.Now and getting a compile issueUse System.DateTime.Now; DateTime is also a bar series.
Adding a data series in OnBarUpdate()Add it in State.Configured.
Writing a series before AddSeries(...)Allocate and register in State.Configured.
Accessing Closes[1] before the extra series is readyGuard CurrentBars[1].