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

RC2_CROSS_MULTIVALUE

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

crossed_above / crossed_below requires single-value decimals on both sides.

What it means

Crossover helpers work between two single-value indicators (or between a single-value indicator and a number). Multi-value indicators like Aroon and MACD expose multiple fields (.up, .down, .histogram, etc.) and don’t have a single “the value” to compare.

Why it happens

class Bad(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
aroon = Aroon(14, on=self.trade)
if aroon.crossed_above(50): # ❌ — aroon has multiple outputs
self.buy(self.trade)

How to fix it

Compare specific fields explicitly. Field-level .crossed_above is on the roadmap; for now, use a direct comparison, plus persistent state when you need the crossing itself:

class AroonFields(Strategy):
trade = Symbol()
sizing = FixedCapital()
def execute(self):
aroon = Aroon(14, on=self.trade)
# Compare fields directly
if aroon.up > 70 and aroon.down < 30 and self.trade.is_flat:
self.buy(self.trade, reason=f"Aroon up={aroon.up:.0f}")

For true crossing detection on a multi-value field, keep the previous bar’s value in persistent state:

class MacdCross(Strategy):
trade = Symbol()
sizing = FixedCapital()
last_line = 0.0
last_signal = 0.0
def execute(self):
m = MACD(12, 26, 9, on=self.trade)
# Detect the MACD line crossing above its signal line
crossed = m.line > m.signal and self.last_line <= self.last_signal
self.last_line = m.line
self.last_signal = m.signal
if crossed and self.trade.is_flat:
self.buy(self.trade)