HyperionXScript Context
Indicators and strategies expose Ctx, a grouped facade over the current calculation host. Prefer it to concrete windows, controls, sessions, connections, and provider implementations.
| Group | Indicator | Strategy | Purpose |
|---|---|---|---|
Ctx.Chart | Yes | Yes | Visible range, chart coordinates, panes, and invalidation. |
Ctx.MarketData | Yes | Yes | Instrument identity, price/depth snapshots, candles, and bar timing. |
Ctx.Drawing | Yes | Yes | Script-owned fixed text and HUD drawings. |
Ctx.Alerts | Preview | Preview | Current Discord signal bridge. |
Ctx.Orders | No | Yes | Managed and direct strategy order actions. |
Ctx.Account | Read-only | Read-only | Account values plus order and position snapshots. |
Ctx.Position | Read-only | Read-only | Current strategy-position snapshot. |
Ctx.Log | Yes | Yes | Bounded diagnostic output. |
Ctx.Runtime | Yes | Yes | Current bar, series index, calculation mode, state, and optimization flag. |
Order methods enforce the strategy boundary at runtime. Calling Ctx.Orders from an indicator throws; it does not turn the indicator into an execution component.
Chart
Ctx.Chart exposes:
VisibleFromIndex,VisibleToIndex, andVisibleCount.PriceMinandPriceMax.CandleWidthandCandleGap.- Read-only pane names through
Panes. GetXByBarIndex(index),GetYByPrice(price), andGetPriceByY(y).Invalidate(),InvalidateVisual(), andInvalidateOverlay().
Chart coordinates are only meaningful in a chart-backed host. Research, optimization, and other chartless contexts can return empty collections or zero values. Custom visual rendering belongs in the Chart Rendering API; do not store or mutate internal WPF chart controls.
Market data
Identity and current values:
Symbol,Instrument,ConnectionName,TickSize, andMultiplier.Last,Bid,Ask, andSpread.IsTimeBasedSeries.
History and time:
GetCandles(int seriesIndex = 0)returns a read-only snapshot list, not a live mutable series.GetCurrentBarOpenTime(),GetCurrentBarCloseTime(),GetCurrentBarDuration(), andGetTimeRemainingInBar()can returnnullwhen the interval is not time based or the host lacks enough context.
Depth:
var snapshot = Ctx.MarketData.GetDepth(10);
var refreshed = await Ctx.MarketData.GetDepthAsync(10, cancellationToken);
SubscribeDepth(depth, refreshMilliseconds) starts an explicit background refresh used by the script context. Pair it with UnsubscribeDepth() in the owning cleanup path. A provider can return an empty snapshot; depth support and entitlement are provider-specific.
Drawings
Ctx.Drawing.FixedText(...) and HudText(...) create tagged, script-owned chart text. Manage it with:
Exists(tag).Remove(tag).ClearAll()or itsRemoveAll()alias.
Use stable tags when one visual should update in place. Avoid creating a new unique tag on every tick. The broader bar-anchored drawing surface is documented in the Drawing API.
Orders
High-level helpers include:
- Market:
BuyMarket,SellMarket,SellShortMarket,BuyToCoverMarket. - Managed entries/exits:
EnterLong,EnterShort,ExitLong,ExitShort. - Managed protection:
SetManagedStopLoss,SetManagedStopLossTicks,SetManagedProfitTarget,SetManagedProfitTargetTicks. - Limit and stop-market helpers for the four order actions.
- Direct protection:
SetStopLossandSetProfitTarget. - Lifecycle:
Cancel(orderId),Change(...),Flatten(...), andCreateOcoGroup(...).
Cancellation scopes matter:
CancelStrategyWorking(...)is limited to working orders owned by the strategy.CancelAccountWorking(...)can affect other working orders on the selected account.CancelAllWorking(...)is obsolete; use the explicit scope.
The optional currentInstrumentOnly narrows by instrument, not by ownership. Prefer strategy-scoped cancellation unless account-wide behavior is the written requirement.
Submission returns an Order object, not a fill guarantee. Observe OnOrderUpdate(Order) and OnExecutionUpdate(Order) in the strategy.
Account and position snapshots
Ctx.Account provides read-only Name, ConnectionName, Balance, Equity, BuyingPower, Realized, Unrealized, TotalPnL, Leverage, Orders, and Positions.
Ctx.Position provides MarketPosition, Quantity, AveragePrice, Unrealized, Leverage, and IsFlat.
These are snapshots at the time of access. They can change asynchronously after submission or a provider update. Do not cache them as an authoritative order state machine.
Logging and runtime
Ctx.Log.Print, Info, Debug, and Error write to platform diagnostics. Keep high-frequency logging disabled in production and never include secrets or complete authenticated payloads.
Ctx.Runtime exposes:
CurrentBarandBarsInProgress.CurrentBars.CalculateandState.IsOptimization.
The inherited members remain available; the runtime group is useful when code is organized around the facade.
Alerts status
Ctx.Alerts is Preview. Its current methods—DiscordSignal, DiscordLiveSignal, and DiscordSignalAsync—target HyperionX's Discord integration. They are not a provider-neutral alert contract. Handle unavailable configuration, throttle repeated signals, and do not put credentials in script source.
Continue with Strategy Patterns, Lifecycle and Calculation, and the Market Data reference.