Skip to content

Guide: Analysis

Advanced

You do not need this page for basic usage. Start with Quick Start if you are new to Hexital.

Hexital's analysis module provides Pine Script–style helpers: crossovers, rising/falling checks, highest/lowest over a window, and more. Full catalogue: analysis catalogue.

Analysis functions accept three kinds of data source:

Source When to use
list[Candle] You already have candles with readings attached
Indicator One indicator's candle stream
Hexital Strategy with named indicators — pass indicator names as strings

Basic usage

from hexital import EMA, WMA, Hexital
from hexital.analysis import cross, rising

strategy = Hexital("Demo", candles, [EMA(period=3), WMA(name="WMA", period=8)])
strategy.calculate()

rising(strategy, "EMA_3", length=8)       # True if EMA rose over last 8 bars
cross(strategy, "EMA_3", "WMA")           # True if EMA crossed WMA recently

With a single indicator:

ema = EMA(candles=candles, period=10)
ema.calculate()

rising(ema, "EMA_10", length=5)

With raw candles (readings must already be on the candles):

from hexital.analysis import above

above(candles, "EMA_10", "SMA_20")

Candle streams for comparisons

When comparing two series on a Hexital strategy, movement functions need to know which candle stream each name lives on.

Same stream — both indicators on one manager (e.g. EMA vs SMA on 1-minute data):

from hexital.analysis import above

above(strategy, "EMA_10", "SMA_20")   # one stream, both names

Different timeframes — pass both names; Hexital resolves streams via candle_pair() and aligns bars by timestamp:

strategy = Hexital("MTF", candles, [
    EMA(name="EMA"),
    EMA(name="EMA_T5", timeframe="T5"),
])
strategy.calculate()

above(strategy, "EMA", "EMA_T5")

Indicator vs OHLCV — compare an indicator to high, low, close, etc. on the indicator's stream:

above(strategy, "EMA_10", "high")

You can also resolve streams explicitly:

stream = strategy.candles_for("EMA_10")
pair = strategy.candle_pair("EMA", "EMA_T5")   # (ema_candles, ema_t5_candles)

Movement functions that take two indicator names (above, below, cross, crossover, crossunder, etc.) use this resolution automatically when the first argument is a Hexital instance.

Single-series functions (rising, bars_since, highest, etc.) take one indicator name and use candles_for() when given a Hexital instance.


Patterns and Amorph

Pattern functions live in hexital.analysis.patterns. They operate on candle sequences directly.

For one-off logic that should run on every append, use Amorph — a top-level indicator that wraps a callable. See Custom indicators.


Further reading