LazyScalp Board
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Aleksandr400

//@version=5
indicator("LazyScalp Board", overlay = true)

avgVolLength = input.int(title="Avg Vol length", defval = 30, minval = 3, maxval=100, step=1)
natrLength = input.int(title="NATR length", defval = 14)
avgType = input.string("EMA", "Avg type", options = ["SMA", "EMA", "RMA", "WMA"])
position = input.string("Right bottom", "Board position", options = ["Right top", "Right bottom", "Center bottom", "Left bottom", "Left top"])
cellWidth = input.int(8, "Cell width", 1, 20, 1)

backColor = input.color(#434651, "Cell Background color")
textColor = input.color(color.white, "Cell Text color")
backColorAlert = input.color(#FBC02D, "Cell Background color alert")
textColorAlert = input.color(color.black, "Cell Text color alert")

showTitles = input.bool(true, "Show titles")
showDayVol = input.bool(true, "Show Day Volume")
showAvgVol = input.bool(true, "Show Avg Volume")
showNatr = input.bool(true, "Show NATR")
showCorr = input.bool(true, "Show Correlation")

corrTicker = input.symbol("BINANCE:BTCUSDT.P", "Correlation symbol")
corrPeriod = input.int(title = "Correlation period", defval = 20, step = 1)

thresholdDayVol = input.int(title = "Day VOL threshold ($)", defval = 100000000, step = 1000000)
thresholdAvgVol = input.int(title = "Avg VOL threshold ($)", defval = 3000000, step = 100000)
thresholdNatr = input.float(title = "NATR threshold", defval = 1, step = 0.1)


// Titles
dv = ""
av = ""
n = ""
c = ""

if showTitles
    dv := "DV "
    av := "AV "
    n := "N "
    c := "C "

// FORMATTER
formater(data) =>
    if str.length(data) > 11
        str.substring(data, 0, 3) + " B"
    else if str.length(data) > 10
        str.substring(data, 0, 2) + " B"
    else if str.length(data) > 9
        str.substring(data, 0, 1) + " B"
    else if str.length(data) > 8
        str.substring(data, 0, 3) + " M"
    else if str.length(data) > 7
        str.substring(data, 0, 2) + " M"
    else if str.length(data) > 6
        str.substring(data, 0, 1) + " M"
    else if str.length(data) > 5
        str.substring(data, 0, 3) + " K"
    else if str.length(data) > 4
        str.substring(data, 0, 2) + " K"
    else if str.length(data) > 3
        str.substring(data, 0, 1) + " K"

// NART
natr = ta.ema(ta.tr(true), natrLength) / close * 100

if avgType == "RMA"
    natr := ta.rma(ta.tr(true), natrLength) / close * 100

if avgType == "SMA"
    natr := ta.sma(ta.tr(true), natrLength) / close * 100

if avgType == "WMA"
    natr := ta.wma(ta.tr(true), natrLength) / close * 100

natrFormated = str.tostring(math.round(natr, 2))

// DAY VOLUME from different timeframe
d1 = request.security(syminfo.tickerid, "60", volume * close)
d2 = request.security(syminfo.tickerid, "60", volume[1] * close[1])
d3 = request.security(syminfo.tickerid, "60", volume[2] * close[2])
d4 = request.security(syminfo.tickerid, "60", volume[3] * close[3])
d5 = request.security(syminfo.tickerid, "60", volume[4] * close[4])
d6 = request.security(syminfo.tickerid, "60", volume[5] * close[5])
d7 = request.security(syminfo.tickerid, "60", volume[6] * close[6])
d8 = request.security(syminfo.tickerid, "60", volume[7] * close[7])
d9 = request.security(syminfo.tickerid, "60", volume[8] * close[8])
d10 = request.security(syminfo.tickerid, "60", volume[9] * close[9])
d11 = request.security(syminfo.tickerid, "60", volume[10] * close[10])
d12 = request.security(syminfo.tickerid, "60", volume[11] * close[11])
d13 = request.security(syminfo.tickerid, "60", volume[12] * close[12])
d14 = request.security(syminfo.tickerid, "60", volume[13] * close[13])
d15 = request.security(syminfo.tickerid, "60", volume[14] * close[14])
d16 = request.security(syminfo.tickerid, "60", volume[15] * close[15])
d17 = request.security(syminfo.tickerid, "60", volume[16] * close[16])
d18 = request.security(syminfo.tickerid, "60", volume[17] * close[17])
d19 = request.security(syminfo.tickerid, "60", volume[18] * close[18])
d20 = request.security(syminfo.tickerid, "60", volume[19] * close[19])
d21 = request.security(syminfo.tickerid, "60", volume[20] * close[20])
d22 = request.security(syminfo.tickerid, "60", volume[21] * close[21])
d23 = request.security(syminfo.tickerid, "60", volume[22] * close[22])
d24 = request.security(syminfo.tickerid, "60", volume[23] * close[23])

dayVolNumber = math.round(d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10 + d11 + d12 + d13 + d14 + d15 + d16 + d17 + d18 + d19 + d20 + d21 + d22 + d23 + d24)
dayVol = str.tostring(dayVolNumber)
dayVol := formater(dayVol)

// AVG VOLUME
avgVolArr = array.new_float(1, volume * close)

for i = 1 to avgVolLength - 1
    array.push(avgVolArr, volume[i] * close[i])

avgVolNumber = math.round(array.avg(avgVolArr))
avgVol = str.tostring(avgVolNumber)
avgVol := formater(avgVol)

// CORRELATION
corrTickerData = request.security(corrTicker, "1", close)
corr = math.round(ta.correlation(corrTickerData, close, corrPeriod), 2)

// Styles
backColorDayVol = backColor
textColorDayVol = textColor
backColorAvgVol = backColor
textColorAvgVol = textColor
backColorNatr = backColor
textColorNatr = textColor

if dayVolNumber >= thresholdDayVol
    backColorDayVol := backColorAlert
    textColorDayVol := textColorAlert

if avgVolNumber >= thresholdAvgVol
    backColorAvgVol := backColorAlert
    textColorAvgVol := textColorAlert

if natr >= thresholdNatr
    backColorNatr := backColorAlert
    textColorNatr := textColorAlert

var tablePosition = position.top_right
if position == "Right top"
    tablePosition := position.top_right
if position == "Right bottom"
    tablePosition := position.bottom_right
if position == "Center bottom"
    tablePosition := position.bottom_center
if position == "Left bottom"
    tablePosition := position.bottom_left
if position == "Left top"
    tablePosition := position.top_left

// Render table
var infoTable = table.new(tablePosition, 1, 4, border_width = 1)

if barstate.islast
    if showDayVol
        table.cell(infoTable, 0, 0, text = dv + str.tostring(dayVol), width = cellWidth, bgcolor = backColorDayVol, text_color = textColorDayVol)
    if showAvgVol
        table.cell(infoTable, 0, 1, text = av + str.tostring(avgVol), width = cellWidth, bgcolor = backColorAvgVol, text_color = textColorAvgVol)
    if showNatr
        table.cell(infoTable, 0, 2, text = n + natrFormated + " %", width = cellWidth, bgcolor = backColorNatr, text_color = textColorNatr)
    if showCorr
        table.cell(infoTable, 0, 3, text = c + " " + str.tostring(corr), width = cellWidth, bgcolor = backColor, text_color = textColor)
    







