Spot line
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Kerbal

//@version=5
indicator("Spot line", overlay = true)
source = input.source(close, "Source")
color kuCoinColor = color.purple
color coinbaseColor = color.orange
color binanceColor = color.blue
int lineWidth = 2
var string spotSymbol = syminfo.ticker
spotSymbol := str.replace_all(spotSymbol, ".PS", "")
spotSymbol := str.replace_all(spotSymbol, ".P", "")

string binanceSpotSymbol = "BINANCE:" + spotSymbol
string coinbaseSpotSymbol = "COINBASE:" + spotSymbol
string kuCoinSpotSymbol = "KUCOIN:" + spotSymbol

binanceSpotClose = request.security(binanceSpotSymbol, timeframe.period, source, ignore_invalid_symbol = true)
plot(binanceSpotClose, "Binance spot", binanceColor, lineWidth, plot.style_line)

coinbaseSpotCloseTemp = request.security(coinbaseSpotSymbol, timeframe.period, source, ignore_invalid_symbol = true)
coinbaseSpotClose = na(binanceSpotClose) ? coinbaseSpotCloseTemp : na
plot(coinbaseSpotClose, "Coinbase spot", coinbaseColor, lineWidth, plot.style_line)

kuCoinSpotCloseTemp = request.security(kuCoinSpotSymbol, timeframe.period, source, ignore_invalid_symbol = true)
kuCoinSpotClose = na(binanceSpotClose)  and na(coinbaseSpotClose) ? kuCoinSpotCloseTemp : na
plot(kuCoinSpotClose, "KuCoin spot", kuCoinColor, lineWidth, plot.style_line)