I’m trying to figure out how the Binance Grid Trading Bot calculates its auto parameters. I found the following link which tells us the formula.
How are auto parameters calculated?
- Upper Band = MA + BBM * Standard Deviation
- Lower Band = MA - BBM * Standard Deviation
- Grid Number = (grid_upper_limit - grid_lower_limit)/ATR
Average True Range (ATR) for the past pre-defined hours of the selected symbol
I created a small pinescript snippet to test with. However, I’m getting completely different values than what Binance gets.
//@version=5
indicator("Grid Bot - Auto parameters", overlay = true)
src = close
length = 30
mult = 2
resolution = 'D'
// Simple Moving Average
sma = ta.sma(src, length)
smaHTF = request.security(syminfo.tickerid, resolution, sma)
// Bollinger bands
[middle, upper, lower] = ta.bb(src, length, mult)
middleHTF = request.security(syminfo.tickerid, resolution, middle)
upperHTF = request.security(syminfo.tickerid, resolution, upper)
lowerHTF = request.security(syminfo.tickerid, resolution, lower)
// p1 = plot(upperHTF, "Upper", color = #2962FF)
// p2 = plot(lowerHTF, "Lower", color = #2962FF)
// fill(p1, p2, title = "Background", color = color.rgb(33, 150, 243, 95))
// Standard deviation
stdev = ta.stdev(src, length)
stdevHTF = request.security(syminfo.tickerid, resolution, stdev)
//===============================
// Upper price & Lower price
upperPrice = smaHTF + middleHTF * stdevHTF
lowerPrice = smaHTF - middleHTF * stdevHTF
plot(upperPrice)
plot(lowerPrice)
atrHTF = request.security(syminfo.tickerid, resolution, ta.atr(length))
gridNumber = (upperPrice - lowerPrice) / atrHTF
// plot(gridNumber)