# Buying and Selling When the 15-Minute RSI Exits a Defined Range

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.&#x20;

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

[<mark style="color:blue;">`mean`</mark>](/function/functions/mean.md)<mark style="color:red;">`([candle.`</mark>[<mark style="color:blue;">`close`</mark>](/function/structures/candle.md) <mark style="color:red;">`for candle in candles_m15])`</mark>

and the RSI

[<mark style="color:blue;">`rsi`</mark>](/function/technical-analysis/stochastic-rsi.md)<mark style="color:red;">`(`</mark>[<mark style="color:blue;">`candles`</mark>](/function/functions/candles.md)<mark style="color:red;">`('m15', '`</mark>[<mark style="color:blue;">`base`</mark>](/function/shortcuts/base.md)<mark style="color:red;">`-`</mark>[<mark style="color:blue;">`counter`</mark>](/function/shortcuts/counter.md)<mark style="color:red;">`'), period=14, column='`</mark>[<mark style="color:blue;">`close`</mark>](/function/structures/candle.md)<mark style="color:red;">`')[0]`</mark>

Sell Orders:

If the RSI exceeds 70, a sell order is placed every 300 seconds (as specified by <mark style="color:red;">`"`</mark>[<mark style="color:blue;">`sleep_after_seconds`</mark>](/function/optional-parameters/sleep-after-seconds.md)<mark style="color:red;">`": "300"`</mark>) at the best bid price, provided it is not lower than the average closing price of the last 100 fifteen-minute candlesticks.

<mark style="color:red;">`"`</mark>[<mark style="color:blue;">`sell_orders_count`</mark>](/function/required-parameters/sell-orders-count.md)<mark style="color:red;">`": "1 if rsi_m15 > 70 else 0"`</mark>

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.

<mark style="color:red;">`"`</mark>[<mark style="color:blue;">`buy_orders_count`</mark>](/function/required-parameters/buy-orders-count.md)<mark style="color:red;">`": "1 if rsi_m15 < 30 else 0"`</mark>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.origami.tech/user-guide/grids-examples/buying-and-selling-when-the-15-minute-rsi-exits-a-defined-range.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
