Placing Orders with a Spread Based on Historical Data
Orders are placed at the best price within a defined spread, ensuring asks are not set below, and bids not set above, historical price levels.
In this example, the following additional data is used:
Ask Price Calculation
The ask price is determined as the maximum of:
The best ask price minus
symbol
().price_precision
.The average high price of 100 fifteen-minute candlesticks (
mean_high_15m
).The minimum ask price (
min_ask_price
). In example it equal tomean_high_15m
. If required, it can be replaced with a specific number or any other value.The midpoint between the average closing price and the average high price of the last two weeks' daily candlesticks.
max
(
orderbook
().ask[0].price-
symbol
().price_precision,(two_weeks_mean_high+two_weeks_mean_close)/2,mean_high_15m,min_ask_price)
Bid Price Calculation
The bid price is determined as the minimum of:
The best bid price plus
symbol
().price_precision
The average low price of 100 fifteen-minute candlesticks (
mean_low_15m
)The maximum bid price (
max_bid_price
). In example it equal tomean_low_15m
. If required, it can be replaced with a specific number or any other value.The midpoint between the average closing price and the average low price of the last two weeks' daily candlesticks.
min
(
orderbook
().bid[0].price+
symbol
().price_precision,(two_weeks_mean_low+two_weeks_mean_close)/2,mean_low_15m,max_bid_price)
Spread and Price Adjustment
If the spread between the calculated price_ask and price_bid is smaller than the parameter spread_min (set to 10 symbol
().price_precision
), orders are adjusted to meet the minimum spread.
Otherwise:
Asks are placed at price_ask with a 0.5% increment (gap_ask
). Bids are placed at price_bid with a 0.5% increment (gap_bid
).
Order Volume Calculation
Order volume is set without increments and equals the equivalent of 6 counter tokens if the order price within the range of the average low and average high prices of two weeks' daily candlesticks.
For orders outside this range, the volume increases as the equivalent of 10 counter tokens multiplied by the order number.
(6/
execute_price
if
execute_price
>two_weeks_mean_low else 10 /
execute_price
*
abs
(
order_pos
)) if
side
=='
buy
' else (6/
execute_price
if
execute_price
<two_weeks_mean_high else 10 /
execute_price
*
abs
(
order_pos
))
Last updated