RunState API Reference
This is a complete reference of all public methods on the RunState object, grouped by category.
Price Data – Basic
| Method | Returns | Description |
|---|
Open(dataN) / O(dataN) | Series | Opening prices |
High(dataN) / H(dataN) | Series | High prices |
Low(dataN) / L(dataN) | Series | Low prices |
Close(dataN) / C(dataN) | Series | Closing prices |
Volume(dataN) / V(dataN) | Series | Volume |
HLAvg(dataN) | Series | (High + Low) / 2 |
HLCAvg(dataN) | Series | (High + Low + Close) / 3 |
OHLCAvg(dataN) | Series | (Open + High + Low + Close) / 4 |
OCAvg(dataN) | Series | (Open + Close) / 2 |
All price methods accept an optional lookback ...int parameter to shift the result.
Price Data – Daily/Weekly/Monthly/Session Aggregates
| Method | Returns | Description |
|---|
OpenD(dataN, loc) | Series | Daily opening prices |
HighD(dataN, loc) | Series | Daily highs |
LowD(dataN, loc) | Series | Daily lows |
CloseD(dataN, loc) | Series | Daily closing prices |
VolumeD(dataN, loc) | Series | Daily volume |
OpenW(dataN, loc) | float64 | Weekly open |
HighW(dataN, loc) | float64 | Weekly high |
LowW(dataN, loc) | float64 | Weekly low |
CloseW(dataN, loc) | float64 | Weekly close |
VolumeW(dataN, loc) | float64 | Weekly volume |
OpenM(dataN, loc) | float64 | Monthly open |
HighM(dataN, loc) | float64 | Monthly high |
LowM(dataN, loc) | float64 | Monthly low |
CloseM(dataN, loc) | float64 | Monthly close |
VolumeM(dataN, loc) | float64 | Monthly volume |
SessionOpen(dataN) | float64 | Session opening price |
SessionHigh(dataN) | float64 | Session high |
SessionLow(dataN) | float64 | Session low |
SessionClose(dataN) | float64 | Session closing price |
SessionVolume(dataN) | float64 | Session volume |
Split variants (CloseSplit, HighSplit, etc.) subdivide intraday data by time boundaries.
Order Placement
| Method | Description |
|---|
Buy(args...) | Enter or add to long position |
SellShort(args...) | Enter or add to short position |
ExitLong(args...) | Reduce or exit long position |
ExitShort(args...) | Reduce or exit short position |
Sell(args...) | Reduce or exit long position (alias) |
BuyToCover(args...) | Cover short position (alias) |
CoverShort(args...) | Cover short position (alias) |
SetStopLoss(dollars) | Place stop loss |
SetProfitTarget(dollars) | Place profit target |
SetBreakEven(floor) | Move stop to break-even |
SetDollarTrailing(dollars) | Dollar trailing stop |
SetPercentTrailing(floor, pct) | Percentage trailing stop |
SetExitOnClose() | Exit at session close |
Position State
| Method | Returns | Description |
|---|
MarketPosition(entries...) | int | Current position (+long, -short, 0=flat) |
PositionSize() | int | Default position size |
AverageEntryPrice() | float64 | Weighted average entry price |
BarsSinceEntry() | int | Bars since last entry (-1 if flat) |
DurationSinceEntry() | Duration | Time since last entry |
MinutesSinceEntry() | Duration | Minutes since last entry |
Fills() | []Fill | List of open fills |
LastFillPrice() | float64 | Price of most recent fill |
CanPyramid() | bool | Whether pyramiding is enabled |
SetPyramiding(bool) | | Enable/disable pyramiding |
Profit and Equity
| Method | Returns | Description |
|---|
NetProfit() | float64 | Realised closed-trade profit |
NetProfitPeak() | float64 | Peak of closed net profit |
OpenPositionProfit() | float64 | Unrealised P&L (base currency) |
OpenPositionProfitPoints() | float64 | Unrealised P&L (points) |
EquityPeak() | float64 | Peak equity |
MaxDrawdownValue() | float64 | Maximum drawdown (currency) |
MaxDrawdownPercent() | float64 | Maximum drawdown (percentage) |
Bar Information
| Method | Returns | Description |
|---|
BarNumber(dataN) | int | Current bar number (0-indexed) |
CurrentBar(dataN) | int | Current bar number (alias) |
BarsTotal(dataN) | int | Total bars in series |
BarsToDate(dataN) | int | Bars seen so far |
BarsRemaining(dataN) | int | Bars remaining |
IsFirstBar(dataN) | bool | First bar of series |
IsLastBar(dataN) | bool | Last bar of series |
IsSecondLastBar(dataN) | bool | Second-to-last bar |
MaxBarsBack() | int | Maximum lookback configured |
DataSeriesCount() | int | Number of loaded series |
FirstBar(dataN) | Bar | First bar data |
LastBar(dataN) | Bar | Last bar data |
Session Boundaries
| Method | Returns | Description |
|---|
IsFirstBarOfSession(dataN) | bool | First bar of trading session |
IsLastBarOfSession(dataN) | bool | Last bar of trading session |
IsSessionSecondLastBar(dataN) | bool | Second-to-last bar of session |
IsFirstBarOfDay(dataN, loc) | bool | First bar of calendar day |
IsLastBarOfDay(dataN, loc) | bool | Last bar of calendar day |
IsFirstBarOfWeek(dataN, loc) | bool | First bar of week |
IsLastBarOfWeek(dataN, loc) | bool | Last bar of week |
IsLastBarOfMonth(dataN, loc) | bool | Last bar of month |
IsLastBarOfYear(dataN, loc) | bool | Last bar of year |
SessionBarNumber(dataN) | int | Bar number within session |
MinutesSinceSessionStart() | Duration | Minutes since session start |
Time
| Method | Returns | Description |
|---|
Time(dataN) | time.Time | Bar ending time |
TimeAtExchange(dataN) | time.Time | Time in exchange timezone |
TimeNextBar(dataN) | time.Time | Time of next bar |
TimePrevBar(dataN) | time.Time | Time of previous bar |
Epoch(dataN) | int64 | Unix epoch timestamp |
Weekday(dataN, loc) | Weekday | Day of the week |
YearDay(dataN, loc) | int | Day of year (1-366) |
WeekISO(dataN, loc) | (int, int) | ISO week and year |
YMD(dataN, loc) | string | Year-Month-Day string |
DMY(dataN, loc) | string | Day-Month-Year string |
DateRange(dataN) | (Time, Time) | Series start and end times |
Duration and Counting
| Method | Returns | Description |
|---|
CountBarsInDuration(dataN, dur) | int | Bars within a time duration |
CountBarsSince(dataN, when) | int | Bars since a timestamp |
CountBarsTotal(dataN) | int | Total bars in series |
CountBarsToNowDay(dataN, loc) | int | Bars to end of day |
CountBarsToNowWeek(dataN, loc) | int | Bars to end of week |
CountBarsToNowMonth(dataN, loc) | int | Bars to end of month |
CountBarsToNowSession(dataN) | int | Bars to end of session |
Symbol Information
| Method | Returns | Description |
|---|
SymbolName(dataN) | string | Symbol name |
SymbolDescription(dataN) | string | Human-readable description |
SymbolCurrency(dataN) | string | Currency code |
SymbolCountry(dataN) | string | Country code |
SymbolExchange(dataN) | string | Exchange code |
SymbolTimeZone(dataN) | *Location | Symbol timezone |
SymbolPointValue(dataN) | float64 | Point value |
SymbolMinMove(dataN) | float64 | Minimum price movement |
SymbolTickSize(dataN) | float64 | Tick size |
SymbolAssetType(dataN) | string | Asset type |
SymbolCategory(dataN) | string | Category |
SymbolMarginInitial(dataN) | float64 | Initial margin |
SymbolMarginMaintenance(dataN) | float64 | Maintenance margin |
SymbolCount() | int | Number of loaded symbols |
BarInterval(dataN) | int | Bar interval in minutes |
BarIntervalText(dataN) | string | Readable interval (e.g., “Daily”) |
Capital and Currency
| Method | Returns | Description |
|---|
InitialCapital() | float64 | Starting capital |
InitialCapitalCurrency() | string | Capital currency code |
BaseCurrency() | string | Base currency for P&L |
CrossRate(from, to) | float64 | Exchange rate between currencies |
SymbolToBaseRate(dataN) | float64 | Symbol-to-base currency rate |
Bar Pattern Detection
| Method | Returns | Description |
|---|
IsInsideBar(dataN) | bool | Current bar is inside previous bar |
IsOutsideBar(dataN) | bool | Current bar engulfs previous bar |
Portfolio Accessors
| Method | Returns | Description |
|---|
HasPortfolio() | bool | Running under Trade Director |
PortfolioEquity() | float64 | Current portfolio equity |
PortfolioNetProfit() | float64 | Total realised profit |
PortfolioNetProfitPeak() | float64 | Peak realised profit |
PortfolioOpenPositionProfit() | float64 | Total unrealised P&L |
PortfolioOpenPositionCount() | int | Count of open positions |
PortfolioOpenPositions() | []*Order | All open positions |
PortfolioFills() | []*Order | All fills |
PortfolioTotalExposure() | float64 | Total notional exposure |
PortfolioExposureByAssetClass() | map | Exposure by asset class |
PortfolioExposureByCategory() | map | Exposure by category |
PortfolioPositionCountByAssetClass() | map | Counts by asset class |
PortfolioPositionCountByCategory() | map | Counts by category |
PortfolioStrategyIDs() | []string | All strategy IDs |
PortfolioStrategyInfo(id) | *StrategyInfo | Info for a strategy |
Dynamic Loading
| Method | Returns | Description |
|---|
LoadSeries(opts) | (int, error) | Load additional data series (Begin() only) |
SeriesOptions(dataN) | SeriesOptions | Load options used for a series |