RC2_FOR_TARGET
forloop target must be a simple variable name.
What it means
The loop variable has to be one plain name — for i in …, for k in …. RaamCode has no unpacking, so a tuple target has nothing to unpack into: there is no enumerate() to produce index/value pairs, and dict iteration yields keys, not pairs. One name, one value per pass.
Why it happens
Reaching for Python’s for k, v in … over a dict:
class Bad(Strategy): trade = Symbol() sizing = FixedCapital() counts = {"up": 0, "down": 0} total = 0.0
def execute(self): for k, v in self.counts: # ❌ tuple target self.total = self.total + 1.0for i, x in enumerate(self.vals): fails here too — and enumerate is a blocked builtin on top of it.
How to fix it
Iterate the keys and look the value up. It is one extra subscript and it reads the same.
class Good(Strategy): trade = Symbol() sizing = FixedCapital() counts = {"up": 0, "down": 0, "doji": 0} total = 0.0
def execute(self): self.total = 0.0 for k in self.counts: # ✅ one name — the key self.total = self.total + self.counts[k]
if self.total > 100 and self.trade.is_flat: self.buy(self.trade)For a list, the index-and-element pair is range(...) plus a subscript:
class Indexed(Strategy): trade = Symbol() sizing = FixedCapital() recent_highs = [0.0]*5 total = 0.0
def execute(self): self.total = 0.0 for i in range(5): # ✅ the index self.total = self.total + self.recent_highs[i]
if self.total > 0 and self.trade.is_flat: self.buy(self.trade)Related
- For Loops — the three loop shapes, in full.
RC2_FOR_ITER— the target is fine, the thing being iterated isn’t.RC2_ASSIGN_LHS— the same “one name” rule for assignment.