Skip to main content

Crate pine_broker

Crate pine_broker 

Source
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.
PineFills
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. size is signed — positive is long, negative short — matching strategy.*trades.size.

Enums§

Commission
How a strategy declaration 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.*.
OrderKind
The price condition that decides when an order fills.
Sizing
How an order without an explicit qty is sized, from the strategy declaration’s default_qty_type/default_qty_value.

Traits§

Broker
The simulated broker a strategy trades against.
FillModel
Decides whether order fills against bar, returning the fill price.