Skip to main content

Build Your First Indicator

Build a configurable moving average, compile it into the live custom assembly, and add it to a chart.

DifficultyTimeApplies to
BeginnerAbout 10 minutesHyperionX 1.1.10

What you will make

The indicator will:

  • Average the most recent closing prices.
  • Expose Period, Plot color, and Thickness in the property grid.
  • Write its values to a registered Series<double>.
  • Render the series as a plot in its own pane.

Before you start

You need HyperionX desktop and at least one chart with historical data. You do not need a broker connection to compile the indicator.

Code Lab stores custom sources under:

%USERPROFILE%\Documents\HyperionX\Bin\Custom
One assembly, one build

Code Lab compiles every .cs file under the custom folder into one assembly. An error in any custom script can block this indicator from building.

1. Create the script

  1. In HyperionX, open Tools → Code Lab.
  2. Select Indicator as the script type.
  3. Select the Plot indicator template.
  4. Select New.
  5. Replace the generated source with the code below.
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using System.Xml.Serialization;
using HyperionX.Chart.Classes;
using HyperionX.Core.Attributes;
using HyperionX.Core.DataCalc;
using HyperionX.Core.Enums;
using HyperionX.Custom.Indicators;

namespace HyperionX.Custom.Indicators;

public class MyMovingAverage : Indicator
{
private const string Parameters = "Parameters";
private const string Appearance = "Appearance";

private Plot _plot = null!;

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

[HyperionXProperty]
[Category(Appearance)]
[Display(Name = "Plot color", GroupName = Appearance, Order = 10)]
public Color PlotColor { get; set; }

[HyperionXProperty]
[Category(Appearance)]
[Display(Name = "Thickness", GroupName = Appearance, Order = 11)]
[Range(1, 10)]
public int Thickness { get; set; }

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

public override void OnStateChanged()
{
if (State == State.SetDefaults)
{
Name = "My Moving Average";
Version = "1.0";
Period = 14;
PlotColor = Colors.DeepSkyBlue;
Thickness = 2;

_plot = new Plot
{
Name = "Average",
Color = PlotColor,
Thickness = Thickness
};
AddPanePlot(_plot);
}
else if (State == State.Configured)
{
Average = new Series<double>();
AddSeries(Average);
_plot.Color = PlotColor;
_plot.Thickness = Thickness;
_plot.DataSource = Average;
}
}

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

var sum = 0.0;
for (var barsAgo = 0; barsAgo < Period; barsAgo++)
sum += Close[barsAgo];

Average[0] = sum / Period;
}
}

2. Understand the four required parts

PartWhy it exists
Indicator base class and namespaceLet Code Lab discover the class as an indicator.
State.SetDefaultsDefine identity, editable defaults, and plot appearance.
State.ConfiguredCreate runtime series and connect the plot to its data source.
OnBarUpdate()Calculate one output value for the current bar.

CurrentBar is the number of bars processed, while Close[0] addresses the newest processed bar. The early-bar guard therefore waits until at least Period values exist before the loop reads them.

3. Save and build

  1. Select Save and keep the file name MyMovingAverage.cs.
  2. Select Build.
  3. Confirm the build summary reports zero errors.
  4. Open the chart's indicator selector. If the desktop runtime detects newer source, it performs the runtime build before showing the list.

The build output is written to:

%USERPROFILE%\Documents\HyperionX\Bin\Custom\bin\Debug\HyperionX.Custom.dll

Do not copy generated helper or cache regions from another trading platform. HyperionX generates its own indicator helpers in memory during both the Code Lab build and the desktop runtime build.

File-scoped and block-scoped namespaces are supported by the current generator. Keep the class in HyperionX.Custom.Indicators and derive it directly from Indicator so the generated helper can reference it.

4. Add it to a chart

  1. Open a chart with data.
  2. Open the chart's indicator window.
  3. Find My Moving Average in the custom indicator list.
  4. Add it, set Period to 14, and apply the changes.

Expected result: a blue moving-average line appears in an indicator pane and updates with the chart.

5. Verify the behavior

  • Change Period and confirm the curve changes.
  • Change the plot color and thickness.
  • Scroll and zoom the chart.
  • Change the data interval.
  • Remove and add the indicator again.
  • Check platform logs for runtime errors.

If it does not work

SymptomCheck
Build failsFix the first compiler error, including errors in other custom files, then build again.
Indicator is missingConfirm the class is public, derives directly from Indicator, uses the HyperionX.Custom.Indicators namespace, and both Code Lab and runtime activation succeeded.
Code Lab succeeds but activation failsOpen the HyperionX log and fix the runtime-build diagnostic. Declare your own using directives and avoid editor-only compatibility shims.
Indicator disables itselfCheck the CurrentBar guard, null runtime objects, and series indexes in the log.
Plot is emptyConfirm the series was created, passed to AddSeries(...), assigned to _plot.DataSource, and written in OnBarUpdate().
A copied API is missingReplace external-platform calls with members from the HyperionXScript reference.

Next steps