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

RC2_CLASS_BODY

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

Class body may only contain Param(), Symbol(), a sizing assignment, or plain literal assignments. Found <construct>.

What it means

The class body of a Strategy runs once at class-definition time, not on every bar. It’s used to declare static schema — Params, Symbols, sizing, constants. Anything that requires computation belongs in execute() (or a helper).

Why it happens

You put logic, expressions, or calls in the class body that aren’t Param(), Symbol(), or a sizing model.

class Bad(Strategy):
trade = Symbol()
sizing = FixedCapital()
threshold = 30 + 5 # ❌ — arithmetic in the class body
def execute(self):
if self.trade.is_flat:
self.buy(self.trade)

Control flow (if True:) and calls (log("starting")) in the class body are refused the same way.

How to fix it

Move computed values into execute(). Use plain literals or Param() for the static parts.

class Good(Strategy):
trade = Symbol()
sizing = FixedCapital()
threshold = 35 # ✅ plain literal
overbought = Param(70, min=60, max=85) # ✅ Param
def execute(self):
rsi = RSI(14, on=self.trade)
if rsi.value > self.overbought and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Overbought")