RunState API Reference

RunState API Reference

This is a complete reference of all public methods on the RunState object, grouped by category.

Price Data – Basic

MethodReturnsDescription
Open(dataN) / O(dataN)SeriesOpening prices
High(dataN) / H(dataN)SeriesHigh prices
Low(dataN) / L(dataN)SeriesLow prices
Close(dataN) / C(dataN)SeriesClosing prices
Volume(dataN) / V(dataN)SeriesVolume
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

MethodReturnsDescription
OpenD(dataN, loc)SeriesDaily opening prices
HighD(dataN, loc)SeriesDaily highs
LowD(dataN, loc)SeriesDaily lows
CloseD(dataN, loc)SeriesDaily closing prices
VolumeD(dataN, loc)SeriesDaily volume
OpenW(dataN, loc)float64Weekly open
HighW(dataN, loc)float64Weekly high
LowW(dataN, loc)float64Weekly low
CloseW(dataN, loc)float64Weekly close
VolumeW(dataN, loc)float64Weekly volume
OpenM(dataN, loc)float64Monthly open
HighM(dataN, loc)float64Monthly high
LowM(dataN, loc)float64Monthly low
CloseM(dataN, loc)float64Monthly close
VolumeM(dataN, loc)float64Monthly volume
SessionOpen(dataN)float64Session opening price
SessionHigh(dataN)float64Session high
SessionLow(dataN)float64Session low
SessionClose(dataN)float64Session closing price
SessionVolume(dataN)float64Session volume

Split variants (CloseSplit, HighSplit, etc.) subdivide intraday data by time boundaries.

Order Placement

MethodDescription
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

MethodReturnsDescription
MarketPosition(entries...)intCurrent position (+long, -short, 0=flat)
PositionSize()intDefault position size
AverageEntryPrice()float64Weighted average entry price
BarsSinceEntry()intBars since last entry (-1 if flat)
DurationSinceEntry()DurationTime since last entry
MinutesSinceEntry()DurationMinutes since last entry
Fills()[]FillList of open fills
LastFillPrice()float64Price of most recent fill
CanPyramid()boolWhether pyramiding is enabled
SetPyramiding(bool)Enable/disable pyramiding

Profit and Equity

MethodReturnsDescription
NetProfit()float64Realised closed-trade profit
NetProfitPeak()float64Peak of closed net profit
OpenPositionProfit()float64Unrealised P&L (base currency)
OpenPositionProfitPoints()float64Unrealised P&L (points)
EquityPeak()float64Peak equity
MaxDrawdownValue()float64Maximum drawdown (currency)
MaxDrawdownPercent()float64Maximum drawdown (percentage)

Bar Information

MethodReturnsDescription
BarNumber(dataN)intCurrent bar number (0-indexed)
CurrentBar(dataN)intCurrent bar number (alias)
BarsTotal(dataN)intTotal bars in series
BarsToDate(dataN)intBars seen so far
BarsRemaining(dataN)intBars remaining
IsFirstBar(dataN)boolFirst bar of series
IsLastBar(dataN)boolLast bar of series
IsSecondLastBar(dataN)boolSecond-to-last bar
MaxBarsBack()intMaximum lookback configured
DataSeriesCount()intNumber of loaded series
FirstBar(dataN)BarFirst bar data
LastBar(dataN)BarLast bar data

Session Boundaries

MethodReturnsDescription
IsFirstBarOfSession(dataN)boolFirst bar of trading session
IsLastBarOfSession(dataN)boolLast bar of trading session
IsSessionSecondLastBar(dataN)boolSecond-to-last bar of session
IsFirstBarOfDay(dataN, loc)boolFirst bar of calendar day
IsLastBarOfDay(dataN, loc)boolLast bar of calendar day
IsFirstBarOfWeek(dataN, loc)boolFirst bar of week
IsLastBarOfWeek(dataN, loc)boolLast bar of week
IsLastBarOfMonth(dataN, loc)boolLast bar of month
IsLastBarOfYear(dataN, loc)boolLast bar of year
SessionBarNumber(dataN)intBar number within session
MinutesSinceSessionStart()DurationMinutes since session start

