Framework Reference
WEALTHLAB FRAMEWORK / CLASS REFERENCE

Transaction

API documentation, members, signatures, and C# examples.

Search the framework

Find classes, members, and documentation.

NamespaceWealthLab.Backtest
Parent
Object

The Transaction class represents a trading order or signal generated during a backtest or processed by WealthLab's trading infrastructure. When developing a C# Strategy, methods such as PlaceTrade return a Transaction instance. You can modify selected properties of the Transaction, such as Quantity, Weight, Tag, AutoStopLossPrice, or AutoProfitTargetPrice, to customize the resulting order. A Transaction also contains information about backtest execution, live broker status, fills, signal origin, account information, and the Position that can result from the order.

Broker and Trading Members

27

Account

public string Account

The broker account associated with the Transaction.

AccountDisplay

public string AccountDisplay

Returns the broker account's display name or nickname when available. Otherwise, returns Account.

Broker

public BrokerBase Broker

The Broker associated with the Transaction. If the Transaction belongs to a SignalBlock, the SignalBlock's Broker takes precedence.

BrokerAccount

public BrokerAccount BrokerAccount

Returns the BrokerAccount corresponding to Account. Returns null if no Broker is assigned or if the account cannot be found.

BrokerTag

public object BrokerTag

Provides broker-specific storage that a Broker implementation can associate with the Transaction.

CanCancel

public bool CanCancel

Returns true when the Transaction's current SignalStatus allows it to be canceled.

CanPlace

public bool CanPlace

Returns true when the Transaction's current SignalStatus allows it to be placed.

FillPrice

public double FillPrice

The fill price reported for a live Transaction.

FillQty

public double FillQty

The quantity filled so far.

IsActive

public bool IsActive

Returns true when the current SignalStatus represents an active order.

IsCompleted

public bool IsCompleted

Returns true when SignalStatus is either:

  • Filled
  • PartialFilled

IsDayTrade

public bool IsDayTrade

Indicates that the Transaction has been classified as a day trade. The default value is false.

IsMOO

public bool IsMOO

Indicates that the Broker submitted the Transaction as a Market-on-Open order. The default value is false.

IsOCO

public bool IsOCO

Returns true if the Transaction is part of an OCO pair.

IsPrePostMarket

public bool IsPrePostMarket

Indicates that the order was submitted for pre-market or post-market trading.

MappedSymbol

public string MappedSymbol

Returns the Broker-mapped symbol for the Transaction. If the Broker does not provide a SymbolMapper, this is the same as Symbol.

Market

public MarketDetails Market

Returns the MarketDetails associated with the Transaction. If Bars is available, its Market is returned. For Transactions without Bars, Market can be assigned directly. If no Market has been supplied, US Stocks is used by default.

Messages

public List<string> Messages

Contains status, error, Portfolio Sync, and other informational messages associated with the Transaction.

MessageString

public string MessageString

Returns the most recent item in Messages. Returns an empty string when no messages are available.

NeedsGTC

public bool NeedsGTC

Returns true when WealthLab should submit the Transaction as Good-Til-Canceled based on the Strategy scale or Trading Preferences.

OcoPair

public Transaction OcoPair

References the other Transaction in an OCO, or One-Cancels-Other, pair. Returns null when the Transaction is not part of an OCO pair.

PartialFill

public void PartialFill(double qty, double price)

Records a partial fill. If previous partial fills exist, WealthLab updates FillQty and recalculates FillPrice as the quantity-weighted average fill price.

SignalStatus

public SignalStatus SignalStatus

Returns the current trading status of the Transaction. WealthLab manages this property as the signal moves through states such as Staged, Placed, Filled, PartialFilled, Canceled, or Error.

Symbol

public string Symbol

The symbol associated with the Transaction. If Symbol has not been explicitly assigned and Bars is available, WealthLab derives it from Bars.Symbol.

Timestamp

public DateTime Timestamp

The timestamp associated with the Transaction. The default value is DateTime.Now.

TransactionToCancel

public Transaction TransactionToCancel

For Broker implementations that support native order replacement, identifies the existing Transaction that should be canceled before this Transaction is submitted.

UseMooOrderIfPossible

public bool UseMooOrderIfPossible

Requests that the Broker submit the Transaction as a Market-on-Open order when supported. The default value is false.

Constructors

1

Transaction

public Transaction()
public Transaction(
TransactionType transType,
OrderType orderType,
double price,
BarHistory bars)
public Transaction(
TransactionType transType,
OrderType orderType,
double price,
BarHistory bars,
int signalIdx)
public Transaction(Transaction t)

