Skip to main content

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.

GroupIndicatorStrategyPurpose
Ctx.ChartYesYesVisible range, chart coordinates, panes, and invalidation.
Ctx.MarketDataYesYesInstrument identity, price/depth snapshots, candles, and bar timing.
Ctx.DrawingYesYesScript-owned fixed text and HUD drawings.
Ctx.AlertsPreviewPreviewCurrent Discord signal bridge.
Ctx.OrdersNoYesManaged and direct strategy order actions.
Ctx.AccountRead-onlyRead-onlyAccount values plus order and position snapshots.
Ctx.PositionRead-onlyRead-onlyCurrent strategy-position snapshot.
Ctx.LogYesYesBounded diagnostic output.
Ctx.RuntimeYesYesCurrent 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, and VisibleCount.
  • PriceMin and PriceMax.
  • CandleWidth and CandleGap.
  • Read-only pane names through Panes.
  • GetXByBarIndex(index), GetYByPrice(price), and GetPriceByY(y).
  • Invalidate(), InvalidateVisual(), and InvalidateOverlay().

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, and Multiplier.
  • Last, Bid, Ask, and Spread.
  • IsTimeBasedSeries.

History and time:

  • GetCandles(int seriesIndex = 0) returns a read-only snapshot list, not a live mutable series.
  • GetCurrentBarOpenTime(), GetCurrentBarCloseTime(), GetCurrentBarDuration(), and GetTimeRemainingInBar() can return null when 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 its RemoveAll() 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: SetStopLoss and SetProfitTarget.
  • Lifecycle: Cancel(orderId), Change(...), Flatten(...), and CreateOcoGroup(...).

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:

  • CurrentBar and BarsInProgress.
  • CurrentBars.
  • Calculate and State.
  • 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.