Skip to main content

Code Lab

Code Lab is the HyperionX C# scripting environment. It is where users build custom indicators, strategies, bar types, optimizers, optimization fitness modules, money management modules, commissions, and addons.

Code Lab is a core part of the HyperionX vision. The platform is not only meant to display charts. It is meant to let users build trading logic inside the same environment where they analyze, test, and trade.

What Code Lab Is For

Use Code Lab when you need to:

  • Build a custom indicator.
  • Build an automated strategy.
  • Port an indicator or strategy from another platform into HyperionX.
  • Build an optimizer or fitness module.
  • Add a custom commission model.
  • Add money management logic.
  • Build reusable trading components.
  • Validate script behavior before running it live.

Custom Script Location

Custom scripts are normally stored under:

%USERPROFILE%\Documents\HyperionX\Bin\Custom

Typical subfolders:

FolderScript Type
IndicatorsCustom indicators.
StrategiesCustom strategies.
BarTypesCustom bar/data series types.
OptimizersOptimizer implementations.
OptimizationFitnessesFitness score modules.
MoneyManagementsMoney management modules.
CommissionsCommission models.
AddonsPlatform extensions.

Script Categories

CategoryNamespaceBase class
IndicatorHyperionX.Custom.IndicatorsIndicator
StrategyHyperionX.Custom.StrategiesStrategy
Bar TypeHyperionX.Custom.BarTypesBar type base
OptimizerHyperionX.Custom.OptimizersOptimizer base
Optimization FitnessHyperionX.Custom.OptimizationFitnessesFitness base
Money ManagementHyperionX.Custom.MoneyManagementsMoney management base
CommissionHyperionX.Custom.CommissionsCommission base
AddonHyperionX.Custom.AddonsAddonBase

The namespace must match the selected script category. If the namespace is wrong, the script may compile but not appear in the expected platform window.

Core Namespaces

Most indicator scripts use:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using System.Xml.Serialization;
using HyperionX.Chart.Classes;
using HyperionX.Chart.Enums;
using HyperionX.Core.Attributes;
using HyperionX.Core.DataCalc;
using HyperionX.Core.Enums;

Strategies usually also use:

using HyperionX.Core.Market;
using HyperionX.Custom.Indicators;

Lifecycle

HyperionX scripts use the OnStateChanged() and OnBarUpdate() lifecycle.

StatePurpose
State.SetDefaultsSet name, version, defaults, parameters, and declare plots.
State.ConfiguredAllocate custom series, call AddSeries(...), connect plots, and initialize indicators.
State.HistoricalHistorical calculation state.
State.PlaybackPlayback/replay state.
State.RealTimeReal-time calculation state.

Use OnBarUpdate() for per-bar logic. Always guard early bars before reading prior values.

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

double momentum = Close[0] - Close[10];
}

Market Data Series

Scripts inherit primary series from ScriptBase:

  • Open
  • High
  • Low
  • Close
  • Volume
  • DateTime
  • Input

Use [0] for the current bar and [1] for one bar ago.

double currentClose = Close[0];
double priorClose = Close[1];
double currentVolume = Volume[0];
System.DateTime barTime = DateTime[0];

Volume is a double series. Do not assume it is an integer-only value.

Parameters

Use [HyperionXProperty] for user-editable script settings.

[HyperionXProperty]
[Display(Name = "Period", GroupName = "Parameters", Order = 1)]
public int Period { get; set; }

Use [Display(...)] to control the property grid label, group, and sort order.

Recommended groups:

  • Parameters for calculation settings.
  • Appearances for colors, widths, line styles, and display settings.
  • Risk for strategy risk inputs.
  • Execution for strategy order behavior.

Plots And Series

Indicators usually create a Plot in State.SetDefaults, allocate a Series<double> in State.Configured, register it with AddSeries(...), then assign the plot data source.

private Plot _plot;

[Browsable(false)]
[XmlIgnore]
public Series<double> Average { get; set; }

public override void OnStateChanged()
{
if (State == State.SetDefaults)
{
_plot = new Plot(Colors.DeepSkyBlue, "Average", 2, PlotLineType.Solid, PlotChartType.Linear);
AddPanePlot(_plot);
}
else if (State == State.Configured)
{
Average = new Series<double>();
AddSeries(Average);
_plot.DataSource = Average;
}
}

Drawing API

Use HyperionX drawing APIs, not drawing APIs from another trading platform.

Correct examples:

Draw.LineHorizontal(this, "last-close", Close[0], Brushes.DeepSkyBlue, 1, DashStyles.Dash);

Draw.FixedText(
this,
"status",
$"Close: {Close[0]:0.####}",
ChartHudAnchor.TopRight,
textBrush: Brushes.White,
backgroundBrush: Brushes.Black,
borderBrush: Brushes.DeepSkyBlue,
fontSize: 12);

Do not use Draw.TextFixed(...), TextPosition, or IsOverlay unless HyperionX explicitly implements them.

Strategy Orders

Strategies should use SubmitOrder(...) with HyperionX order enums.

SubmitOrder(
selectedBarsInProgress: 0,
orderAction: OrderAction.Buy,
orderType: OrderType.Market,
quantity: 1,
limitPrice: 0,
stopPrice: 0,
oco: "",
signalName: "Enter Long");

Do not assume helpers like Buy(...), Sell(...), ShortSell(...), or Cover(...) exist unless they are implemented in HyperionX.

Porting Scripts From Other Platforms

When porting a script:

  1. Identify whether it is an indicator, strategy, bar type, optimizer, or addon.
  2. Put it in the matching HyperionX namespace.
  3. Replace other-platform lifecycle methods with HyperionX OnStateChanged() and OnBarUpdate().
  4. Replace other-platform drawing APIs with HyperionX Draw APIs.
  5. Replace order helper methods with SubmitOrder(...).
  6. Replace unsupported properties with HyperionX-supported properties.
  7. Compile.
  8. Fix all diagnostics.
  9. Load in simulation or on a test chart.
  10. Watch logs for runtime errors.

Common Compile Problems

ProblemTypical Cause
Script does not appearWrong namespace, wrong base class, duplicate class name, or custom assembly failed to build.
Generated helper missingThe indicator class failed to compile or is in the wrong namespace.
Draw.TextFixed not foundScript used another platform's API. Use Draw.FixedText(...) or Draw.HudText(...).
IsOverlay not foundScript used another platform property. Use HyperionX plot/panel behavior instead.
Strategy helper not foundUse SubmitOrder(...) with OrderAction and OrderType.
Runtime indicator disabledScript threw during calculation. Check early-bar guards and null assumptions.

AI Script Rules

When AI writes Code Lab scripts, it must:

  • Write HyperionX scripts, not scripts for another platform.
  • Use local HyperionX APIs.
  • Use the correct namespace and base class.
  • Use [HyperionXProperty] for editable settings.
  • Guard early bars.
  • Register custom series with AddSeries(...).
  • Use supported plot and draw APIs.
  • Compile after editing.
  • Fix all errors before loading the script.

Build And Test Flow

Recommended development flow:

  1. Create or edit the script in Code Lab.
  2. Build custom scripts.
  3. Fix compile errors.
  4. Load the indicator/strategy on a test chart.
  5. Check logs for runtime errors.
  6. Validate output visually.
  7. Run strategy validation/backtesting where applicable.
  8. Test in simulation or playback.
  9. Use small size before any live deployment.