So I'm trying to create a Binance trading grid-like structure:
My attempt:
grid_start = 2.5
grid_gap = 5
total_grids = 10
grids = 0
buy_grid_start = grid_start
buy_grids = []
# CALCULATE GRID
while True:
if grids == total_grids:
break
else:
grids += 1
buy_grid_start += (buy_grid_start * grid_gap / 100)
buy_grids.append(f"{buy_grid_start:0.3f}")
print(buy_grids)
print(f"Total grids: {grids}")
This just gives me 10 grids, each grid 5% above the previous grid (price).
My question is how do I get a grid structure like where you can enter Lower Price and Upper Price, and the number of grids - which will show you the percentage between each grid?
ATTEMPT 2:
import math
grid_start = 1.1
grid_end = 2.2
total_grids = 10
grids = 0
buy_grid_start = grid_start
buy_grid_end = grid_end
ratio = math.pow(buy_grid_start / buy_grid_end, 1 / total_grids) * 100
buy_grids = []
# CALCULATE GRID
while True:
if grids == total_grids:
break
else:
grids += 1
buy_grid_end == buy_grid_start * math.pow(ratio, grids)
buy_grids.append(f"{buy_grid_start:0.3f}")
print(buy_grids)
print(f"Total grids: {grids}")
Output:
['1.100', '1.100', '1.100', '1.100', '1.100', '1.100', '1.100', '1.100', '1.100', '1.100']
Total grids: 10
