Position object represents the aggregate of all currently active trades. Access it via Strategy.position inside next().
Position evaluates to False in boolean context when there are no active trades (flat), and True when any trade is open.
Properties
Net position size: the sum of all active trade sizes.
- Positive when net long.
- Negative when net short.
0.0when flat (no open trades).
When
hedging=True is set on Backtest, long and short trades coexist. position.size is their net sum and may not reflect total exposure.Total unrealized profit (positive) or loss (negative) of the current position in cash units. Equivalent to the sum of
trade.pl across all active trades.P&L as a percentage relative to total invested value (sum of
entry_price × abs(size) for each active trade).Returns 0 when there are no open trades.True when the net position is long (i.e. size > 0).True when the net position is short (i.e. size < 0).Methods
Position.close()
portion of the current position by calling Trade.close(portion) on every active trade.
Fraction of each trade to close. Must satisfy
0 < portion <= 1.1.0(default) closes all active trades entirely.0.5closes 50% of each trade.
position.close() closes each individual trade proportionally. If you need finer control — for example, closing only long trades — iterate over self.trades and call trade.close() selectively.Example
The following example usesPosition to guard entries, monitor P&L, and exit on a signal or drawdown threshold: