Anna-Lysa
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MartinKostov

//@version=5
// Premarket High/Low + LastDayHigh/Low + ATR + VWAP + 3xDailyMA + 2 FrameEMA + Volume% AVG Daily Volume ... 

indicator('Anna-Lysa', shorttitle="Analyse", overlay=true)

import TradingView/ta/6

aftermarket = input.bool(title='Include Aftermarket', defval=false, group='Overnight Session')
ending_hour = input.int(defval=9, title='PM Ending Hour', group='Overnight Session', inline='Input 0')
ending_minute = input.int(defval=30, title=' Minute', group='Overnight Session', inline='Input 0')
spm = input.bool(true, title='Show Premarket High/Low ', group='Overnight Session', inline='Input 1')
pmColor = input.color(color.new(color.yellow, 30), title='', group='Overnight Session', inline='Input 1')
pmwidth = input.int(1, title="line", options=[1, 2, 3, 4],  group='Overnight Session', inline='Input 1')

sy = input.string(title='Show Lastday   High/Low ', group='Show Day / Week / Month high/low ', options=['on', 'off'], defval='on', inline='Input 0')
syColor = input.color(color.new(color.red, 30), title='', group='Show Day / Week / Month high/low ', inline='Input 0')
sywidth = input.int(1, title='line', options=[1, 2, 3, 4],  group='Show Day / Week / Month high/low ', inline='Input 0')
sw = input.string(title='Show Lastweek  High/Low' + ' ', group='Show Day / Week / Month high/low ', options=['off', 'current', 'last'], defval='off', inline='Input 1')
swColor = input.color(color.new(color.green, 30), title='', group='Show Day / Week / Month high/low ', inline='Input 1')
swwidth = input.int(1, title='line', options=[1, 2, 3, 4],  group='Show Day / Week / Month high/low ', inline='Input 1')
sm = input.string(title='Show Lastmonth High/Low', group='Show Day / Week / Month high/low ', options=['off', 'current', 'last'], defval='off', inline='Input 2')
smColor = input.color(color.new(color.lime, 30), title='', group='Show Day / Week / Month high/low ', inline='Input 2')
smwidth = input.int(1, title='line', options=[1, 2, 3, 4],  group='Show Day / Week / Month high/low ', inline='Input 2')


svwap = input.bool(true, title='Show VWAP', group='VWAP and stdev ops  ', inline='Input 0')
source = input.source(hlc3, title='', group='VWAP and stdev ops  ', inline='Input 0')
svwapPColor = input.color(color.new(color.lime, 30), title='', group='VWAP and stdev ops  ', inline='Input 0')
svwapNColor = input.color(color.new(color.red, 30), title='', group='VWAP and stdev ops  ', inline='Input 0')
svwapStyle = input.string('dotted', title='', options=['line','dotted'], group='VWAP and stdev ops  ', inline='Input 0')

sstdev = input.bool(false, title='Show Stdev1', group='VWAP and stdev ops  ', inline='Input 1')
devNum = input.int(1, title='Number', group='VWAP and stdev ops  ', inline='Input 1')
sstdevColor = input.color(color.new(color.gray, 30), title='', group='VWAP and stdev ops  ', inline='Input 1')
sstdev2 = input.bool(false, title='Show Stdev2', group='VWAP and stdev ops  ', inline='Input 2')
devNum2 = input.int(2, title='Number', group='VWAP and stdev ops  ', inline='Input 2')
sstdev2Color = input.color(color.new(color.gray, 30), title='', group='VWAP and stdev ops  ', inline='Input 2')
sstdev3 = input.bool(false, title='Show Stdev3', group='VWAP and stdev ops  ', inline='Input 3')
devNum3 = input.int(3, title='Number', group='VWAP and stdev ops  ', inline='Input 3')
sstdev3Color = input.color(color.new(color.gray, 30), title='', group='VWAP and stdev ops  ', inline='Input 3')
sWvwap = input.bool(false, title='Show Weekly VWAP', group='VWAP and stdev ops  ', inline='Input 4')
sWvwapColor = input.color(color.new(color.gray, 30), title='', group='VWAP and stdev ops  ', inline='Input 4')
sMvwap = input.bool(false, title='Show Monthly VWAP', group='VWAP and stdev ops  ', inline='Input 5')
sMvwapColor = input.color(color.new(color.gray, 30), title='', group='VWAP and stdev ops  ', inline='Input 5')



wt = time('W')
mt = time('M')
wstart = na(wt[1]) or wt > wt[1]
mstart = na(mt[1]) or mt > mt[1]
wsumSrc = source * volume
wsumVol = volume
wsumSrc := wstart ? wsumSrc : wsumSrc + wsumSrc[1]
wsumVol := wstart ? wsumVol : wsumVol + wsumVol[1]
wvw = wsumSrc / wsumVol
msumSrc = source * volume
msumVol = volume
msumSrc := mstart ? msumSrc : msumSrc + msumSrc[1]
msumVol := mstart ? msumVol : msumVol + msumVol[1]
mvw = msumSrc / msumVol


satr1 = input.bool(true, title='Show ATR1', group='Daily ATR', inline='Input 1')
atr_factor1 = input.float(title='Faktor', group='Daily ATR', inline='Input 1', defval=1)
atr_days1 = input.int(title='Days', group='Daily ATR', inline='Input 1', defval=10)
satr1Color = input.color(color.new(color.silver, 30), title='', group='Daily ATR', inline='Input 1')
//satr1width = input.int(1, title='', options=[1, 2, 3, 4],  group='Daily ATR', inline='Input 1')

satr2 = input.bool(false, title='Show ATR2', group='Daily ATR', inline='Input 2')
atr_factor2 = input.float(title='Faktor', group='Daily ATR', inline='Input 2', defval=2)
atr_days2 = input.int(title='Days', group='Daily ATR', inline='Input 2', defval=10)
satr2Color = input.color(color.new(color.silver, 30), title='', group='Daily ATR', inline='Input 2')
//satr2width = input.int(1, title='line', options=[1, 2, 3, 4],  group='Daily ATR', inline='Input 2')

satr3 = input.bool(false, title='Show ATR3', group='Daily ATR', inline='Input 3')
atr_factor3 = input.float(title='Faktor', group='Daily ATR', inline='Input 3', defval=3)
atr_days3 = input.int(title='Days', group='Daily ATR', inline='Input 3', defval=10)
satr3Color = input.color(color.new(color.silver, 30), title='', group='Daily ATR', inline='Input 3')
//satr3width = input.int(1, title='line', options=[1, 2, 3, 4],  group='Daily ATR', inline='Input 3')

satr4 = input.bool(false, title='Show ATR4', group='Daily ATR', inline='Input 4')
atr_factor4 = input.float(title='Faktor', group='Daily ATR', inline='Input 4', defval=4)
atr_days4 = input.int(title='Days', group='Daily ATR', inline='Input 4', defval=10)
satr4Color = input.color(color.new(color.silver, 30), title='', group='Daily ATR', inline='Input 4')
//satr4width = input.int(1, title='line', options=[1, 2, 3, 4],  group='Daily ATR', inline='Input 4')

satr5 = input.bool(false, title='Show ATR5', group='Daily ATR', inline='Input 5')
atr_factor5 = input.float(title='Faktor', group='Daily ATR', inline='Input 5', defval=5)
atr_days5 = input.int(title='Days', group='Daily ATR', inline='Input 5', defval=10)
satr5Color = input.color(color.new(color.silver, 30), title='', group='Daily ATR', inline='Input 5')
//satr5width = input.int(1, title='line', options=[1, 2, 3, 4],  group='Daily ATR', inline='Input 5')

//satr6 = input(false, title="Show ATR6", group = "ATR", inline = "Input 6")
//atr_factor6 = input(title="Faktor", group = "ATR", inline = "Input 6", type=input.float, defval=6)
//atr_days6 = input(title="Days", group = "ATR", inline = "Input 6", type=input.integer, defval=10)
//satr6Color = input(color.gray, title="", group = "ATR", inline = "Input 6") 





slen1 = input.bool(true, title='Show Daily MA', group='Daily moving averages Lines', inline='Input 1')
len1 = input.int(20, '', minval=1, group='Daily moving averages Lines', inline='Input 1')
slen1Color = input.color(color.new(color.blue, 30), title='', group='Daily moving averages Lines', inline='Input 1')
slen2 = input.bool(true, title='Show Daily MA', group='Daily moving averages Lines', inline='Input 2')
len2 = input.int(100, '', minval=1, group='Daily moving averages Lines', inline='Input 2')
slen2Color = input.color(color.new(color.blue, 30), title='', group='Daily moving averages Lines', inline='Input 2')
slen3 = input.bool(true, title='Show Daily MA', group='Daily moving averages Lines', inline='Input 3')
len3 = input.int(200, '', minval=1, group='Daily moving averages Lines', inline='Input 3')
slen3Color = input.color(color.new(color.blue, 30), title='', group='Daily moving averages Lines', inline='Input 3')


slenEMA1 = input.bool(true, title='Show Frame EMA', group='Timeframe exponential moving average', inline='Input 1')
lenEMA1 = input.int(8, minval=1, title='', group='Timeframe exponential moving average', inline='Input 1')
srcEMA1 = close  // input(close, title="Source", group = "Timeframe MA", inline = "Input 1")
offsetEMA1 = 0  // input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500, group = "Timeframe MA", inline = "Input 1")
slenEMA1Color = input.color(color.new(color.lime, 60), title='', group='Timeframe exponential moving average', inline='Input 1')

slenEMA2 = input.bool(true, title='Show Frame EMA', group='Timeframe exponential moving average', inline='Input 2')
lenEMA2 = input.int(21, minval=1, title='', group='Timeframe exponential moving average', inline='Input 2')
srcEMA2 = close  // input(close, title="SourceEMA2", group = "Timeframe MA", inline = "Input 2")
offsetEMA2 = 0  //input(title="OffsetEMA2", type=input.integer, defval=0, minval=-500, maxval=500, group = "Timeframe MA", inline = "Input 2")
slenEMA2Color = input.color(color.new(color.orange, 60), title='', group='Timeframe exponential moving average', inline='Input 2')


sVM = input.bool(true, title='Show AvgVolume %', group='Show / Hide Volume %', inline='Input 0', tooltip='Volume % from Average Volume last x Candles')
VolumeColor = input.color(color.new(color.orange, 30), title='', group='Show / Hide Volume %', inline='Input 0')
Vsma = input.int(title='Last Candles', defval=10, group='Show / Hide Volume %', inline='Input 0')

stbl = input.bool(true, title='Show at ', group="Table", inline="0")
tablePositionY = input.string('top', title='Y-Pos', options=['top', 'middle', 'bottom'], group="Table", inline="0")
tablePositionX = input.string('right', title='X-Pos', options=['left', 'center', 'right'], group="Table", inline="0")
tableTextColor = input(color.new(color.silver, 80), "Table Text ", group="Table", inline="1")
tableBgColor =   input(color.new(color.black,95), "Table Background ", group="Table", inline="1")
DRlength =       input.int(title="Ø Days Range ", defval=10, minval=1, group="Table", inline="2")
DVlength =       input.int(title="Ø Days Volume", defval=10, minval=1, group="Table", inline="3")
FrameATRlength = input.int(title="ATR Ø Last Candles", defval=2, minval=1, group="Table", inline="4")
RvolLength = input.int(title="RVOL at Time Lenght", defval=5, minval=1, group="Table", inline="5")

y= year(timenow)
m= month(timenow)
d= dayofmonth(timenow)
start= timestamp(y, m, d, 06, 00)
end= timestamp(y, m, d, 16, 00)

float vwapsum = na
float volumesum = na
float v2sum = na

change_1 = ta.change(dayofweek)
newSession = change_1 ? 1 : 0
vwapsum := newSession ? hl2 * volume : vwapsum[1] + hl2 * volume
volumesum := newSession ? volume : volumesum[1] + volume
v2sum := newSession ? volume * hl2 * hl2 : v2sum[1] + volume * hl2 * hl2
myvwap = vwapsum / volumesum
dev = math.sqrt(math.max(v2sum / volumesum - myvwap * myvwap, 0))


pdh = timeframe.isintraday ? time('1440', '0000-0930:23456') ? request.security(syminfo.tickerid, 'D', high[0]) : request.security(syminfo.tickerid, 'D', high[1]) : na
pdl = timeframe.isintraday ? time('1440', '0000-0930:23456') ? request.security(syminfo.tickerid, 'D', low[0]) : request.security(syminfo.tickerid, 'D', low[1]) : na

