> For the complete documentation index, see [llms.txt](https://docs.origami.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.origami.tech/grids/recipes/buying-and-selling-when-the-15-minute-rsi-exits-a-defined-range.md).

# Buy and sell when 15-minute RSI exits a range

Grid recipe: buy when the 15-minute RSI drops below 30 and sell when it rises above 70.

Explore an Origami Tech grid example using RSI-based triggers to automate buy and sell orders when indicators exit defined thresholds.

Execute buy and sell orders when the 15-minute RSI moves outside the specified range of values.

```json
{
  "max_bid": "mean([candle.close for candle in candles_m15])",
  "min_ask": "mean([candle.close for candle in candles_m15])",
  "rsi_m15": "rsi(candles('m15', 'base-counter'), period=14, column='close')[0]",
  "candles_m15": "candles('m15', 'base-counter')",
  "execute_price": "min(orderbook().ask[0].price,max_bid) if side == 'buy' else max(orderbook().bid[0].price,min_ask)",
  "execute_volume": "10 / ticker()",
  "buy_orders_count": "1 if rsi_m15 < 30 else 0",
  "sell_orders_count": "1 if rsi_m15 > 70 else 0",
  "sleep_after_seconds": "300"
}
```

Buy Orders: Triggered when the RSI falls below 30, executed at the first ask price.

Sell Orders: Triggered when the RSI rises above 70, executed at the first bid price.

In this example, 15-minute candlestick data is used to calculate the average closing price

`mean([candle.close` `for candle in candles_m15])`

and the RSI

`rsi(candles('m15', 'base-counter'), period=14, column='close')[0]`

Sell Orders:

If the RSI exceeds 70, a sell order is placed every 300 seconds (as specified by `"sleep_after_seconds": "300"`) at the best bid price, provided it is not lower than the average closing price of the last 100 fifteen-minute candlesticks.

`"sell_orders_count": "1 if rsi_m15 > 70 else 0"`

Buy Orders:

If the RSI falls below 30, a buy order is placed every 300 seconds at the best ask price, provided it is not higher than the average closing price of the last 100 fifteen-minute candlesticks.

`"buy_orders_count": "1 if rsi_m15 < 30 else 0"`
