Price Data Label
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © amphibiantrading

//@version=5
indicator("Price Data Label", overlay=true,  max_labels_count = 500)

//constants
ISDAILY = timeframe.isdaily
ISWEEKLY = timeframe.isweekly

//inputs
var g1 = 'Daily Moving Averages'
ima1 = input.int(8, "Daily Moving Average 1", inline = "a1", group = g1)
ima2 = input.int(21, "Daily Moving Average 2",inline = "a2", group = g1)
ima3 = input.int(50, "Daily Moving Average 1",inline = "a3", group = g1)
ima4 = input.int(200, "Daily Moving Average 2",inline = "a4", group = g1)
maType1 = input.string("EMA", "", options = ["EMA", "SMA"],inline = "a1", group = g1)
maType2 = input.string("EMA", "", options = ["EMA", "SMA"],inline = "a2", group = g1)
maType3 = input.string("SMA", "", options = ["EMA", "SMA"],inline = "a3", group = g1)
maType4 = input.string("SMA", "", options = ["EMA", "SMA"],inline = "a4", group = g1)

var g2 = 'Weekly Moving Averages'
ima5 = input.int(10, 'Weekly Moving Average 1', inline = '2', group = g2)
ima6 = input.int(40, 'Weekly Moving Average 2', inline = '3', group = g2)
maType5 = input.string("SMA", "", options = ["EMA", "SMA"],inline = "2", group = g2)
maType6 = input.string("SMA", "", options = ["EMA", "SMA"],inline = "3", group = g2)

// create labels
var label dashboard = na
float volSec = na
projVol  = float(volume)

//mas
ma1 = maType1 == "EMA" ? ta.ema(close, ima1) : maType1 == "SMA" ? ta.sma(close, ima1) : na
ma2 = maType2 == "EMA" ? ta.ema(close, ima2) : maType2 == "SMA" ? ta.sma(close, ima2) : na
ma3 = maType3 == "EMA" ? ta.ema(close, ima3) : maType3 == "SMA" ? ta.sma(close, ima3) : na
ma4 = maType4 == "EMA" ? ta.ema(close, ima4) : maType4 == "SMA" ? ta.sma(close, ima4) : na
ma5 = maType5 == "EMA" ? ta.ema(close, ima5) : maType3 == "SMA" ? ta.sma(close, ima5) : na
ma6 = maType6 == "EMA" ? ta.ema(close, ima6) : maType4 == "SMA" ? ta.sma(close, ima6) : na
nasVolAvg = request.security('TVOLQ', 'D', ta.sma(close,50))
spxVolAvg = request.security('TVOL', 'D', ta.sma(close,50))
nasVolAvgWk = request.security('TVOLQ', "W", ta.sma(close,10))
spxVolAvgWk = request.security('TVOL', 'W', ta.sma(close,10))
avgVol = syminfo.ticker == 'IXIC' ? nasVolAvg : syminfo.ticker == 'SPX' ? spxVolAvg : ta.sma(volume,50)
avgVolWk = syminfo.ticker == 'IXIC' ? nasVolAvgWk : syminfo.ticker == 'SPX' ? spxVolAvgWk : ta.sma(volume,10)
nasVol = request.security('TVOLQ', 'D', close)
spxVol = request.security('TVOL', 'D', close)
nasVolWk = request.security('TVOLQ', 'W', close)
spxVolWk = request.security('TVOL', 'W', close)

//projected volume
timePassed = timenow - time
timeLeft = time_close - timenow

if timeLeft > 0 and (syminfo.ticker != 'IXIC' or syminfo.ticker != 'SPX')
    volSec := (volume / timePassed)
    projVol  := (volume + (volSec * timeLeft))

projVolPer = (projVol / avgVol * 100) - 100
projVolPerWk = (projVol / avgVolWk * 100) - 100


//calculations
distMa1 = ((close / ma1) -1 ) *100
distMa2 = ((close / ma2) -1 ) *100
distMa3 = ((close / ma3) -1 ) *100
distMa4 = ((close / ma4) -1 ) *100
distMa5 = ((close / ma5) -1 ) *100
distMa6 = ((close / ma6) -1 ) *100
dollarChng = ta.change(close,1)
perChng = dollarChng / close[1] * 100
closeRange = (close - low) / (high - low) *100
runRate = syminfo.ticker == 'IXIC' ? 100 * (nasVol / nasVolAvg) - 100 : syminfo.ticker == 'SPX' ? 100 * (spxVol / spxVolAvg) - 100 : projVolPer
runRateWk = syminfo.ticker == 'IXIC' ? 100 * (nasVolWk / nasVolAvgWk) - 100 : syminfo.ticker == 'SPX' ? 100 * (spxVolWk / spxVolAvgWk) - 100 : projVolPerWk