Creates a new Transaction. The overload accepting another Transaction creates a copy containing the principal properties of the supplied Transaction. Normally, Strategy code does not construct Transaction instances directly. Instead, a Transaction is returned from methods such as PlaceTrade.

Display and Formatting Members

17

Description

public string Description

Returns a descriptive representation of the Transaction containing its TransactionType, Quantity, OrderType, and applicable price.

ExecutionDateDisplay

public string ExecutionDateDisplay

Returns ExecutionDate formatted for display. If the time portion is midnight, only the date is displayed.

ExecutionPriceDisplay

public string ExecutionPriceDisplay

Returns ExecutionPrice formatted using PriceFormatCode for order types that use a price.

FillPriceDisplay

public string FillPriceDisplay

Returns FillPrice formatted according to the Transaction's price formatting rules.

FillQtyDisplay

public string FillQtyDisplay

Returns FillQty formatted according to the Transaction's quantity formatting rules. Returns an empty string when FillQty is zero.

LastClose

public double LastClose

Returns the last closing value in Bars. Returns Double.NaN when Bars is unavailable.

LastCloseDisplay

public string LastCloseDisplay

Returns LastClose formatted according to PriceFormatCode. Returns an empty string if LastClose is Double.NaN.

LiveOrderDescription

public string LiveOrderDescription

Returns a descriptive string containing the Transaction description and current SignalStatus. For error Transactions, the latest message is included. For filled or partially filled Transactions, the fill price is included.

OrderPriceDecimals

public int OrderPriceDecimals

Returns the number of decimal places WealthLab should use when displaying the order price. The value is derived from the Broker, Market, or Bars where possible, and defaults to 2.

PriceFormatCode

public string PriceFormatCode

Gets or sets the numeric formatting code used for prices. If not explicitly assigned, WealthLab derives a format such as "N2" from OrderPriceDecimals.

QuantityDisplay

public string QuantityDisplay

Returns the Transaction quantity formatted for display. For entry Transactions using next-bar position sizing, this can display BasisAmount as a dollar value instead of a share or contract quantity.

QuantityDisplaySimple

public string QuantityDisplaySimple

Returns Quantity formatted using QuantityFormatCode.

QuantityFormatCode

public string QuantityFormatCode

Gets or sets the numeric formatting code used for quantities. If not explicitly assigned, WealthLab derives the required precision from the Broker and the Quantity itself.

SecurityName

public string SecurityName

Returns the security name from Bars enclosed in parentheses. Returns an empty string when no security name is available.

TimestampString

public string TimestampString

Returns Timestamp formatted as a short date/time string.

ToString

public override string ToString()

Returns a descriptive string containing the Transaction's Symbol and Description.

Order Members

7

OrderPrice

public double OrderPrice

The requested order price. This property is relevant to order types that use a price, such as Limit, Stop, and StopLimit orders. The default value is 0.

OrderPriceAdjusted

public double OrderPriceAdjusted

Returns OrderPrice rounded according to the associated Broker's supported price precision. If no Broker is assigned, returns OrderPrice unchanged.

OrderPriceDisplay

public string OrderPriceDisplay

Returns the order price formatted for display. For StopLimit orders whose stop and limit prices differ, the returned text includes both prices.

OrderType

public OrderType OrderType

Specifies the Transaction's order type. Depending on the context, supported values include Market, Limit, Stop, StopLimit, MarketClose, LimitClose, FixedPrice, and other WealthLab order types.

PriceIsBeyondOrderPrice

public bool PriceIsBeyondOrderPrice(double price)

Returns true if price is beyond the Transaction's Limit, Stop, or StopLimit order price in the direction that would cause the order to be executable. Returns false for order types that are not Limit or Stop based.

StopLimitLimitPrice

public double StopLimitLimitPrice

Specifies the limit portion of a StopLimit order. If no separate limit price is assigned, this property returns OrderPrice, which represents the stop price.

StopLimitLimitPriceAdjusted

public double StopLimitLimitPriceAdjusted

Returns StopLimitLimitPrice rounded according to the associated Broker's supported price precision.

Other Public Members

10

AddPortfolioSyncMessage

public void AddPortfolioSyncMessage(string msg)

Adds msg to the Transaction's Messages collection and assigns it to PortfolioSyncMessage.

AddTradingThresholdMessage

public void AddTradingThresholdMessage(string msg)

Adds msg to the Transaction's Messages collection and assigns it to TradingThresholdMessage.