volumeDailyAVG = request.security(syminfo.tickerid, 'D', ta.sma(volume, Vsma))
volumelastAVG = ta.sma(volume, Vsma)
volumeToday = request.security(syminfo.tickerid, 'D', volume)
percentageToday = volumeToday / volumeDailyAVG * 100
percentage = volume / volumeDailyAVG * 100
percentage2 = volume / volumelastAVG * 100
color_1 = color.new(#f23535, 50)
color_2 = color.new(#58a9f5, 50)

out1 = request.security(syminfo.tickerid, 'D', ta.sma(close, len1))
out2 = request.security(syminfo.tickerid, 'D', ta.sma(close, len2))
out3 = request.security(syminfo.tickerid, 'D', ta.sma(close, len3))
outEMA1 = ta.ema(srcEMA1, lenEMA1)
outEMA2 = ta.ema(srcEMA2, lenEMA2)

vwapcond = timeframe.isintraday ?  ta.vwap(source) : na

lastClose = request.security(syminfo.tickerid, 'D', close[1], lookahead=barmerge.lookahead_on) 

t = aftermarket == false ? time('1440', '0400-0930:23456') : time('1440', '1600-0930:23456')  // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter
is_first = na(t[1]) and not na(t) or t[1] < t

day_high = float(na)
day_low = float(na)
k = int(na)

if is_first and barstate.isnew and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    day_high := high
    day_low := low
    day_low
else
    day_high := day_high[1]
    day_low := day_low[1]
    day_low

if high > day_high and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    day_high := high
    day_high

if low < day_low and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    day_low := low
    day_low


dailyATR1 = request.security(syminfo.tickerid, 'D', ta.atr(atr_days1))
dailyATR2 = request.security(syminfo.tickerid, 'D', ta.atr(atr_days2))
dailyATR3 = request.security(syminfo.tickerid, 'D', ta.atr(atr_days3))
dailyATR4 = request.security(syminfo.tickerid, 'D', ta.atr(atr_days4))
dailyATR5 = request.security(syminfo.tickerid, 'D', ta.atr(atr_days5))
//dailyATR6 = security(syminfo.tickerid, 'D', atr(atr_days6))
davg0 = request.security(syminfo.tickerid, 'D', high[0] - low[0])




adr= ( request.security(syminfo.tickerid, 'D', high[1] - low[1]) + request.security(syminfo.tickerid, 'D', high[2] - low[2]) + request.security(syminfo.tickerid, 'D', high[3] - low[3]) + request.security(syminfo.tickerid, 'D', high[4] - low[4]) + request.security(syminfo.tickerid, 'D', high[5] - low[5]) + request.security(syminfo.tickerid, 'D', high[6] - low[6]) + request.security(syminfo.tickerid, 'D', high[7] - low[7]) + request.security(syminfo.tickerid, 'D', high[8] - low[8]) + request.security(syminfo.tickerid, 'D', high[9] - low[9]) + request.security(syminfo.tickerid, 'D', high[10] - low[10]) ) / 10 

FrameATR = request.security(syminfo.tickerid,'', ta.sma(ta.tr(true),FrameATRlength))
[currentVolume, pastVolume, _] = ta.relativeVolume( RvolLength, "1D",  true)

if stbl 
    var table dataTable = table.new(tablePositionY + '_' + tablePositionX, 4, 5, border_width=7)
    table.cell(dataTable, 1, 0, text= "Daily Range Ø\n" + str.tostring(100-(adr-davg0)/adr*100 ,"0.00") +" %\n" + ( 100-(adr-davg0)/adr*100 < 100 ? " " + str.tostring(davg0 - adr  ,"0.00")+ " $"  : "+ " + str.tostring(davg0 - adr  ,"0.00")+ "$" ) , bgcolor=tableBgColor, text_color=tableTextColor,text_size=size.auto)
    table.cell(dataTable, 2, 0, text= "Daily Volume Ø\n " + str.tostring(100-(volumeDailyAVG-volumeToday)/volumeDailyAVG*100 ,"0.00") +" %\n" + ( 100-(volumeDailyAVG-volumeToday)/volumeDailyAVG*100 > 100 ? "+ " + str.tostring(volumeToday-volumeDailyAVG  , format.volume) : "- " + str.tostring(volumeDailyAVG - volumeToday  , format.volume) ), bgcolor=tableBgColor, text_color=tableTextColor,text_size=size.auto)
    table.cell(dataTable, 1, 1, text= "Atr Ø SL\n" + str.tostring(FrameATR , "0.00") +" $", bgcolor=tableBgColor, text_color=tableTextColor,text_size=size.auto)
    table.cell(dataTable, 2, 1, text=  "RVOL at Time (1D)\n" + str.tostring( currentVolume / pastVolume , "0.00")    , bgcolor=tableBgColor, text_color=tableTextColor,text_size=size.auto)

TSO = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")
MarketCap = TSO * close[1] 


//table.cell(dataTable, 1, 2, text= "Market Cap\n"+ str.tostring(MarketCap , format.volume)  , bgcolor=tableBgColor, text_color=tableTextColor,text_size=size.auto)
//table.cell(dataTable, 2, 2, text=  " " , bgcolor=tableBgColor, text_color=tableTextColor,text_size=size.auto) 


plot(spm and day_high ? day_high : na, title='PMH Line', trackprice=true, offset=-9999, color=pmColor, linewidth=pmwidth, style=plot.style_line,  editable=false)


var l1 = label.new(bar_index, day_high, 'PMH ', color=tableBgColor, textcolor=pmColor, style=label.style_label_down, tooltip='Premarket High')
label.set_xy(l1, bar_index + 50, spm and day_high ? day_high : na)
label.set_text(l1, 'PMH ' + str.tostring(spm and day_high ? day_high : na, '0.00'))

plot(spm and day_low ? day_low : na, title='PML Line', trackprice=true, offset=-9999, color=pmColor, linewidth=pmwidth, editable=false)
var l2 = label.new(bar_index, day_low, 'PML ', color=tableBgColor, textcolor=pmColor, style=label.style_label_down, tooltip='Premarket Low')
label.set_xy(l2, bar_index + 50, spm and day_low ? day_low : na)
label.set_text(l2, 'PML ' + str.tostring(spm and day_low ? day_low : na, '0.00'))




plot(sy == 'on' and pdh ? pdh : na, title='Previous Daily High', style=plot.style_line, trackprice=true, offset=-9999, color=syColor, linewidth=sywidth, editable=false)
var l3 = label.new(bar_index, pdh, 'LDH ', color=tableBgColor, textcolor=syColor, style=label.style_label_down, tooltip='Last Day High')
label.set_xy(l3, bar_index + 30, sy == 'on' and pdh ? pdh : na)
label.set_text(l3, 'LDH ' + str.tostring(sy == 'on' and pdh ? pdh : na, '0.00'))

plot(sy == 'on' and pdl ? pdl : na, title='Previous Daily Low', style=plot.style_line, trackprice=true,  offset=-9999, color=syColor, linewidth=sywidth, editable=false)
var l4 = label.new(bar_index, pdl, 'LDL ', color=tableBgColor, textcolor=syColor, style=label.style_label_down, tooltip='Last Day Low')
label.set_xy(l4, bar_index + 30, sy == 'on' and pdl ? pdl : na)
label.set_text(l4, 'LDL ' + str.tostring(sy == 'on' and pdl ? pdl : na, '0.00'))


plot(sw == 'current' ? request.security(syminfo.tickerid, 'W', high[0]) : sw == 'last' ? request.security(syminfo.tickerid, 'W', high[1]) : na, title='WeekHigh Line', trackprice=true, offset=-9999, color=swColor, linewidth=swwidth, editable=false)
var l17 = label.new(bar_index, lastClose, 'WH ', color=tableBgColor, textcolor=swColor, style=label.style_label_down, tooltip='Weekly High ')
label.set_xy(l17, bar_index + 70, sw == 'current' ? request.security(syminfo.tickerid, 'W', high[0]) : sw == 'last' ? request.security(syminfo.tickerid, 'W', high[1]) : na)
label.set_text(l17, 'WH ' + str.tostring(sw == 'current' ? request.security(syminfo.tickerid, 'W', high[0]) : sw == 'last' ? request.security(syminfo.tickerid, 'W', high[1]) : na, '0.00'))



plot(sw == 'current' ? request.security(syminfo.tickerid, 'W', low[0]) : sw == 'last' ? request.security(syminfo.tickerid, 'W', low[1]) : na, title='WeekLow Line', trackprice=true, offset=-9999, color=swColor, linewidth=swwidth, editable=false)
var l18 = label.new(bar_index, lastClose, 'WL ', color=tableBgColor, textcolor=swColor, style=label.style_label_down, tooltip='Weekly Low ')
label.set_xy(l18, bar_index + 70, sw == 'current' ? request.security(syminfo.tickerid, 'W', low[0]) : sw == 'last' ? request.security(syminfo.tickerid, 'W', low[1]) : na)
label.set_text(l18, 'WL ' + str.tostring(sw == 'current' ? request.security(syminfo.tickerid, 'W', low[0]) : sw == 'last' ? request.security(syminfo.tickerid, 'W', low[1]) : na, '0.00'))


plot(sm == 'current' ? request.security(syminfo.tickerid, 'M', high[0]) : sm == 'last' ? request.security(syminfo.tickerid, 'M', high[1]) : na, title='MonthHigh Line', trackprice=true, offset=-9999, color=smColor, linewidth=smwidth, editable=false)
var l19 = label.new(bar_index, lastClose, 'MH ', color=tableBgColor, textcolor=smColor, style=label.style_label_down, tooltip='Monthly High ')
label.set_xy(l19, bar_index + 70, sm == 'current' ? request.security(syminfo.tickerid, 'M', high[0]) : sm == 'last' ? request.security(syminfo.tickerid, 'M', high[1]) : na)
label.set_text(l19, 'MH ' + str.tostring(sm == 'current' ? request.security(syminfo.tickerid, 'M', high[0]) : sm == 'last' ? request.security(syminfo.tickerid, 'M', high[1]) : na, '0.00'))

plot(sm == 'current' ? request.security(syminfo.tickerid, 'M', low[0]) : sm == 'last' ? request.security(syminfo.tickerid, 'M', low[1]) : na, title='MonthLow Line', trackprice=true, offset=-9999, color=smColor, linewidth=smwidth, editable=false)
var l20 = label.new(bar_index, lastClose, 'ML ', color=tableBgColor, textcolor=smColor, style=label.style_label_down, tooltip='Monthly Low ')
label.set_xy(l20, bar_index + 70, sm == 'current' ? request.security(syminfo.tickerid, 'M', low[0]) : sm == 'last' ? request.security(syminfo.tickerid, 'M', low[1]) : na)
label.set_text(l20, 'ML ' + str.tostring(sm == 'current' ? request.security(syminfo.tickerid, 'M', low[0]) : sm == 'last' ? request.security(syminfo.tickerid, 'M', low[1]) : na, '0.00'))



plot(satr1 and lastClose + dailyATR1 * atr_factor1 ? lastClose + dailyATR1 * atr_factor1 : na, title='ATRH1 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr1Color, linewidth=1, editable=false)
var l5 = label.new(bar_index, lastClose, 'ATR-H ', color=tableBgColor, textcolor=satr1Color, style=label.style_label_down, tooltip='High of the daily ATR')
label.set_xy(l5, bar_index + 70, satr1 and lastClose + dailyATR1 * atr_factor1 ? lastClose + dailyATR1 * atr_factor1 : na)
label.set_text(l5, 'ATR-H ' + str.tostring(satr1 and lastClose + dailyATR1 * atr_factor1 ? lastClose + dailyATR1 * atr_factor1 : na, '0.00'))

plot(satr1 and lastClose - dailyATR1 * atr_factor1 ? lastClose - dailyATR1 * atr_factor1 : na, title='ATRL1 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr1Color, linewidth=1, editable=false)
var l6 = label.new(bar_index, lastClose, 'ATR-L ', color=tableBgColor, textcolor=satr1Color, style=label.style_label_down, tooltip='Low of the daily ATR')
label.set_xy(l6, bar_index + 70, satr1 and lastClose - dailyATR1 * atr_factor1 ? lastClose - dailyATR1 * atr_factor1 : na)
label.set_text(l6, 'ATR-L ' + str.tostring(satr1 and lastClose - dailyATR1 * atr_factor1 ? lastClose - dailyATR1 * atr_factor1 : na, '0.00'))

plot(satr2 and lastClose + dailyATR2 * atr_factor2 ? lastClose + dailyATR2 * atr_factor2 : na, title='ATRH2 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr2Color, linewidth=1, editable=false)
var l7 = label.new(bar_index, lastClose, 'ATR2-H ', color=tableBgColor, textcolor=satr2Color, style=label.style_label_down, tooltip='High of the daily ATR 2')
label.set_xy(l7, bar_index + 70, satr2 and lastClose + dailyATR2 * atr_factor2 ? lastClose + dailyATR2 * atr_factor2 : na)
label.set_text(l7, 'ATR2-H ' + str.tostring(satr2 and lastClose + dailyATR2 * atr_factor2 ? lastClose + dailyATR2 * atr_factor2 : na, '0.00'))

plot(satr2 and lastClose - dailyATR2 * atr_factor2 ? lastClose - dailyATR2 * atr_factor2 : na, title='ATRL2 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr2Color, linewidth=1, editable=false)
var l8 = label.new(bar_index, lastClose, 'ATR2-L ', color=tableBgColor, textcolor=satr2Color, style=label.style_label_down, tooltip='Low of the daily ATR 2')
label.set_xy(l8, bar_index + 70, satr2 and lastClose - dailyATR2 * atr_factor2 ? lastClose - dailyATR2 * atr_factor2 : na)
label.set_text(l8, 'ATR2-L ' + str.tostring(satr2 and lastClose - dailyATR2 * atr_factor2 ? lastClose - dailyATR2 * atr_factor2 : na, '0.00'))

plot(satr3 and lastClose + dailyATR3 * atr_factor3 ? lastClose + dailyATR3 * atr_factor3 : na, title='ATRH3 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr3Color, linewidth=1, editable=false)
var l9 = label.new(bar_index, lastClose, 'ATR3-H ', color=tableBgColor, textcolor=satr3Color, style=label.style_label_down, tooltip='High of the daily ATR 3')
label.set_xy(l9, bar_index + 70, satr3 and lastClose + dailyATR3 * atr_factor3 ? lastClose + dailyATR3 * atr_factor3 : na)
label.set_text(l9, 'ATR3-H ' + str.tostring(satr3 and lastClose + dailyATR3 * atr_factor3 ? lastClose + dailyATR3 * atr_factor3 : na, '0.00'))

plot(satr3 and lastClose - dailyATR3 * atr_factor3 ? lastClose - dailyATR3 * atr_factor3 : na, title='ATRL3 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr3Color, linewidth=1, editable=false)
var l10 = label.new(bar_index, lastClose, 'ATR3-L ', color=tableBgColor, textcolor=satr3Color, style=label.style_label_down, tooltip='Low of the daily ATR 3')
label.set_xy(l10, bar_index + 70, satr3 and lastClose - dailyATR3 * atr_factor3 ? lastClose - dailyATR3 * atr_factor3 : na)
label.set_text(l10, 'ATR3-L ' + str.tostring(satr3 and lastClose - dailyATR3 * atr_factor3 ? lastClose - dailyATR3 * atr_factor3 : na, '0.00'))

plot(satr4 and lastClose + dailyATR4 * atr_factor4 ? lastClose + dailyATR4 * atr_factor4 : na, title='ATRH4 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr4Color, linewidth=1, editable=false)
var l11 = label.new(bar_index, lastClose, 'ATR4-H ', color=tableBgColor, textcolor=satr4Color, style=label.style_label_down, tooltip='High of the daily ATR 4')
label.set_xy(l11, bar_index + 70, satr4 and lastClose + dailyATR4 * atr_factor4 ? lastClose + dailyATR4 * atr_factor4 : na)
label.set_text(l11, 'ATR4-H ' + str.tostring(satr4 and lastClose + dailyATR4 * atr_factor4 ? lastClose + dailyATR4 * atr_factor4 : na, '0.00'))

plot(satr4 and lastClose - dailyATR4 * atr_factor4 ? lastClose - dailyATR4 * atr_factor4 : na, title='ATRL4 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr4Color, linewidth=1, editable=false)
var l12 = label.new(bar_index, lastClose, 'ATR4-L ', color=tableBgColor, textcolor=satr4Color, style=label.style_label_down, tooltip='Low of the daily ATR 4')
label.set_xy(l12, bar_index + 70, satr4 and lastClose - dailyATR4 * atr_factor4 ? lastClose - dailyATR4 * atr_factor4 : na)
label.set_text(l12, 'ATR4-L ' + str.tostring(satr4 and lastClose - dailyATR4 * atr_factor4 ? lastClose - dailyATR4 * atr_factor4 : na, '0.00'))

plot(satr5 and lastClose + dailyATR5 * atr_factor5 ? lastClose + dailyATR5 * atr_factor5 : na, title='ATRH5 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr5Color, linewidth=1, editable=false)
var l13 = label.new(bar_index, lastClose, 'ATR5-H ', color=tableBgColor, textcolor=satr5Color, style=label.style_label_down, tooltip='High of the daily ATR 5')
label.set_xy(l13, bar_index + 70, satr5 and lastClose + dailyATR5 * atr_factor5 ? lastClose + dailyATR5 * atr_factor5 : na)
label.set_text(l13, 'ATR5-H ' + str.tostring(satr5 and lastClose + dailyATR5 * atr_factor5 ? lastClose + dailyATR5 * atr_factor5 : na, '0.00'))

plot(satr5 and lastClose - dailyATR5 * atr_factor5 ? lastClose - dailyATR5 * atr_factor5 : na, title='ATRL5 Line', style=plot.style_line, trackprice=true, offset=-9999, color=satr5Color, linewidth=1, editable=false)
var l14 = label.new(bar_index, lastClose, 'ATR5-L ', color=tableBgColor, textcolor=satr5Color, style=label.style_label_down, tooltip='Low of the daily ATR 5')
label.set_xy(l14, bar_index + 70, satr5 and lastClose - dailyATR5 * atr_factor5 ? lastClose - dailyATR5 * atr_factor5 : na)
label.set_text(l14, 'ATR5-L ' + str.tostring(satr5 and lastClose - dailyATR5 * atr_factor5 ? lastClose - dailyATR5 * atr_factor5 : na, '0.00'))

//plot(satr6 and lastClose + dailyATR6*atr_factor6 ? lastClose + dailyATR6*atr_factor6 : na, title='ATRH6 Line',style=plot.style_line, trackprice=true, offset=-9999, color=satr6Color, linewidth=1)
//var l15 = label.new(bar_index, lastClose, "ATR6-H " ,color=tableBgColor, textcolor=color.new(satr6Color, 0)  , style=label.style_label_down, tooltip="High of the daily ATR 6" )
//label.set_xy(l15, bar_index+70, satr6 and lastClose + dailyATR6*atr_factor6 ? lastClose + dailyATR6*atr_factor6 : na)
//label.set_text(l15, "ATR6-H " + tostring(satr6 and lastClose + dailyATR6*atr_factor6 ? lastClose + dailyATR6*atr_factor6 : na, '0.00'))

//plot(satr6 and lastClose - dailyATR6*atr_factor6 ? lastClose - dailyATR6*atr_factor6 : na, title='ATRL6 Line',style=plot.style_line, trackprice=true, offset=-9999, color=satr6Color, linewidth=1)
//var l16 = label.new(bar_index, lastClose, "ATR6-L " ,color=tableBgColor, textcolor=color.new(satr6Color, 0)  , style=label.style_label_down, tooltip="Low of the daily ATR 6" )
//label.set_xy(l16, bar_index+70, satr6 and lastClose - dailyATR6*atr_factor6 ? lastClose - dailyATR6*atr_factor6 : na)
//label.set_text(l16, "ATR6-L " + tostring(satr6 and lastClose - dailyATR6*atr_factor6 ? lastClose - dailyATR6*atr_factor6 : na, '0.00'))



plot(slen1 and out1 ? out1 : na, style=plot.style_circles, title='ma1 Line ', color=slen1Color, trackprice=true, offset=-9999, editable=false)
var l21 = label.new(bar_index, lastClose, 'Ma' + str.tostring(len1), color=tableBgColor, textcolor=slen1Color, style=label.style_label_down, tooltip='Ma' + str.tostring(len1))
label.set_xy(l21, bar_index + 120, slen1 and out1 ? out1 : na)
label.set_text(l21, 'Ma' + str.tostring(len1) + ' ' + str.tostring(slen1 and out1 ? out1 : na, '0.00'))

plot(slen2 and out2 ? out2 : na, style=plot.style_circles, title='ma2 Line', color=slen2Color, trackprice=true, offset=-9999, editable=false)
var l22 = label.new(bar_index, lastClose, 'Ma' + str.tostring(len2), color=tableBgColor, textcolor=slen1Color, style=label.style_label_down, tooltip='Ma' + str.tostring(len2))
label.set_xy(l22, bar_index + 120, slen2 and out2 ? out2 : na)
label.set_text(l22, 'Ma' + str.tostring(len2) + ' ' + str.tostring(slen2 and out2 ? out2 : na, '0.00'))

plot(slen3 and out3 ? out3 : na, style=plot.style_circles, title='ma3 Line', color=slen3Color, trackprice=true, offset=-9999, editable=false)
var l23 = label.new(bar_index, lastClose, 'Ma' + str.tostring(len3), color=tableBgColor, textcolor=slen3Color, style=label.style_label_down, tooltip='Ma' + str.tostring(len3))
label.set_xy(l23, bar_index + 120, slen3 and out3 ? out3 : na)
label.set_text(l23, 'Ma' + str.tostring(len3) + ' ' + str.tostring(slen3 and out3 ? out3 : na, '0.00'))


plot(slenEMA1 and outEMA1 ? outEMA1 : na, title='EMA1', color=slenEMA1Color, offset=offsetEMA1, editable=false)
plot(slenEMA2 and outEMA2 ? outEMA2 : na, title='EMA2', color=slenEMA2Color, offset=offsetEMA2, editable=false)


plot(svwap and vwapcond ? vwapcond : na, title='VWAP', color=ta.rising(vwapcond, 2) ? svwapPColor : svwapNColor, linewidth=1, style= svwapStyle == 'line' ? plot.style_line : plot.style_circles, trackprice=true, editable=false)
var l24 = label.new(bar_index, ta.vwap and vwapcond ? vwapcond : na, 'VWAP ' + str.tostring(ta.vwap and vwapcond ? vwapcond : na), color=tableBgColor, textcolor = ta.rising(vwapcond, 2) ? svwapPColor : svwapNColor, style=label.style_label_down, tooltip='volume weighted average price')
label.set_xy(l24, bar_index + 50, svwap and vwapcond ? vwapcond : na)
label.set_text(l24, 'VWAP ' + str.tostring(svwap and vwapcond ? vwapcond : na, '0.00'))
label.set_textcolor(l24, textcolor= ta.rising(vwapcond, 2) ? svwapPColor : svwapNColor)


plot(timeframe.isintraday and sWvwap ? wvw : na, title='W-VWAP', color=sWvwapColor, style=plot.style_circles, editable=false)
plot(timeframe.isintraday and sMvwap ? mvw : na, title='M-VWAP', color=sMvwapColor, style=plot.style_circles, editable=false)


plot(sstdev and myvwap + devNum * dev ? myvwap + devNum * dev : na, title='VWAP Upper Stdev', color=sstdevColor, style=plot.style_line, linewidth=1, editable=false)
plot(sstdev and myvwap - devNum * dev ? myvwap - devNum * dev : na, title='VWAP Lower Stdev', color=sstdevColor, style=plot.style_line, linewidth=1, editable=false)
plot(sstdev2 and myvwap + devNum2 * dev ? myvwap + devNum2 * dev : na, title='VWAP Upper Stdev2', color=sstdev2Color, style=plot.style_line, linewidth=1, editable=false)
plot(sstdev2 and myvwap - devNum2 * dev ? myvwap - devNum2 * dev : na, title='VWAP Lower Stdev2', color=sstdev2Color, style=plot.style_line, linewidth=1, editable=false)
plot(sstdev3 and myvwap + devNum3 * dev ? myvwap + devNum3 * dev : na, title='VWAP Upper Stdev3', color=sstdev3Color, style=plot.style_line, linewidth=1, editable=false)
plot(sstdev3 and myvwap - devNum3 * dev ? myvwap - devNum3 * dev : na, title='VWAP Lower Stdev3', color=sstdev3Color, style=plot.style_line, linewidth=1, editable=false)


//dt = time - time[1]
if barstate.islast and sVM
    var l25 = label.new(bar_index, na, style=label.style_none, text=str.tostring(percentage2, '#.##') + ' %', textcolor=VolumeColor, yloc=yloc.abovebar, tooltip='% Average Volume last x Candle. Prints Velocity ')
    label.delete(l25[1])


