Volume — Volume
תוכן זה אינו זמין עדיין בשפה שלך.
Trade volume for the bar, drawn as a histogram tinted by candle direction: green when the bar closed at or above its open, red when it closed below.
Volume is the identifier the chart uses; Volume is the label the indicator picker shows. Single value.
Effectively chart-only — read self.trade.volume instead
Volume is the one platform indicator that declares no parameters, and the transpiler requires every indicator construction to carry a first positional argument regardless. Volume(on=self.trade) therefore raises RC2_IND_PERIOD. Volume(1, on=self.trade) does compile — but the 1 is a throwaway the indicator never reads, so writing it is asking the reader to trust a number that means nothing.
Use self.trade.volume: the same value, on every bar, with no indicator to declare. The Volume catalog entry earns its keep on the chart, where it draws the tinted histogram. Everything below describes that.
Signature
Volume(on=<source>) # chart / indicator picker only| Argument | Type | Required | Notes |
|---|---|---|---|
on= |
symbol | No | Source. Defaults to the chart’s symbol. (Volume needs open, close and volume — the whole bar, not a single field.) |
Formula
$$ \text{Volume}_t = \text{volume}_t $$
The value is the raw per-bar volume. The colour is the only computed part:
| Bar | Colour |
|---|---|
close ≥ open |
up colour (theme-resolved) |
close < open |
down colour (theme-resolved) |
Colours are semantic tokens resolved against the viewer’s active theme, not fixed hex — the same series looks right in light and dark mode.
Warmup
None. The indicator declares no rolling buffer, so it is ready on its first bar and every bar carries a real value.
Reading volume from a strategy
Read it straight off the symbol, and put it through an SMA when you need a baseline:
self.trade.volume # this bar's volumeSMA(20, on=self.trade.volume) # 20-bar average volume, as an indicatorExample
Volume as a confirmation filter — no Volume indicator involved:
class VolumeConfirmedBreakout(Strategy): """Require above-average volume to confirm a channel breakout.""" period = Param(20, min=2, max=200) trade = Symbol() sizing = FixedCapital()
def execute(self): avg_vol = SMA(self.period, on=self.trade.volume) upper = DonchianHigh(self.period, on=self.trade) self.stop_loss(2.5)
breakout_level = upper.value_at(1)
if self.trade.close > breakout_level and self.trade.volume > avg_vol.value and self.trade.is_flat: self.buy(self.trade, reason="Breakout on heavy volume")
if self.trade.close < breakout_level and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Lost the channel high")Notes
- In strategy code,
self.trade.volumeis the whole story. It is the same number the histogram draws, available on every bar with nothing to declare. - The colour lives on the chart only, and so does the indicator. To branch on bar direction in code, compare
self.trade.closewithself.trade.open. - Raw volume is not comparable across bars of different session lengths — a half-session bar carries a fraction of a full one. Compare against a moving average of volume (
SMA(20, on=self.trade.volume)), as the example does, rather than against a fixed number. - Volume confirms; it does not lead. Use it as a filter on a signal some other indicator produced.