1

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

https://www.binance.com/en/support/faq/76bd4effa3c4456c971a1c6835762742

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)

Moving average will be the day range you've selected for the grid.

BBM will be as per the standard deviation as stated in the article https://www.binance.com/en/support/faq/76bd4effa3c4456c971a1c6835762742

nop
  • 4,711
  • 6
  • 32
  • 93
  • 1
    your pine implementation looks correct to me Maybe Binance uses different calculations for the stdev or atr functions? What I mean is, pine use the ta.rma to calculate the ATR, maybe Binance uses something else? – Dave Oct 04 '22 at 06:28
  • @Daveatt, they are probably using different parameters multiplier for the Bollinger bands and their source might be different – nop Oct 04 '22 at 06:32

1 Answers1

1

ta.bb already calculates sma and stdev.

Here you can see in detail: https://www.tradingview.com/pine-script-reference/v5/#fun_ta{dot}bb

On the other hand, you are using "request.security" in the wrong way because it repaints https://www.tradingview.com/pine-script-docs/en/v5/concepts/Repainting.html#repainting-request-security-calls

Try this:

//@version=5
indicator("Grid Bot - Auto parameters", overlay = true)

src = close
length = 30
mult = 2
resolution = 'D'

// Bollinger bands
[middle, upper, lower] = ta.bb(src, length, mult)

middleHTF = request.security(syminfo.tickerid, resolution, middle[1], lookahead = barmerge.lookahead_on)
upperHTF  = request.security(syminfo.tickerid, resolution, upper[1],  lookahead = barmerge.lookahead_on)
lowerHTF  = request.security(syminfo.tickerid, resolution, lower[1],  lookahead = barmerge.lookahead_on)

plot(upperHTF)
plot(middleHTF)
plot(lowerHTF)
Gu5tavo71
  • 706
  • 1
  • 4
  • 11
  • You are right about the repainting, but the difference is brutal, which means they are using different period – nop Oct 04 '22 at 19:13
  • I talked to the support and they told me the following: > Moving average will be the day range you've selected for the grid. BBM will be as per the standard deviation as stated in the article https://www.binance.com/en/support/faq/76bd4effa3c4456c971a1c6835762742 – nop Oct 04 '22 at 19:15