# RSI crossing a level

The entry fires on the bar where the RSI crosses up through `buy_level`, not on every bar it stays above. The exit fires when it reaches `exit_level`.

> **Trap.** A level that the RSI is already above on the first bar after warm-up is not a cross. Nothing fires until the RSI has been below the level first.

## rsi_cross.py

```python
import forge as fg
from forge import param, ta

FORGE_API = 1


class RsiCross(fg.Strategy):
    bars = fg.bars.Time("H1")
    direction = "long"

    period = param.Int(14, min=2, max=50, group="RSI")
    buy_level = param.Int(30, min=10, max=45, step=5, group="RSI")
    exit_level = param.Int(60, min=50, max=80, step=5, group="RSI")

    def compute(self, d) -> fg.Signals:
        rsi = ta.rsi(d.close, self.period)
        return fg.Signals(
            long_entry=ta.crossover(rsi, self.buy_level),
            long_exit=rsi > self.exit_level,
        )
```
