Trading and Orders

Trade Statistics

Introduction

The TradeBuilder tracks the trades of your algorithm and calculates some statistics. You can adjust how it defines a trade and how it matches offsetting order fills.

Set Trade Builder

To set the TradeBuilder, in the Initialize method, call the SetTradeBuilder method.

SetTradeBuilder(new TradeBuilder(groupingMethod, matchingMethod));
self.set_trade_builder(TradeBuilder(groupingMethod, matchingMethod))

The following table describes the arguments the TradeBuilder constructor accepts:

ArgumentData TypeDescriptionDefault Value
groupingMethodFillGroupingMethodThe method used to group order fills into trades
matchingMethodFillMatchingMethodThe method used to match offsetting order fills

The FillGroupingMethod enumeration has the following members:

The FillMatchingMethod enumeration has the following members:

Default Behavior

The default TradeBuilder uses FillGroupingMethod.FillToFill and FillMatchingMethod.FIFO.

Check Open Positions

To check if you have a position open for a security as defined by the FillGroupingMethod, call the HasOpenPosition method.

var hasOpenPosition = TradeBuilder.HasOpenPosition(_symbol);
has_open_position = self.trade_builder.has_open_position(self.symbol)

Get Closed Trades

To get your closed trades, use the ClosedTrades property.

var trades = TradeBuilder.ClosedTrades;
trades = self.trade_builder.closed_trades

This property returns a list of Trade objects, which have the following attributes:

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: