Expand description
A simulated broker: the emulator a Pine strategy trades against.
There is no order book and no exchange. A backtest replays historical bars
and asks, bar by bar, what would have happened — so filling an order is a
modelling assumption (FillModel), not a match against a real resting
order. Everything else — position, average price, commission, the trade log,
equity — is plain accounting that does not depend on the venue, so there is
one BarBroker, not one per exchange.
Placing real orders is deliberately out of scope: in Pine that happens outside the strategy, when an alert is delivered to an external system. This crate only simulates.
Structs§
- BarBroker
- Exit
- A stop-loss / take-profit bracket attached to a position, from
strategy.exit. Its legs are evaluated each bar once the position exists; whichever fills first closes it and cancels the other (one-cancels-all). - Order
- A submitted order, before it fills. Replaces any pending order with the same
id, as Pine’s order commands do. - Pine
Fills - TradingView’s default assumptions:
- Position
- The current net position: signed size and the average price it was opened at.
- Trade
- One trade: an entry, and its exit once closed.
sizeis signed — positive is long, negative short — matchingstrategy.*trades.size.
Enums§
- Commission
- How a
strategydeclaration charges commission. - Direction
- Long or short.
- OcaType
- What happens to the other orders in a One-Cancels-All group when one of them
fills, from
strategy.oca.*. - Order
Kind - The price condition that decides when an order fills.
- Sizing
- How an order without an explicit
qtyis sized, from thestrategydeclaration’sdefault_qty_type/default_qty_value.