Skip to main content

V2 Script API

HyperionX 1.1.12 introduced V2, an opt-in facade available to normal Code Lab indicators and strategies. It adds selected-series reads and versioned indicator entry points without changing the behavior of existing Open, Close, Closes, or legacy indicator-helper calls.

V2 is useful when you are creating a new script that needs explicit series selection or when you are converting a script you own and want to adopt the versioned behavior gradually. It is not a new script base class, an automatic converter, or a new order API.

Clean-room examples

Every example on this page was written only to demonstrate API mechanics. When converting code, use only source you own or have permission to modify. Do not place third-party strategy names, source, parameters, rules, results, screenshots, prompts, or conversion history in public documentation, AI prompts, support messages, or shared examples.

Compatibility

Use V2 with the generated HyperionX.Custom.Indicators.Indicator or HyperionX.Custom.Strategies.Strategy model in HyperionX 1.1.12 or later. The signed 1.1.12 baseline introduced direct selected-series reads and the versioned indicator entry points. Confirm the exact installed build before distributing a script because later builds can correct behavior within those versioned entry points.

Secondary-series indicator binding is build-specific

The active development source contains corrections that bind a V2 child indicator's OHLCV values, readiness, updates, nested indicators, and outputs to an explicitly selected secondary-series timeline. Do not assume the original signed 1.1.12 package contains all of those later corrections. Direct V2.Series(index) reads are part of the 1.1.12 contract; verify release notes and the exact packaged build before relying on a V2 child indicator bound to V2.Series(1).Close or another secondary input.

The V2 facade and HyperionX.SDK are different surfaces:

SurfaceMeaning
V2An inherited ScriptBase property used inside the established HyperionX.Custom lifecycle.
HyperionX.SDKA separate adapter and lifecycle for direct SDK base classes. It does not enable or replace V2.

Do not derive from ScriptApiV2. Start from the normal Code Lab indicator or strategy template and opt in only where needed.

Opt In

Every normal Code Lab indicator and strategy inherits the V2 property. Series access needs no additional namespace:

var primary = V2.Series(0);

if (!primary.IsReady(2))
return;

double newestClose = primary.Close[0];
double previousClose = primary.Close[1];

Add these imports to use the versioned indicator extension methods, their return types, and ScriptOptions:

using HyperionX.Core.DataCalc;
using HyperionX.Custom.Indicators;

Then initialize child indicators in State.Configured, as you would with legacy helpers:

private V2EMA _average = null!;

public override void OnStateChanged()
{
if (State == State.Configured)
{
var quiet = new ScriptOptions
{
ShowPlots = false,
ShowPanes = false
};

_average = V2.EMA(V2.Series(0).Close, 12, quiet);
}
}

public override void OnBarUpdate()
{
var primary = V2.Series(0);
if (!primary.IsReady(12))
return;

double currentAverage = _average.MA[0];
// Use the value in code you own and have validated.
}

If the script does not configure ScriptOptions, only the HyperionX.Custom.Indicators import is required for the versioned indicator calls.

Selected-Series Reads

V2.Series(seriesIndex) returns a ScriptBarsV2 view of one loaded series.

MemberMeaning
Open, High, Low, Close, VolumeBars-ago numeric series for the selected index.
TimeBars-ago System.DateTime series for the selected index.
CountTotal candles currently loaded for the selected series.
CurrentBarNumber of selected-series bars available at the current callback anchor.
IsReady(requiredBars)Returns whether CurrentBar meets the requested minimum.

Series index 0 is the primary series. Additional series are numbered 1, 2, and so on in the order they are added with AddDataSeries(...).

During a callback for the selected series, [0] is the bar scheduled for that callback. When reading another series, HyperionX anchors [0] to the latest bar whose close time is not later than the current event's close time. This avoids treating a future secondary bar as though it were already available.

Always guard reads with IsReady(...). An unavailable numeric value returns 0, and an unavailable time returns the default System.DateTime; neither default proves that a real bar exists. A negative bars-ago value or an index for a series that was not loaded throws an argument-range exception.

Synthetic multi-series read

This fragment adds one secondary series and compares timestamps without placing an order:

public override void OnStateChanged()
{
if (State == State.Configured)
AddDataSeries(DataSeriesType.Minute, 15);
}

public override void OnBarUpdate()
{
var primary = V2.Series(0);
var secondary = V2.Series(1);

if (!primary.IsReady(2) || !secondary.IsReady(2))
return;

System.DateTime primaryTime = primary.Time[0];
System.DateTime secondaryTime = secondary.Time[0];
double secondaryClose = secondary.Close[0];

// Inspect or log these synthetic values while validating series alignment.
}

Continue to route multi-series callbacks with BarsInProgress when the script performs different work for each callback. Selecting a series for a read does not replace callback routing.

Versioned Indicator Entry Points

The bundled HyperionX.Custom.Indicators V2 extension file exposes these entry points:

CallParametersExplicit input overloadCommon output series
V2.ATR(...)periodYesATRValue, TrueRange
V2.EMA(...)periodYesMA
V2.SMA(...)periodYesMA
V2.RSI(...)period, optional smoothYesRSIValues, AvRSIValues
V2.MACD(...)fastPeriod, slowPeriod, smoothPeriodYesMACDValues, Average, Diff
V2.Stochastics(...)periodK, periodD, smooth, optional thresholdNoK, D
V2.StochasticRSI(...)periodNoStochRSIValue
V2.StDev(...)periodNoStDeviation
V2.BollingerBands(...)period, stDevMultiplierNoMiddleBand, TopBand, BottomBand
V2.ADXSuit(...)period, selectedViewNoADX, DiPlus, DiMinus
V2.VWAP(...)period, sessionStartHour, sessionStartMinuteNoVWAPVal