AssignSignalStatus

public void AssignSignalStatus(SignalStatus ss)

Assigns the Transaction's SignalStatus without firing the normal SignalStatusChanged event. This is primarily intended for framework and extension code.

EntrySignalDate

public DateTime EntrySignalDate

Contains the entry signal date associated with the Position being acted upon. If it has not been explicitly assigned and a Position is associated internally, WealthLab derives it from the Position's EntryDate.

MetaStrategyComponent

public MetaStrategyComponent MetaStrategyComponent

The MetaStrategy component responsible for the Transaction, if applicable.

MetaStrategyName

public string MetaStrategyName

Returns a descriptive identifier for the associated MetaStrategy component. Returns an empty string when the Transaction is not associated with a MetaStrategy component.

PortfolioSyncMessage

public string PortfolioSyncMessage

Contains a message describing an adjustment made by Portfolio Sync.

Resubmit

public void Resubmit()

Resets the Transaction's internal status to Staged so that it can be resubmitted.

TradingThresholdMessage

public string TradingThresholdMessage

Contains a message describing why Trading Threshold processing prevented or modified an order.

TransactionID

public int TransactionID

A unique Transaction identifier generated by WealthLab. The ID can subsequently be transferred to Positions created from the Transaction.

Persistence

3

Clone

public Transaction Clone()

Creates a lightweight copy of the Transaction using the same fields persisted by Persist. This is not equivalent to the Transaction(Transaction t) copy constructor, which copies considerably more Transaction state.

Parse

public static Transaction Parse(string s)

Creates a Transaction from a string previously produced by Persist.

Persist

public string Persist()

Serializes a subset of the Transaction's properties into a string. The persisted information includes:

  • Symbol
  • TransactionType
  • Quantity
  • OrderType
  • OrderPrice
  • Weight
  • ExecutionDate
  • Broker name
  • Account
  • IsDayTrade

Quantity Processing

6

ApplyRoundLots

public void ApplyRoundLots(BacktestSettings bts)

Applies the Round Lots settings in bts to the Transaction quantity. When enabled and applicable, quantities above 10 are rounded to standard 10- or 100-unit lots.

AssignedQuantity

public double AssignedQuantity

Gets or assigns Quantity without marking the Transaction as manually sized. This property is primarily useful to WealthLab framework and extension code that needs to change Quantity while preserving the distinction between automatic and manual sizing. Negative values are converted to zero.

ManualQuantity

public bool ManualQuantity

Indicates that Transaction.Quantity was explicitly assigned rather than calculated automatically.

NextBarPosSizeMode

public bool NextBarPosSizeMode

Indicates that the Transaction was generated using next-bar position sizing. The default value is false.

QuantityAdjusted

public double QuantityAdjusted

Returns Quantity rounded to the number of quantity decimals supported by the associated Broker. If no Broker is assigned, returns Quantity unchanged.

TruncateQuantity

public void TruncateQuantity(int precision)

Truncates Quantity to the specified number of decimal places.

Strategy and Backtest Members

32

AssignAutoProfitTargetPrice

public void AssignAutoProfitTargetPrice(double price)

Assigns an AutoProfitTargetPrice while applying WealthLab's pruning logic when more than one candidate target price is assigned. This method is primarily used by Building Block processing.

AssignAutoStopLossPrice

public void AssignAutoStopLossPrice(double price)

Assigns an AutoStopLossPrice while applying WealthLab's pruning logic when more than one candidate stop price is assigned. This method is primarily used by Building Block processing.

AutoProfitTargetPrice

public double AutoProfitTargetPrice

Assigns a same-bar profit target price to an entry Transaction. When the entry fills, WealthLab can attempt to exit the resulting Position at this limit price on the same bar. This applies both to backtesting and live trading. For realistic backtesting, same-bar exits are most reliable with Market entries. Limit and Stop entries can introduce uncertainty because the intrabar sequence of prices may not be known. The assigned price is adjusted to the security's tick size when Futures Mode is applicable.

AutoStopLossPrice

public double AutoStopLossPrice

Assigns a same-bar stop-loss price to an entry Transaction. When the entry fills, WealthLab can attempt to exit the resulting Position at this stop price on the same bar. This applies both to backtesting and live trading. The assigned price is adjusted to the security's tick size when Futures Mode is applicable.

BacktestCurrentEquity

public double BacktestCurrentEquity

Contains the Backtester's current equity value associated with the Transaction. WealthLab uses this when comparing simulated equity to broker-reported account equity for Portfolio Sync position sizing. The default value is Double.NaN.

