RC2_EXIT_NO_QTY
Exit verbs (
sell,buy_to_cover) require an explicit quantity.
What it means
Exit verbs aren’t auto-sized by the strategy’s sizing model — they need to know exactly how much to exit. The transpiler refuses an exit call without a quantity, even when the intent looks obvious.
Why it happens
class Bad(Strategy): trade = Symbol() sizing = FixedCapital()
def execute(self): if self.trade.is_long: self.sell(self.trade, reason="Exit") # ❌ — no quantity givenYou probably meant “sell everything I hold.” The transpiler doesn’t infer that — it makes you say it.
How to fix it
Pass the quantity as the second positional argument. self.trade.position is “everything I hold”:
class Good(Strategy): trade = Symbol() sizing = FixedCapital()
def execute(self): sma = SMA(20, on=self.trade)
if self.trade.is_flat: self.buy(self.trade)
if self.trade.is_long: self.sell(self.trade, self.trade.position, stop=sma.value) # ✅ full exitOther common forms — all of them positional:
class ExitForms(Strategy): trade = Symbol() sizing = FixedCapital()
def execute(self): if self.trade.is_long: self.sell(self.trade, self.trade.position / 2) # exit half if self.trade.is_short: self.buy_to_cover(self.trade, self.trade.position) # close a shortWhy no qty= kwarg?
Quantity for exits is always positional: the second argument of sell / buy_to_cover is how much of the position to close, and it is never a keyword. qty= and percent= on an exit verb are RC2_EXIT_NO_KWARGS.
Note the order the two checks run in: the missing-positional test comes first, so self.sell(self.trade, qty=100) — a kwarg with no positional at all — reports this code, not RC2_EXIT_NO_KWARGS. You see RC2_EXIT_NO_KWARGS only when the positional quantity is present and a forbidden kwarg is passed alongside it.