Selling at the Best Price Considering Historical Data

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.

{
"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])

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

Last updated