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
- Broker
Config - The account settings a
strategy()declaration configures its broker with, so a customBrokerFactorycan honour the script’s parameters rather than inventing its own. - Default
Broker Factory - The built-in factory: a
BarBrokerwithPineFills, reproducing Pine’s default fill model. - 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.
- Entry
Filter - Which entry directions
strategy.risk.allow_entry_inpermits. - 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.
- Risk
Rule - A risk-management rule set by a
strategy.risk.*call, applied to the broker. - Risk
Type - How a risk threshold’s value is measured (
strategy.risk.max_drawdownandstrategy.risk.max_intraday_loss). - Sizing
- How an order without an explicit
qtyis sized, from thestrategydeclaration’sdefault_qty_type/default_qty_value.
Traits§
- Broker
- The simulated broker a strategy trades against.
- Broker
Factory - Builds the
Brokerastrategytrades against. The default,DefaultBrokerFactory, produces the built-in bar-fill broker; a host can supply its own to simulate against a different engine while still honouring the script’sBrokerConfig. - Fill
Model - Decides whether
orderfills againstbar, returning the fill price.