דלגו לתוכן
פתיחת RaamTrade

RC2_STATE_EMPTY_LIST

תוכן זה אינו זמין עדיין בשפה שלך.

A bare [] literal has no element type to infer.

What it means

A class-body list declared as name = [] carries no element-type information. RaamCode can’t tell whether the list holds ints, decimals, bools, or strings — and the slot has to be typed before the first bar runs.

Why it happens

class Bad(Strategy):
trade = Symbol()
sizing = FixedCapital()
empty = [] # ❌ — what's the element type?
def execute(self):
if self.trade.is_flat:
self.buy(self.trade)

How to fix it

Pin the element type with the [<literal>]*0 idiom — the literal in the brackets fixes the type, *0 gives it zero length.

class Good(Strategy):
trade = Symbol()
sizing = FixedCapital()
no_decimals = [0.0]*0 # ✅ empty list of decimal
no_ints = [0]*0 # ✅ empty list of int
no_flags = [False]*0 # ✅ empty list of bool
no_words = [""]*0 # ✅ empty list of string
def execute(self):
if self.trade.is_flat:
self.buy(self.trade)

Or, when the contents are known up front, write them out:

class Prefilled(Strategy):
trade = Symbol()
sizing = FixedCapital()
nq_highs = [0.0, 0.0, 0.0, 0.0, 0.0] # ✅ five decimals
# equivalently: nq_highs = [0.0]*5
def execute(self):
self.nq_highs[0] = self.trade.high
if self.trade.is_flat:
self.buy(self.trade)

Why we don’t allow bare []

Each list is pinned to a single element type by the literal you declare. An empty literal offers nothing to pin to, and inferring one would mean either a silent default (“always decimal”) or a guess from the first write — both add ambiguity for no benefit. [0.0]*0 is three characters longer and removes it entirely.