# Bollinger Mean Reversion

> Bollinger Mean Reversion is a strategy that trades EURUSD on 1-hour bars. It holds at most 1 open trade and closes its trade on an opposite signal.

Source: https://algobarsx.com/docs/ex-11-bollinger-mean-reversion/

```algobarsx
strategy "Bollinger Mean Reversion"
    market: EURUSD
    bars: 1h
    max_open: 1
    opposite: close

input length = 20
input width = 2.0

bands = bollinger(close, length, multiplier: width)

when crosses_below(close, bands.lower) and rsi(close, 14) < 30:
    buy limit: bands.lower, risk: 1%, stop: bands.lower - atr(14), target: bands.middle, expires: 5 bars

when crosses_above(close, bands.upper) and rsi(close, 14) > 70:
    sell limit: bands.upper, risk: 1%, stop: bands.upper + atr(14), target: bands.middle, expires: 5 bars

plot bands.upper, color: gray
plot bands.middle, color: blue
plot bands.lower, color: gray
```
What this script says

Bollinger Mean Reversion is a strategy that trades EURUSD on 1-hour bars. It holds at most 1 open trade and closes its trade on an opposite signal.

You can change 2 inputs: `length` (default 20) and `width` (default 2.0).

It calculates `bands` as the Bollinger Bands (source the close, length `length`, multiplier `width`).

When the close crosses below `bands.lower` and the 14-bar RSI is below 30, it buys with a limit order at `bands.lower`, risking 1% of the balance, with a stop at `bands.lower` minus the 14-bar ATR, with a target at `bands.middle` and expiring after 5 bars.

When the close crosses above `bands.upper` and the 14-bar RSI is above 70, it sells with a limit order at `bands.upper`, risking 1% of the balance, with a stop at `bands.upper` plus the 14-bar ATR, with a target at `bands.middle` and expiring after 5 bars.

On the chart, it plots `bands.upper`, `bands.middle` and `bands.lower`.
