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:
| Folder | Script Type |
|---|---|
Indicators | Custom indicators. |
Strategies | Custom strategies. |
BarTypes | Custom bar/data series types. |
Optimizers | Optimizer implementations. |
OptimizationFitnesses | Fitness score modules. |
MoneyManagements | Money management modules. |
Commissions | Commission models. |
Addons | Platform extensions. |
Script Categories
| Category | Namespace | Base class |
|---|---|---|
| Indicator | HyperionX.Custom.Indicators | Indicator |
| Strategy | HyperionX.Custom.Strategies | Strategy |
| Bar Type | HyperionX.Custom.BarTypes | Bar type base |
| Optimizer | HyperionX.Custom.Optimizers | Optimizer base |
| Optimization Fitness | HyperionX.Custom.OptimizationFitnesses | Fitness base |
| Money Management | HyperionX.Custom.MoneyManagements | Money management base |
| Commission | HyperionX.Custom.Commissions | Commission base |
| Addon | HyperionX.Custom.Addons | AddonBase |
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.
| State | Purpose |
|---|---|
State.SetDefaults | Set name, version, defaults, parameters, and declare plots. |
State.Configured | Allocate custom series, call AddSeries(...), connect plots, and initialize indicators. |
State.Historical | Historical calculation state. |
State.Playback | Playback/replay state. |
State.RealTime | Real-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:
OpenHighLowCloseVolumeDateTimeInput
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:
Parametersfor calculation settings.Appearancesfor colors, widths, line styles, and display settings.Riskfor strategy risk inputs.Executionfor 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:
- Identify whether it is an indicator, strategy, bar type, optimizer, or addon.
- Put it in the matching HyperionX namespace.
- Replace other-platform lifecycle methods with HyperionX
OnStateChanged()andOnBarUpdate(). - Replace other-platform drawing APIs with HyperionX
DrawAPIs. - Replace order helper methods with
SubmitOrder(...). - Replace unsupported properties with HyperionX-supported properties.
- Compile.
- Fix all diagnostics.
- Load in simulation or on a test chart.
- Watch logs for runtime errors.
Common Compile Problems
| Problem | Typical Cause |
|---|---|
| Script does not appear | Wrong namespace, wrong base class, duplicate class name, or custom assembly failed to build. |
| Generated helper missing | The indicator class failed to compile or is in the wrong namespace. |
Draw.TextFixed not found | Script used another platform's API. Use Draw.FixedText(...) or Draw.HudText(...). |
IsOverlay not found | Script used another platform property. Use HyperionX plot/panel behavior instead. |
| Strategy helper not found | Use SubmitOrder(...) with OrderAction and OrderType. |
| Runtime indicator disabled | Script 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:
- Create or edit the script in Code Lab.
- Build custom scripts.
- Fix compile errors.
- Load the indicator/strategy on a test chart.
- Check logs for runtime errors.
- Validate output visually.
- Run strategy validation/backtesting where applicable.
- Test in simulation or playback.
- Use small size before any live deployment.