Build Your First Indicator
Build a configurable moving average, compile it into the live custom assembly, and add it to a chart.
| Difficulty | Time | Applies to |
|---|---|---|
| Beginner | About 10 minutes | HyperionX 1.1.10 |
What you will make
The indicator will:
- Average the most recent closing prices.
- Expose
Period,Plot color, andThicknessin 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
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
- In HyperionX, open Tools → Code Lab.
- Select Indicator as the script type.
- Select the Plot indicator template.
- Select New.
- 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
| Part | Why it exists |
|---|---|
Indicator base class and namespace | Let Code Lab discover the class as an indicator. |
State.SetDefaults | Define identity, editable defaults, and plot appearance. |
State.Configured | Create 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
- Select Save and keep the file name
MyMovingAverage.cs. - Select Build.
- Confirm the build summary reports zero errors.
- 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
- Open a chart with data.
- Open the chart's indicator window.
- Find My Moving Average in the custom indicator list.
- Add it, set
Periodto14, 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
Periodand 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
| Symptom | Check |
|---|---|
| Build fails | Fix the first compiler error, including errors in other custom files, then build again. |
| Indicator is missing | Confirm 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 fails | Open the HyperionX log and fix the runtime-build diagnostic. Declare your own using directives and avoid editor-only compatibility shims. |
| Indicator disables itself | Check the CurrentBar guard, null runtime objects, and series indexes in the log. |
| Plot is empty | Confirm the series was created, passed to AddSeries(...), assigned to _plot.DataSource, and written in OnBarUpdate(). |
| A copied API is missing | Replace external-platform calls with members from the HyperionXScript reference. |
Next steps
- Deepen the indicator with Indicator Development.
- Learn reusable composition in Indicator Patterns.
- Understand editable inputs in Parameters and Generated Helpers.
- Add visual annotations with the Drawing API.
- Learn lifecycle and calculation modes in Script Lifecycle and Calculation.
- Build automated logic with Strategy Development.