Skip to main content

Lifecycle Reference

HyperionX scripts are state-driven. Most script setup belongs in OnStateChanged(). Calculation logic belongs in OnBarUpdate().

State Values

The runtime state enum currently includes:

StateMeaning
UndefinedScript is not initialized or has been stopped.
SetDefaultsSet name, version, default parameters, and default plot definitions.
ConfiguredAllocate runtime series, add plots/panes, add extra data series, and create child indicators.
HistoricalHistorical calculation is running.
FinalizedRuntime context is being released.
CalculatedCalculation finished.
PlaybackPlayback/replay mode is running.
RealTimeLive calculation is running.
DataLoadedData has loaded.
TransitionRuntime is moving between states.
TerminatedScript is terminating.

Standard Pattern

public override void OnStateChanged()
{
if (State == State.SetDefaults)
{
Name = "My Script";
Version = "1.0";
}
else if (State == State.Configured)
{
// Allocate series, child indicators, panes, plots, and extra series.
}
}

public override void OnBarUpdate()
{
if (CurrentBar < 20)
return;

// Per-bar logic.
}

Setup Responsibilities

Use State.SetDefaults for stable defaults:

  • Name
  • Version
  • [HyperionXProperty] default values
  • plot appearance defaults
  • non-runtime constants

Use State.Configured for runtime objects:

  • Series<double> instances
  • AddSeries(...)
  • AddPane(...)
  • AddPanePlot(...)
  • plot DataSource assignment
  • child indicators such as SMA(20)
  • AddDataSeries(...)

Update Methods

MethodPurpose
OnBarUpdate()Main per-bar calculation.
OnTickUpdate(ICandle candle, ICandle tick)Tick update hook when tick data is available.
OnMarketData(MarketDataEventArgs marketData)Market data update hook with price, volume, bid/ask volume, and trade count fields.
OnMarketDepth(MarketDepthEventArgs marketDepth)Depth snapshot hook after depth data is requested or subscribed.
OnAfterBarUpdate()Runtime post-update hook. Most scripts do not override it.
OnConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, string connectionName)Connection state changes.

Bar Guards

Always check CurrentBar before reading prior bars.

if (CurrentBar < Period + 1)
return;

double prior = Close[1];
double older = Close[Period];

The indexer uses bars ago. Close[0] is the current bar. Close[1] is one bar ago.

Multi-Series Timing

BarsInProgress identifies the series currently being processed. Primary series is 0. Extra data series use indexes starting at 1.

if (BarsInProgress != 0)
return;

Use CurrentBars[seriesIndex] before reading extra series values.

Calculation Mode

Scripts expose Calculate, which is a CalculateMode value. The default is OnBarClose.

The current chart/data context determines when real-time or playback scripts receive updates. Strategy developers should explicitly test the same mode they intend to trade.