> 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/selling-at-the-best-price-considering-historical-data.md).

# Selling at the best price considering historical data

Grid recipe: sell at the best price, but not below the midpoint of last month's average daily close and high.

Learn how to configure Origami Tech grid strategies that optimize sell orders based on historical data analysis and performance tracking.

Grid 2: Selling at the Best Price Considering Historical Data

Selling at the best price, not lower than `min_ask_price` and the midpoint between the average closing price and the average highs of daily candles over the past month.

```json
{
"gap": "0.01",
"candles_1d": "candles('d1', 'base-counter',count=30)",
"execute_price": "max(orderbook().ask[0].price-symbol().price_precision,(month_mean_high+month_mean_close)/2,min_ask_price)*(1+gap*(order_pos-1))",
"min_ask_price": "max(month_mean_close,orderbook().bid[0].price+symbol().price_precision*2)",
"execute_volume": "10/execute_price if execute_price<month_mean_high else (10/execute_price+abs(order_pos)*10/execute_price)",
"month_mean_high": "mean([price.high for price in candles_1d])",
"buy_orders_count": "0",
"month_mean_close": "mean([price.close for price in candles_1d])",
"sell_orders_count": "5 if balance('counter').total < 5000 else 0"
}
```

The grid places sell orders at the best price. An additional parameter, **`gap`**, is used to calculate the order prices. In this example, it is set to **1%**.

`1+gap*(order_pos-1)`

As additional parameters, daily candles for the last 30 days are retrieved.

`candles('d1', 'base-counter',count=30)`

Based on these, additional parameters are calculated: the average closing price and the average daily high price over the last 30 days.

`mean([price.close` `for price in candles_1d])`

`mean([price.high` `for price in candles_1d])`

<figure><img src="https://3075831504-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh6BkURa7HNU017yGuhBt%2Fuploads%2FRmTEbUbYzJJyt5zxvqGi%2Fimage.png?alt=media&#x26;token=f433a94c-0758-4a1b-8a53-458378f7b828" alt=""><figcaption></figcaption></figure>

Next, the order price is calculated as the maximum of the current best price, the minimum ask price set in the `min_ask_price` parameter, and the midpoint between the average closing price and the average high price over the last 30 days.

In this example, `min_ask_price` is set to the maximum of the average closing price and the current best bid price, plus 2 price\_precision.

Orders will be placed until the balance of the **Counter** token exceeds 5000.\
If needed, this can be replaced with a combined balance across multiple exchanges.

`group_balance('counter').current.total`

`5 if` `group_balance('counter').current.total < 5000 else 0`

or based on the token balance `base` `balance('base').total`

`5 if` `balance('base').total > 5000 else 0`
