HX102 Indicators
HX102 converts the indicator lesson path into HyperionX. You start with a minimal indicator, then add parameters, plots, output series, drawing, and strategy-readable signals.
This lesson uses the Current HyperionX.Custom.Indicators.Indicator runtime. Start with Build Your First Indicator, and use the Indicator Reference and Drawing API Reference as the member-level sources of truth.
Lesson 1: Minimal Indicator
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;
namespace HyperionX.Custom.Indicators;
public class HXCloseMomentum : Indicator
{
private Plot _plot;
[Browsable(false)]
[XmlIgnore]
public Series<double> Momentum { get; set; }
public override void OnStateChanged()
{
if (State == State.SetDefaults)
{
Name = "HX Close Momentum";
Version = "1.0";
_plot = new Plot(Colors.DeepSkyBlue, "Momentum", 2, PlotLineType.Solid, PlotChartType.Linear);
AddPanePlot(_plot);
}
else if (State == State.Configured)
{
Momentum = new Series<double>();
AddSeries(Momentum);
_plot.DataSource = Momentum;
}
}
public override void OnBarUpdate()
{
if (CurrentBar < 2)
return;
Momentum[0] = Close[0] - Close[1];
}
}
Lesson 2: Parameters
Use [HyperionXProperty] for anything the user should edit.
[HyperionXProperty]
[Range(1, 500)]
[Display(Name = "Period", GroupName = "Parameters", Order = 0)]
public int Period { get; set; }
Set defaults in State.SetDefaults, not in the property declaration.
Lesson 3: Plots And Output Series
The plot controls how data looks. The series holds the data.
_plot = new Plot(Colors.LimeGreen, "Average", 2, PlotLineType.Solid, PlotChartType.Linear);
AddPanePlot(_plot);
Average = new Series<double>();
AddSeries(Average);
_plot.DataSource = Average;
For multi-output indicators, create one series per output: Fast, Slow, Signal, Upper, Lower, etc.
Lesson 4: Bar Coloring And Backgrounds
Use script properties that HyperionX already supports:
if (Close[0] > Open[0])
{
BarBrush = Brushes.LimeGreen;
CandleOutlineBrush = Brushes.White;
}
else
{
BarBrush = Brushes.Red;
CandleOutlineBrush = Brushes.White;
}
Use BackBrushAll sparingly. It affects the chart background and can make dark mode unreadable if colors are too saturated.
Lesson 5: Draw Objects
Use the HyperionX Draw API:
Draw.Arrow(this, ArrowDirection.Up, "buy-" + CurrentBar, 0, Low[0], ArrowConnector.End, Brushes.LimeGreen);
Draw.Text(this, "label-" + CurrentBar, "BUY", 0, Low[0] - TickSize * 3, Brushes.White);
Use unique tags when you want multiple drawings. Reuse the same tag when you want one drawing to update.
Lesson 6: Indicator Signals For Strategies
If a strategy should consume an indicator, expose a clean output series.
[Browsable(false)]
[XmlIgnore]
public Series<double> Signal { get; set; }
Signal[0] = crossedUp ? 1 : crossedDown ? -1 : 0;
Completion check:
- The indicator compiles.
- Parameters appear in the property grid.
- Plots are connected to series in
State.Configured. - Drawing tags do not grow without limit unless that is intentional.
- A strategy can read the output series without guessing from chart colors.
Before rebuilding, remove affected indicator instances or reload their owning chart afterward. An existing object does not switch to the new custom assembly merely because Code Lab reports a successful build. See Build, Test, And Debug.