Skip to content
Open RaamTrade

RC2_FOR_RANGE

range() in a for loop takes 1 argument (stop) or 2 arguments (start, stop).

What it means

RaamCode’s range(...) has two forms and no third: range(stop) counts 0 … stop-1, and range(start, stop) counts start … stop-1. The upper bound is exclusive in both, as in Python. The three-argument range(start, stop, step) is refused — every loop steps by one, which keeps the loop bound obvious to read and to the graph analyzer that compiles it.

Why it happens

Reaching for a step:

class Bad(Strategy):
trade = Symbol()
sizing = FixedCapital()
recent_highs = [0.0]*10
total = 0.0
def execute(self):
for i in range(0, 10, 2): # ❌ three-argument range
self.total = self.total + self.recent_highs[i]

A backwards range (range(10, 0, -1)) is the same refusal — count forwards and index from the other end instead.

How to fix it

Use range(stop) or range(start, stop), and put the step into the index arithmetic:

class Good(Strategy):
trade = Symbol()
sizing = FixedCapital()
recent_highs = [0.0]*10
total = 0.0
def execute(self):
self.total = 0.0
for i in range(5): # ✅ 0..4, indexed 0,2,4,6,8
self.total = self.total + self.recent_highs[i*2]
for i in range(2, 10): # ✅ start, stop
self.total = self.total + self.recent_highs[i]
if self.total > 0 and self.trade.is_flat:
self.buy(self.trade)

To walk a buffer backwards, index from the far end: self.recent_highs[9-i] inside for i in range(10).

  • For Loops — every supported loop shape.
  • RC2_FOR_ITER — the iterable isn’t range(...) or a state collection at all.
  • RC2_FOR_TARGET — the loop variable isn’t a simple name.