Builtins: level 1 quotes
The best bid and offer. On a live chart the newest bar carries the current quote, and every bar that formed while a script reading l1.* was on the chart keeps the last quote it saw, how many quotes arrived during it and the spread they showed. Bars from before that carry none and answer l1.available() false. In replay there is no recorded quote at all, so l1.supported() is false there. For a book with a recorded history, use the depth builtins.
| Signature | Returns |
|---|---|
| l1.supported() -> bool | Whether quotes are wired on this chart |
| l1.available() -> bool | Whether a quote is attached to this bar |
| l1.bid_price() -> float | Best bid, nan without a quote |
| l1.ask_price() -> float | Best offer |
| l1.bid_size() -> float | Size at the best bid |
| l1.ask_size() -> float | Size at the best offer |
| l1.bid_exchange() -> string | Bid exchange code, empty when not stated |
| l1.ask_exchange() -> string | Offer exchange code, empty when not stated |
| l1.quote_count() -> int | How many quotes arrived while this bar formed, 0 without any |
| l1.spread_avg() -> float | Average offer minus bid over those quotes, nan without any |
| l1.spread_max() -> float | Widest spread seen during the bar |
| l1.spread_min() -> float | Narrowest spread seen during the bar |
- On past bars the quote is the one standing when the bar closed. On the newest bar it is the quote right now.
- The chart keeps up to the newest 20,000 bars of quotes per instrument and timeframe. Reopening the chart starts the history again.
- The spread statistics count only quotes with both a bid and an offer above zero.
let quoted: bool = l1.supported() && l1.available()
let spread: float = l1.ask_price() - l1.bid_price()
let jumpy: bool = quoted && l1.spread_max() > l1.spread_min() * 3
plot.marker(jumpy, high, "#F59E0B", "x", "above", 8, 2)
let book_lean: float = (l1.bid_size() - l1.ask_size()) / (l1.bid_size() + l1.ask_size())
if quoted {
plot.label(str.concat("SPREAD ", format.fixed(spread, 2), " BID ", format.compact(l1.bid_size()), " x ASK ", format.compact(l1.ask_size())), "#E5E7EB")
}