Every call also accepts an optional ScriptOptions argument. Calls without an explicit input use the owning script's Input. Where an explicit input overload is listed, the current API accepts a selected V2 price series as the child's input:

private V2EMA _secondaryAverage = null!;

public override void OnStateChanged()
{
if (State == State.Configured)
{
AddDataSeries(DataSeriesType.Minute, 15);
_secondaryAverage = V2.EMA(V2.Series(1).Close, 10);
}
}

In a build that includes the selected-secondary-timeline corrections, a child bound to V2.Series(1).Close uses the selected series for its bar readiness, input, inherited OHLCV values, output storage, and scheduling. Treat this as version-gated and test it against the exact packaged build used for deployment.

The V2 indicator types have separate runtime identities from their legacy counterparts. For example, a versioned EMA and a legacy EMA do not share one indicator instance or calculation cache. Versioned ATR, EMA, and session VWAP also define their version-specific calculation behavior; do not assume they will reproduce legacy output bar for bar.

Cache And Instance Rules

Within one calculation context, a V2 indicator helper reuses an existing child when these values match:

  • Concrete V2 indicator type.
  • Input-series object.
  • Parameters represented by that helper.

In the current implementation, ScriptOptions is applied when a child is created but is not part of the V2 reuse match. Use one consistent option set for a given type, input, and parameter combination. Create child indicators once in State.Configured and store the returned instance instead of requesting them repeatedly in OnBarUpdate().

Cache identity does not cross a runtime host, application restart, or custom-assembly reload. After a Code Lab build, an already-loaded script remains an instance of the assembly that created it. Remove and add the script again, or reload its owning host, before judging the new result.

Create A New Script With V2

  1. Confirm HyperionX 1.1.12 or later is installed.
  2. Create a normal indicator or strategy from the closest Code Lab template.
  3. Keep the established HyperionX.Custom namespace, base class, and OnStateChanged() / OnBarUpdate() lifecycle.
  4. Add using HyperionX.Custom.Indicators; if the script calls versioned indicators.
  5. Add any secondary series in State.Configured.
  6. Create and retain V2 child indicators in State.Configured.
  7. Use V2.Series(index).IsReady(...) before every selected-series bars-ago read.
  8. Build the complete custom project and fix every diagnostic.
  9. Create a fresh runtime instance and validate it with controlled data.

Do not copy internal platform types or the implementation of ScriptApiV2 into a custom script. The inherited facade and bundled public extension methods are the supported entry points.

Convert A Script You Own

V2 is intentionally opt-in, so a conversion can be incremental. Existing legacy members retain their prior behavior until you replace a particular read or helper call.

Use this conversion sequence:

  1. Confirm you own the source or have explicit permission to convert it.
  2. Freeze the original script, target HyperionX version, test data, settings, and expected output outside the public documentation repository.
  3. Copy the script under a new class name and version so the original remains available for comparison.
  4. Keep lifecycle, parameters, plots, and order handling unchanged during the first V2 pass.
  5. Replace one series family at a time:
    • Close[0] becomes V2.Series(0).Close[0] when explicit primary selection is wanted.
    • Closes[index][barsAgo] becomes V2.Series(index).Close[barsAgo].
    • DateTimes[index][barsAgo] becomes V2.Series(index).Time[barsAgo].
    • CurrentBars[index] checks can become V2.Series(index).IsReady(requiredBars).
  6. Replace a legacy indicator helper only when you deliberately want the versioned result, such as EMA(input, period) becoming V2.EMA(input, period).
  7. Compile and compare after each small change. Do not combine a V2 migration with unrelated parameter, risk, session, or order changes.
  8. Recreate the runtime instance after every build.
  9. Validate historical, Playback, and real-time behavior before considering live use.

Mixed legacy and V2 calls are allowed during a staged conversion, but give each result a clear field name and do not assume their warm-up, cache, or output values are interchangeable.

Validation Checklist

  • Record the exact HyperionX build used for the test.
  • Confirm the complete custom project compiles, not just one file.
  • Create a fresh runtime instance after compilation.
  • Verify series indexes and BarsInProgress routing.
  • Test unequal primary and secondary history and a secondary series with no bars.
  • Test the first usable bar and every bars-ago boundary.
  • Compare legacy and V2 outputs on the same fixed dataset when migrating.
  • Test each supported calculation mode used by the script.
  • Run strategy behavior in Validator where available, then Playback and LocalPaper.
  • Review order, position, session, and restart behavior separately from indicator-value parity.
  • Re-run the matrix after every platform update.

Troubleshooting

SymptomCheck
V2 is not foundVerify the installed HyperionX build is 1.1.12 or later and that the script derives from the normal Code Lab indicator or strategy base.
V2.EMA(...) or another indicator call is not foundAdd using HyperionX.Custom.Indicators;, confirm the bundled V2 indicator extension file exists, and rebuild the complete custom project.
Series index ... is unavailableAdd the expected series first and verify its index/order.
A selected-series value is unexpectedly zero or the time is defaultGuard with IsReady(...); the selected series may not have an eligible bar at the current callback time.
A different ScriptOptions value has no effectThe matching V2 child may already be cached; configure options consistently and recreate the host.
Output still reflects old code after a successful buildRemove and add the script again or reload the owning host to create an instance from the new assembly.

Continue with Code Lab, the Code Lab API Reference, Script Lifecycle And Calculation, and Build, Test, And Debug.