RC2_IND_SERIES
תוכן זה אינו זמין עדיין בשפה שלך.
Series
<name>capacity must be a singleParamreference, optionally offset by an integer literal — e.g.Series(period)orSeries(period + 1).
What it means
A Series is the rolling buffer compute() writes into. Its capacity is not free-form: it must name a declared Param, optionally plus or minus an integer.
That is a deliberate coupling, not a syntax quirk. The capacity is what the platform uses to compute the indicator’s warmup — how many bars to prefill before the first real value. Tying it to a Param means that when the optimizer sweeps period from 5 to 200, the buffer and the warmup move with it. A hard-coded capacity would not, and the indicator would quietly return an average of the wrong number of bars at every setting except the one you wrote.
Why it happens
A literal capacity — the shape everyone tries first:
class MySMA(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(20) # ❌ must reference the Param, not repeat it
def compute(self, close): self.buffer.add(close) return sum(self.buffer) / len(self.buffer)Series(1) and Series(2) are refused for the same reason — “I only need the last bar or two” is still a literal. Declare a Param for it, even a pinned one: lookback = Param(2, min=2, max=2).
Wrong number of arguments — Series(), or a start/stop pair:
class MySMA(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period, 2) # ❌ exactly one argument
def compute(self, close): self.buffer.add(close) return sum(self.buffer) / len(self.buffer)How to fix it
Reference the Param.
class MySMA(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period)
def compute(self, close): self.buffer.add(close) return sum(self.buffer) / len(self.buffer)An integer offset is allowed, and is what a difference-style indicator needs — spanning N periods takes N+1 buffered values:
class Change(Indicator): position = OFF_CHART period = Param(10, min=1, max=200) buffer = Series(period + 1)
def compute(self, close): self.buffer.add(close) if not self.is_ready: return 0 return self.buffer[0] - self.buffer[self.period]self.is_ready is true once every buffer is full, so indexing up to self.period is safe below it.
Related
- Custom Indicators
Param()- Warmup
RC2_IND_SERIES_CAPACITY— the capacity is a name, but noParamby that name is declared.RC2_IND_BODY— the assignment is not aSeries()(orParam(), child indicator, or literal) at all.