HX104 Advanced Scripts
HX104 covers advanced HyperionX script topics after the user already understands indicators and basic strategies.
Lesson 1: Tick Updates
OnTickUpdate(ICandle candle, ICandle tick) lets a script react between bar closes. Keep it lightweight.
public override void OnTickUpdate(ICandle candle, ICandle tick)
{
if (State != State.RealTime && State != State.Playback)
return;
if (LastPosition.MarketPosition == MarketPosition.Flat)
return;
double lastPrice = tick.C;
// Update trailing logic, alerts, or live-only state here.
}
Rules:
- Do not create indicators inside
OnTickUpdate(). - Do not run long loops on every tick.
- Keep historical/backtest assumptions separate from live tick behavior.
- Use
OnBarUpdate()for signal creation unless the strategy is intentionally tick-driven.
Lesson 2: Multiple Data Series
Add extra data series in State.Configured.
public override void OnStateChanged()
{
if (State == State.Configured)
{
AddDataSeries(DataSeriesType.Minute, 5);
}
}
Guard every series before reading it.
if (CurrentBars[0] < 50)
return;
if (CurrentBars[1] < 50)
return;
double primaryClose = Closes[0][0];
double higherTimeframeClose = Closes[1][0];
Lesson 3: Scale In And Scale Out
Scale logic is state management first and order placement second.
Track:
- Entry price.
- Total target size.
- Current scale level.
- Last scale price.
- Whether first target has already been hit.
- Full-exit reset.
private int _scaleLevel;
private double _entryPrice;
private double _lastScalePrice;
private bool _firstTargetHit;
private void ResetScaleState()
{
_scaleLevel = 0;
_entryPrice = 0;
_lastScalePrice = 0;
_firstTargetHit = false;
}
Do not scale repeatedly from the same signal. Require a new price condition and a max level guard.
Lesson 4: Strategy Plots
Strategy plots help debug entries, stops, targets, and trailing logic.
Use them to show:
- Entry price.
- Active stop.
- Active target.
- Break-even level.
- Trail stop.
If a value is not active, either leave the series unset for that bar or set it to a neutral value only when that is intentional.
Lesson 5: Rendering
HyperionX advanced rendering uses IChartOverlayRenderer and IChartRenderContext, not OnRender(DrawingContext).
using HyperionX.Chart.Rendering;
public class HXVisibleRangeOverlay : Indicator, IChartOverlayRenderer
{
public ChartRenderPass RenderPass => ChartRenderPass.OverDrawings;
public bool RenderOnPricePanel => true;
public void OnRender(IChartRenderContext context)
{
int from = context.VisibleFromIndex;
int to = context.VisibleToIndex;
for (int barIndex = from; barIndex <= to; barIndex++)
{
double x = context.GetXByBarIndex(barIndex);
context.DrawLine(
new ChartPoint(x, 0),
new ChartPoint(x, context.Height),
new ChartStroke(ChartPaint.FromColor("#333333"), 1));
}
}
}
Rendering rules:
- Use visible range indexes.
- Clamp all loops.
- Reuse tags and cached resources where possible.
- Use render context methods for coordinate conversion.
- Do not assume WPF-only rendering.
Lesson 6: Custom UI And Chart Interaction
Custom WPF buttons attached directly to a chart are not a beginner HyperionX course pattern.
For HyperionX, teach this order:
- Use built-in chart toolbar/actions.
- Use drawing tools.
- Use
Drawand HUD text. - Use
IChartOverlayRenderer. - Only then build script-owned WPF UI, and only with dispatcher cleanup and theme-aware resources.
Lesson 7: Drawing Cleanup
Advanced indicators should remove only the drawings they own. Use stable tags, keep a list of generated tags when needed, and remove those tags during recalculation or cleanup.
Recommended pattern:
- Prefix every script drawing tag with the script name.
- Keep manual chart drawings separate from indicator drawings.
- Reuse a tag when updating the same visual object.
- Remove old tags when the signal is no longer valid.
- Never clear all chart drawings from an indicator.
This matters because HyperionX supports manual drawings, AI-created drawings, and script drawings on the same chart.
Lesson 8: Image And Overlay Rendering
When a script needs advanced visual output, choose the lowest-risk rendering surface:
| Need | Preferred approach |
|---|---|
| Static text or labels | Draw.FixedText(...), Draw.HudText(...), or tagged Draw calls. |
| Bar-attached signal markers | Tagged drawing calls or an overlay renderer with visible-range bounds. |
| Bitmap-style signals | IChartOverlayRenderer with render-context image support where available. |
| Large visible-range calculations | Precompute in OnBarUpdate(), then render cached results in OnRender(...). |
Rendering must survive scroll, zoom, resize, theme changes, and chart backend differences.
Completion check:
- Tick code does not freeze the chart.
- Multi-series scripts guard
CurrentBarsfor every series. - Scale state resets after a full exit.
- Rendering survives scroll, zoom, resize, and live updates.
- UI work follows the app theme and unsubscribes events when removed.
- Script-created drawings can be removed without touching manual or AI-created drawings.