Skip to content
Open RaamTrade

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 / else
  • for i in range(...)
  • local assignment, and augmented assignment (+=, -=, *=, /=)
  • self.<state> = ... on a state field declared in the class body
  • self.<series>.add(value), self.<series>[i]
  • return <expr> (or a dict, for a multi-output indicator)
  • sum, len, min, max, abs, round, int, and the math.* 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 change

And 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.period