Time

MethodReturnsDescription
Time(dataN)time.TimeBar ending time
TimeAtExchange(dataN)time.TimeTime in exchange timezone
TimeNextBar(dataN)time.TimeTime of next bar
TimePrevBar(dataN)time.TimeTime of previous bar
Epoch(dataN)int64Unix epoch timestamp
Weekday(dataN, loc)WeekdayDay of the week
YearDay(dataN, loc)intDay of year (1-366)
WeekISO(dataN, loc)(int, int)ISO week and year
YMD(dataN, loc)stringYear-Month-Day string
DMY(dataN, loc)stringDay-Month-Year string
DateRange(dataN)(Time, Time)Series start and end times

Duration and Counting

MethodReturnsDescription
CountBarsInDuration(dataN, dur)intBars within a time duration
CountBarsSince(dataN, when)intBars since a timestamp
CountBarsTotal(dataN)intTotal bars in series
CountBarsToNowDay(dataN, loc)intBars to end of day
CountBarsToNowWeek(dataN, loc)intBars to end of week
CountBarsToNowMonth(dataN, loc)intBars to end of month
CountBarsToNowSession(dataN)intBars to end of session

Symbol Information

MethodReturnsDescription
SymbolName(dataN)stringSymbol name
SymbolDescription(dataN)stringHuman-readable description
SymbolCurrency(dataN)stringCurrency code
SymbolCountry(dataN)stringCountry code
SymbolExchange(dataN)stringExchange code
SymbolTimeZone(dataN)*LocationSymbol timezone
SymbolPointValue(dataN)float64Point value
SymbolMinMove(dataN)float64Minimum price movement
SymbolTickSize(dataN)float64Tick size
SymbolAssetType(dataN)stringAsset type
SymbolCategory(dataN)stringCategory
SymbolMarginInitial(dataN)float64Initial margin
SymbolMarginMaintenance(dataN)float64Maintenance margin
SymbolCount()intNumber of loaded symbols
BarInterval(dataN)intBar interval in minutes
BarIntervalText(dataN)stringReadable interval (e.g., “Daily”)

Capital and Currency

MethodReturnsDescription
InitialCapital()float64Starting capital
InitialCapitalCurrency()stringCapital currency code
BaseCurrency()stringBase currency for P&L
CrossRate(from, to)float64Exchange rate between currencies
SymbolToBaseRate(dataN)float64Symbol-to-base currency rate

Bar Pattern Detection

MethodReturnsDescription
IsInsideBar(dataN)boolCurrent bar is inside previous bar
IsOutsideBar(dataN)boolCurrent bar engulfs previous bar

Portfolio Accessors

MethodReturnsDescription
HasPortfolio()boolRunning under Trade Director
PortfolioEquity()float64Current portfolio equity
PortfolioNetProfit()float64Total realised profit
PortfolioNetProfitPeak()float64Peak realised profit
PortfolioOpenPositionProfit()float64Total unrealised P&L
PortfolioOpenPositionCount()intCount of open positions
PortfolioOpenPositions()[]*OrderAll open positions
PortfolioFills()[]*OrderAll fills
PortfolioTotalExposure()float64Total notional exposure
PortfolioExposureByAssetClass()mapExposure by asset class
PortfolioExposureByCategory()mapExposure by category
PortfolioPositionCountByAssetClass()mapCounts by asset class
PortfolioPositionCountByCategory()mapCounts by category
PortfolioStrategyIDs()[]stringAll strategy IDs
PortfolioStrategyInfo(id)*StrategyInfoInfo for a strategy

Dynamic Loading

MethodReturnsDescription
LoadSeries(opts)(int, error)Load additional data series (Begin() only)
SeriesOptions(dataN)SeriesOptionsLoad options used for a series