//titles
dateTitle = "Date:       "
highTitle = "High:       "
lowTitle = "Low:        "
closeTitle = "Close:      "
perChangeTitle = "% Chg:      "
clsrngTitle = "DCR:         "
clsrngTitleWk = 'WCR:        '
volTitle = "Volume:    "
volPercTitle = 'Vol %:       '  
maTitle1 = maType1 + str.tostring(ima1) +  ":       "
maTitle2 = maType2 + str.tostring(ima2) +  ":     "
maTitle3 = maType3 + str.tostring(ima3) +  ":     "
maTitle4 = maType4 + str.tostring(ima4) +  ":    "
maTitle5 = maType5 + str.tostring(ima5) +  ":     "
maTitle6 = maType6 + str.tostring(ima6) +  ":     "
nl = '\n'

// plot the labels
if ISDAILY and (barstate.isconfirmed or barstate.islast)
    label(dashboard)
    dashboard := label.new(bar_index, high ,color = color.new(color.white,100), tooltip = dateTitle + str.format_time(time, 'MM-dd-yy', 'UTC-7') + nl + 
         highTitle +  str.tostring(high, "##.##") +  nl + 
         lowTitle + str.tostring(low, "##.##") + nl + 
         closeTitle + str.tostring(close, "##.##") + ' (' + str.tostring(dollarChng, format.mintick) + ')' + nl + 
         perChangeTitle + str.tostring(perChng, "##.##") + nl + 
         clsrngTitle + str.tostring(closeRange, "#") + "%" +  nl + 
         volTitle + (syminfo.ticker == 'IXIC' ? str.tostring(nasVol, "#,###,###,###") : 
         syminfo.ticker == 'SPX' ? str.tostring(spxVol, "#,###,###,###") : str.tostring(volume, "#,###,###,###")) + nl +
         volPercTitle + str.tostring(runRate, "#") + '%' +  nl +
         maTitle1 + str.tostring(ma1, format.mintick) + ' (' + str.tostring(distMa1, "#.#") + "%" + ')' + nl + 
         maTitle2 + str.tostring(ma2, format.mintick) + ' (' + str.tostring(distMa2, "#.#") + "%" + ')' + nl + 
         maTitle3 + str.tostring(ma3, format.mintick) + ' (' + str.tostring(distMa3, "#.#") + "%" + ')' + nl + 
         maTitle4 + str.tostring(ma4, format.mintick) + ' (' + str.tostring(distMa4, "#.#") + "%" + ')'
         ) 

if ISWEEKLY and (barstate.isconfirmed or barstate.islast)
    label(dashboard)
    dashboard := label.new(bar_index, high ,color = color.new(color.white,100), tooltip = dateTitle + str.format_time(time, 'MM-dd-yy', 'UTC-7') + nl + 
         highTitle +  str.tostring(high, "##.##") +  nl + 
         lowTitle + str.tostring(low, "##.##") + nl + 
         closeTitle + str.tostring(close, "##.##") + ' (' + str.tostring(dollarChng, format.mintick) + ')' + nl + 
         perChangeTitle + str.tostring(perChng, "##.##") + nl + 
         clsrngTitleWk + str.tostring(closeRange, "#") + "%" +  nl + 
         volTitle + (syminfo.ticker == 'IXIC' ? str.tostring(nasVolWk, "#,###,###,###") : 
         syminfo.ticker == 'SPX' ? str.tostring(spxVolWk, "#,###,###,###") : str.tostring(volume, "#,###,###,###")) + nl +
         volPercTitle + str.tostring(runRateWk, "#") + '%' +  nl +
         maTitle5 + str.tostring(ma5, format.mintick) + ' (' + str.tostring(distMa5, "#.#") + "%" + ')' + nl + 
         maTitle6 + str.tostring(ma6, format.mintick) + ' (' + str.tostring(distMa6, "#.#") + "%" + ')'
         ) 





