DePeg Player
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Market-Masters

//@version=5
indicator("Depeg Player", overlay=true)

dl = input.float(0.995, "Depeg Level", step=0.01)
showlast = input(true, "Show Only Most Recent Label?")
depeg = low <= dl

s1 = input.symbol("MEXC:BUSDUSDT.P", "Symbol 1")
s2 = input.symbol("BYBIT:BUSDUSDT.P", "Symbol 2")
s3 = input.symbol("OKX:USDCUSDT.P", "Symbol 3")
s4 = input.symbol("BINANCE:USDCUSDT.P", "Symbol 4")
s5 = input.symbol("BYBIT:USDCUSDT.P", "Symbol 5")
s6 = input.symbol("BITGET:USDCUSDT.P", "Symbol 6")
s7 = input.symbol("WOONETWORK:USDCUSDT.P", "Symbol 5")
s8 = input.symbol("MEXC:USDCUSDT.P", "Symbol 6")
s11 = request.security(s1, timeframe.period, depeg)
s22 = request.security(s2, timeframe.period, depeg)
s33 = request.security(s3, timeframe.period, depeg)
s44 = request.security(s4, timeframe.period, depeg)
s55 = request.security(s5, timeframe.period, depeg)
s66 = request.security(s6, timeframe.period, depeg)
s77 = request.security(s7, timeframe.period, depeg)
s88 = request.security(s8, timeframe.period, depeg)

plot(dl, "Depeg Line", color=color.yellow, style=plot.style_line)


if s11
    lbl = label.new(bar_index, low, "Depeg\n" + syminfo.ticker(s1) + "\n" + syminfo.prefix(s1), style=label.style_label_up, color=color.green, size=size.small, textcolor=color.white)
    alert("DEPEG ALERT\n" + syminfo.ticker(s1) + "\n" + syminfo.prefix(s1), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])

if s22
    lbl = label.new(bar_index, (low*0.98), "Depeg\n" + syminfo.ticker(s2) + "\n" + syminfo.prefix(s2), style=label.style_label_up, color=color.red, size=size.small, textcolor=color.white)
    alert("DEPEG ALERT\n" + syminfo.ticker(s2) + "\n" + syminfo.prefix(s2), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])
if s33
    lbl = label.new(bar_index, (low*0.96), "Depeg\n" + syminfo.ticker(s3) + "\n" + syminfo.prefix(s3), style=label.style_label_up, color=color.orange, size=size.small, textcolor=color.white)
    alert("DEPEG ALERT\n" + syminfo.ticker(s3) + "\n" + syminfo.prefix(s3), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])

if s44
    lbl = label.new(bar_index, (low*0.94), "Depeg\n" + syminfo.ticker(s4) + "\n" + syminfo.prefix(s4), style=label.style_label_up, color=color.purple, size=size.small, textcolor=color.white)
    alert("DEPEG ALERT\n" + syminfo.ticker(s4) + "\n" + syminfo.prefix(s4), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])

if s55
    lbl = label.new(bar_index, (low*0.92), "Depeg\n" + syminfo.ticker(s5) + "\n" + syminfo.prefix(s5), style=label.style_label_up, color=color.blue, size=size.small, textcolor=color.white)
    alert("DEPEG ALERT\n" + syminfo.ticker(s5) + "\n" + syminfo.prefix(s5), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])

if s66
    lbl = label.new(bar_index, (low*0.90), "Depeg\n" + syminfo.ticker(s6) + "\n" + syminfo.prefix(s6), style=label.style_label_up, color=color.yellow, size=size.small, textcolor=color.black)
    alert("DEPEG ALERT\n" + syminfo.ticker(s6) + "\n" + syminfo.prefix(s6), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])
if s77
    lbl = label.new(bar_index, (low*0.88), "Depeg\n" + syminfo.ticker(s7) + "\n" + syminfo.prefix(s7), style=label.style_label_up, color=color.olive, size=size.small, textcolor=color.white)
    alert("DEPEG ALERT\n" + syminfo.ticker(s7) + "\n" + syminfo.prefix(s7), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])

if s88
    lbl = label.new(bar_index, (low*0.86), "Depeg\n" + syminfo.ticker(s8) + "\n" + syminfo.prefix(s8), style=label.style_label_up, color=color.maroon, size=size.small, textcolor=color.white)
    alert("DEPEG ALERT\n" + syminfo.ticker(s8) + "\n" + syminfo.prefix(s8), alert.freq_once_per_bar)
    if showlast
        label.delete(lbl[1])
