Skip to main content

Strategy Development

Strategies are C# classes in the HyperionX.Custom.Strategies namespace. They inherit from Strategy and use HyperionX order, account, position, and indicator APIs.

Minimal Strategy

using System.ComponentModel.DataAnnotations;
using HyperionX.Core.Attributes;
using HyperionX.Core.Enums;
using HyperionX.Core.Market;
using HyperionX.Custom.Indicators;

namespace HyperionX.Custom.Strategies;

public class MyCrossStrategy : Strategy
{
private SMA _fast;
private SMA _slow;

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

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

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

public override void OnStateChanged()
{
if (State == State.SetDefaults)
{
Name = "My Cross Strategy";
Version = "1.0";
FastPeriod = 9;
SlowPeriod = 21;
Quantity = 1;
}
else if (State == State.Configured)
{
_fast = SMA(FastPeriod);
_slow = SMA(SlowPeriod);
}
}

public override void OnBarUpdate()
{
if (CurrentBar < SlowPeriod + 1)
return;

bool crossedUp = _fast[0] > _slow[0] && _fast[1] <= _slow[1];
bool crossedDown = _fast[0] < _slow[0] && _fast[1] >= _slow[1];

if (crossedUp && LastPosition.MarketPosition == MarketPosition.Flat)
{
SubmitOrder(0, OrderAction.Buy, OrderType.Market, Quantity, 0, 0, "", "Enter Long");
}
else if (crossedDown && LastPosition.MarketPosition == MarketPosition.Long)
{
SubmitOrder(0, OrderAction.Sell, OrderType.Market, LastPosition.Quantity, 0, 0, "", "Exit Long");
}
}
}

Order API

Use SubmitOrder(...) for strategy orders.

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

Supported OrderAction values:

  • OrderAction.Buy
  • OrderAction.BuyToCover
  • OrderAction.Sell
  • OrderAction.SellShort

Supported OrderType values:

  • OrderType.Market
  • OrderType.Limit
  • OrderType.MIT
  • OrderType.StopLimit
  • OrderType.StopMarket

HyperionX strategies do not use other-platform helper names like Buy(...), Sell(...), ShortSell(...), or Cover(...) unless those helpers are explicitly added to HyperionX.

Position And Performance State

Strategies can inspect account and performance state through the base class:

  • Account
  • Accounts
  • Positions
  • LastPosition
  • SystemPerformance
  • Realized
  • Unrealized
  • NetProfit
  • ProfitFactor
  • Sharpe
  • MaxDrawDown

Use LastPosition.MarketPosition to decide whether the strategy is flat, long, or short.

Stops And Targets

Stops and targets are regular orders. A common pattern is to submit an entry, then submit exit orders using OrderType.StopMarket or OrderType.Limit.

SubmitOrder(0, OrderAction.Sell, OrderType.StopMarket, LastPosition.Quantity, 0, stopPrice, "", "Long Stop");
SubmitOrder(0, OrderAction.Sell, OrderType.Limit, LastPosition.Quantity, targetPrice, 0, "", "Long Target");

Strategy Safety

  • Start with simulation or playback.
  • Keep order names unique enough to debug.
  • Guard all indicator and series reads with enough bars.
  • Do not store API keys or credentials in strategy parameters.
  • Keep AI-generated strategy scripts constrained to HyperionX APIs and compile them before testing.