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:
| State | Meaning |
|---|---|
Undefined | Script is not initialized or has been stopped. |
SetDefaults | Set name, version, default parameters, and default plot definitions. |
Configured | Allocate runtime series, add plots/panes, add extra data series, and create child indicators. |
Historical | Historical calculation is running. |
Finalized | Runtime context is being released. |
Calculated | Calculation finished. |
Playback | Playback/replay mode is running. |
RealTime | Live calculation is running. |
DataLoaded | Data has loaded. |
Transition | Runtime is moving between states. |
Terminated | Script 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:
NameVersion[HyperionXProperty]default values- plot appearance defaults
- non-runtime constants
Use State.Configured for runtime objects:
Series<double>instancesAddSeries(...)AddPane(...)AddPanePlot(...)- plot
DataSourceassignment - child indicators such as
SMA(20) AddDataSeries(...)
Update Methods
| Method | Purpose |
|---|---|
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.