# RSI reversion

The entry is true on every bar the RSI is under `buy_below`, and the exit on every bar it is over `exit_above`. The stop sits two average true ranges from the entry, and the target is twice the distance to the stop.

> **Trap.** Every array in `d` is ordered oldest first. The latest closed bar is the last one, not the first.

## rsi_reversion.py

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

FORGE_API = 1


class RsiReversion(fg.Strategy):
    """Buys when the RSI falls under a level and leaves when it recovers."""

    meta = fg.Meta(title="RSI reversion", short="RSIR", tags=["mean reversion"])
    bars = fg.bars.Time("H1")
    direction = "long"

    period = param.Int(14, min=5, max=40, step=1, group="RSI")
    buy_below = param.Int(30, min=10, max=40, step=5, group="RSI")
    exit_above = param.Int(55, min=45, max=70, step=5, group="RSI")

    def compute(self, d) -> fg.Signals:
        rsi = ta.rsi(d.close, self.period)
        return fg.Signals(
            long_entry=rsi < self.buy_below,
            long_exit=rsi > self.exit_above,
            stop=fg.Stop.atr(mult=2.0, length=14),
            target=fg.Target.r(value=2.0),
        )
```
