RC2_IND_COMPUTE
תוכן זה אינו זמין עדיין בשפה שלך.
Unsupported statement or expression inside
compute().
What it means
compute() is lowered into a per-bar expression tree that the graph engine can evaluate — that engine is what makes optimization and walk-forward fast. The subset it accepts is small and closed:
if/elif/elsefor i in range(...)- local assignment, and augmented assignment (
+=,-=,*=,/=) self.<state> = ...on a state field declared in the class bodyself.<series>.add(value),self.<series>[i]return <expr>(or a dict, for a multi-output indicator)sum,len,min,max,abs,round,int, and themath.*namespace
RC2_IND_COMPUTE is the catch-all for everything outside it. The message names the specific construct.
Why it happens
Writing to a state field that was never declared — the most common by a distance:
class MySMA(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period)
def compute(self, close): self.buffer.add(close) self.previous = close # ❌ 'previous' is not declared return sum(self.buffer) / len(self.buffer)There is no implicit creation. A state field exists because the class body says so, with its initial value — that is what gives the generated state record a slot and a starting number.
Iterating something other than range():
class MySMA(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period)
def compute(self, close): self.buffer.add(close) total = 0 for x in self.buffer: # ❌ loops must iterate over range() total = total + x return total / len(self.buffer)Other shapes that land here: while, try, chained comparisons (0 < x < 1 — write x > 0 and x < 1), subscripting anything but a Series, and calling a function outside the list above.
How to fix it
Declare the state field in the class body with its initial value.
class Change(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period) previous = 0
def compute(self, close): self.buffer.add(close) change = close - self.previous self.previous = close return changeAnd index the buffer through range():
class ManualAverage(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period)
def compute(self, close): self.buffer.add(close) if not self.is_ready: return close total = 0 for i in range(0, self.period): total = total + self.buffer[i] return total / self.periodRelated
- Custom Indicators
- The Python Subset
RC2_IND_COMPUTE_SIG— the body is fine; the parameters are not bar fields.RC2_IND_BODY— the offending line is in the class body, not incompute().RC2_EXEC_STMT— the strategy-side analogue, for an unsupported statement inexecute().