Bars

public BarHistory Bars

The BarHistory associated with the Transaction.

BasisAmount

public double BasisAmount

Contains the amount of capital on which the Transaction's quantity calculation was based. This is also used when displaying signals created using next-bar position sizing.

BasisPrice

public double BasisPrice

Contains the price used as the basis for position sizing.

Commission

public double Commission

The commission applied to the Transaction during a backtest. Commission behavior is controlled by the Strategy's Backtest Settings.

CostBasis

public double CostBasis

Returns the approximate capital represented by the Transaction. For Market and MarketClose orders, WealthLab uses the close of the EntryDate bar. For other order types, it uses Quantity � OrderPrice.

EntryDate

public DateTime EntryDate

The signal date of the Transaction. This generally corresponds to the bar on which the trading signal was generated.

ExceededMaxOpenPos

public string ExceededMaxOpenPos

Indicates that an entry Transaction exceeded a maximum-open-position constraint. The value can identify the affected side, such as "Long", "Short", or "Long+Short". Returns null when the Transaction was not rejected for this reason.

ExecutionDate

public DateTime ExecutionDate

The date and time at which the Transaction was executed by the Backtester.

ExecutionPrice

public double ExecutionPrice

The price at which the Backtester executed the Transaction. The default value is Double.NaN.

FromQuotes

public bool FromQuotes

Indicates that the Transaction originated from Quotes processing. The default value is false.

GranularWeightBasis

public DateTime GranularWeightBasis

When Granular Limit/Stop Processing is used, contains the intraday DateTime that determined the Transaction's execution priority. The default value is DateTime.MinValue.

IsEntry

public bool IsEntry

Returns true if the Transaction is an entry:

  • Buy
  • Short

IsExit

public bool IsExit

Returns true if the Transaction is an exit:

  • Sell
  • Cover

MarginOverride

public bool MarginOverride

Set this property to true to allow the Backtester to fill the Transaction even when insufficient simulated capital would normally prevent the fill. The default value is false.

MarketOpenPrice

public double MarketOpenPrice

Returns the opening price of the bar following SignalIndex. Returns Double.NaN if Bars is unavailable, SignalIndex is -1, or there is no following bar.

NSF

public bool NSF

Indicates that the Transaction was flagged as Non-Sufficient Funds by the Backtester.

PositionTag

public int PositionTag

An internal identifier used to associate Transactions with specific Positions or Building Block entries. Strategy developers should normally use Tag instead for custom data.

PositionType

public PositionType PositionType

Returns the PositionType represented by the Transaction. Buy and Sell Transactions correspond to PositionType.Long. Short and Cover Transactions correspond to PositionType.Short.

Quantity

public double Quantity

Gets or assigns the Transaction quantity. For entry Transactions, explicitly assigning Quantity in Strategy code overrides normal Position Sizing. For exit Transactions, assigning a Quantity smaller than the Position quantity can be used to generate a partial exit. Assigning this property also marks the Transaction as having a manually assigned quantity. Negative values are converted to zero.

SetPositionMetric

public void SetPositionMetric(string metric, double value)

Assigns a custom Position Metric to the Transaction. If the Transaction creates a Position, the metric is transferred to that Position and can be used by Performance Visualizers such as Position Metrics.

SignalIndex

public int SignalIndex

The bar index at which the Transaction signal was generated.

SignalName

public string SignalName

An optional descriptive name associated with the signal. For an entry Transaction, this value is transferred to the resulting Position's EntrySignalName.

SignalStrategy

public Strategy SignalStrategy

Returns the Strategy responsible for the signal. For a normal Strategy Transaction this is Strategy. For a MetaStrategy Transaction, this returns the Strategy belonging to the associated MetaStrategy component.

Strategy

public Strategy Strategy

The Strategy that generated the Transaction.

Tag

public object Tag

Provides a general-purpose property for associating custom data with the Transaction. When an entry Transaction creates a Position, the Transaction's Tag is transferred to the Position's Tag property.

TransactionType

public TransactionType TransactionType

Specifies the direction of the Transaction. Possible values include:

  • TransactionType.Buy
  • TransactionType.Sell
  • TransactionType.Short
  • TransactionType.Cover

Weight

public double Weight

Specifies the Transaction's priority when more candidate Transactions exist than available simulated capital permits. Transactions are sorted from higher Weight to lower Weight. Assign a larger Weight to give a Transaction greater fill priority.

Need help with this API?

Ask the community or explore custom development services.