RC2_IND_MIXED_RETURN
compute()mixes single-value returns with dict returns. Use one or the other.
What it means
The shape of what compute() returns is what decides the shape of the indicator. Return a number and it is single-value: strategies read it as .value and the chart draws one line. Return a dict and it is multi-output: strategies read .upper, .mid, .lower, and the chart draws one series per key.
That decision is made once, at compile time, from all the return statements in the method — because it becomes the C# type the value record is emitted as. A method that returns a number down one branch and a dict down another has no single such type, so it is refused.
Why it happens
Almost always a guard clause that was written before the indicator grew its extra outputs:
class MyBands(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period)
def compute(self, close): self.buffer.add(close) mid = sum(self.buffer) / len(self.buffer) if not self.is_ready: return close # ❌ a bare number on this path return {"upper": mid + 1, "mid": mid, "lower": mid - 1}The early return close was correct when the indicator returned a single average. Once the main path started returning three bands, it stopped being a warmup shortcut and became a second, incompatible shape.
How to fix it
Return the same dict on every path — fill the keys with whatever the early branch would have meant.
class MyBands(Indicator): position = ON_CHART period = Param(20, min=2, max=200) buffer = Series(period)
def compute(self, close): self.buffer.add(close) mid = sum(self.buffer) / len(self.buffer) if not self.is_ready: return {"upper": close, "mid": close, "lower": close} return {"upper": mid + 1, "mid": mid, "lower": mid - 1}If the indicator was only ever meant to produce one number, go the other way and delete the dict — the branch that returns three values is then the one that does not belong.
The one exception that looks like a mix
return {"value": v, "color": c} is not a multi-output return — those two keys are reserved for the coloured single-value shape used by histogram bars. Mixing that dict with a bare number raises this same diagnostic, and the fix is the same: pick one shape.
Related
- Custom Indicators
RC2_IND_INCONSISTENT_OUTPUTS— every path returns a dict, but not the same keys.RC2_IND_RESERVED_OUTPUT_KEY— a multi-output dict usingvalueorcoloras an output name.RC2_IND_COMPUTE—compute()returns nothing at all on some path.