crazynou
Pine Script Rookie
Pine Script Rookie
Posts: 4
Joined: October 3rd, 2023

Syntax error at input '['

//@version=5
indicator(title='Binance Order Book Volume Ratio', overlay=true)
// Define input options
lookback_percent = input.float(1, title='Lookback %', minval=0.1, maxval=10.0, step=0.1)
// Define volume ratio thresholds for buy and sell signals
buy_volume_ratio_threshold = input.float(1.5, title='Buy Volume Ratio Threshold', minval=0.1, maxval=10.0, step=0.1)
sell_volume_ratio_threshold = input.float(1.5, title='Sell Volume Ratio Threshold', minval=0.1, maxval=10.0, step=0.1)
// Get current ticker symbol and exchange name
symbol = syminfo.tickerid
exchange = syminfo.exchange
// Calculate price range for order book data
last_price = close
price_range = last_price * lookback_percent / 100
// Function to fetch order book data
get_order_book_data() =>
api_key = 'your_api_key_here' // Replace with your API key
api_secret = 'your_api_secret_here' // Replace with your API secret
depth = 5 // fetch order book depth for top 5 bids and asks
limit = 1000 // fetch up to 1000 entries for each bid and ask
url = 'https://api.binance.com/api/v3/depth?symbol=' + symbol + '&limit=' + limit + '&depth=' + depth
headers = ['X-MBX-APIKEY': api_key]
response = http.request('GET', url, headers=headers, timeout=5000)
response
// Get order book data
order_book_response = get_order_book_data()
order_book_data = request.security("BINANCE:BTCUSDTPERP", "T", order_book_response)
// Calculate volume ratios for buy and sell signals
buy_volume = 0.0
sell_volume = 0.0
for bid in order_book_data.bids
if bid[1] >= last_price - price_range and bid[1] <= last_price + price_range
buy_volume := buy_volume + bid[0]
for ask in order_book_data.asks
if ask[1] >= last_price - price_range and ask[1] <= last_price + price_range
sell_volume := sell_volume + ask[0]
buy_volume_ratio = buy_volume / sell_volume
sell_volume_ratio = sell_volume / buy_volume
// Plot volume ratio lines
plot(buy_volume_ratio, color=color.green, title='Buy Volume Ratio')
plot(sell_volume_ratio, color=color.red, title='Sell Volume Ratio')
// Plot buy and sell signals
buy_signal = buy_volume_ratio > buy_volume_ratio_threshold
sell_signal = sell_volume_ratio > sell_volume_ratio_threshold
plotshape(series=buy_signal, style=shape.arrowup, location=location.belowbar, color=color.green, text='Buy', size=size.small)
plotshape(series=sell_signal, style=shape.arrowdown, location=location.abovebar, color=color.red, text='Sell', size=size.small)

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Syntax error at input '['

I would suggest the error is in this line

headers = ['X-MBX-APIKEY': api_key]

You may need to get in contact with the script owner to understand what this does and how to fix this.

Also remove [0] from lines such as buy_volume := buy_volume + bid[0] which should be buy_volume := buy_volume + bid

Return to “Pine Script Q&A”