#vol_compare_night
#https://usethinkscript.com/threads/add-chart-label-to-compare-cumulative-overnight-volume-to-avg-overnight-vol.20199/
#Add Chart Label to compare Cumulative Overnight Volume to Avg Overnight Vol
#GOCUSH Jan 6, 2025 #1
#In TOS Studies there is a Study named CumulativeOvernightVolume
# with plots for CumulativeOvernightVolume and AverageOvernightVolume on lines 42 and 43
# Add a Label to show the ratio of Average-to-Cumulative Volume
#Additionally, I would like the Label color to change from (some dull color) to GREEN when the Cumulative overnight volume is more than X times (an input) the Average Volume
# CumulativeOvernightVolume
declare lower;
declare hide_on_daily;
input nightSessionFromMidnight = 0100;
input firstHourTrading = 0930;
input mainSession = 1030;
input nightSessionFromMainSessionEnd = 1615;
input paintBars = yes;
def isNightSessionFromMidnight = SecondsFromTime(nightSessionFromMidnight) >= 0 and SecondsTillTime(firstHourTrading) > 0;
def isFirstHourTrading = SecondsFromTime(firstHourTrading) >= 0 and SecondsTillTime(mainSession) > 0;
def isMainSession = SecondsFromTime(mainSession) >= 0 and SecondsTillTime(nightSessionFromMainSessionEnd) > 0;
def newNightSessionFromMidnight = isNightSessionFromMidnight and !isNightSessionFromMidnight[1];
def cOvernightVolume = if newNightSessionFromMidnight then volume else if isNightSessionFromMidnight then cOvernightVolume[1] + volume else cOvernightVolume[1];
def count = count[1] + if newNightSessionFromMidnight then 1 else 0;
def overnightVolume1;
def overnightVolume2;
def overnightVolume3;
def overnightVolume4;
def overnightVolume5;
if (newNightSessionFromMidnight and count > 1) {
overnightVolume1 = cOvernightVolume[1];
overnightVolume2 = overnightVolume1[1];
overnightVolume3 = overnightVolume2[1];
overnightVolume4 = overnightVolume3[1];
overnightVolume5 = overnightVolume4[1];
} else {
overnightVolume1 = overnightVolume1[1];
overnightVolume2 = overnightVolume2[1];
overnightVolume3 = overnightVolume3[1];
overnightVolume4 = overnightVolume4[1];
overnightVolume5 = overnightVolume5[1];
}
plot CumulativeOvernightVolume = if isNightSessionFromMidnight then cOvernightVolume else Double.NaN;
plot AverageOvernightVolume = if count > 5 then (overnightVolume1 + overnightVolume2 + overnightVolume3 + overnightVolume4 + overnightVolume5) / 5 else Double.NaN;
CumulativeOvernightVolume.DefineColor("Below", GetColor(1));
CumulativeOvernightVolume.DefineColor("Above", GetColor(0));
CumulativeOvernightVolume.AssignValueColor(if CumulativeOvernightVolume > AverageOvernightVolume then CumulativeOvernightVolume.Color("Above") else CumulativeOvernightVolume.Color("Below"));
CumulativeOvernightVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
AverageOvernightVolume.SetDefaultColor(GetColor(5));
AverageOvernightVolume.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DefineGlobalColor("Night Session #1", Color.WHITE);
DefineGlobalColor("First Hour Trading", Color.RED);
DefineGlobalColor("Main Session", Color.BLUE);
DefineGlobalColor("Night Session #2", Color.GRAY);
AssignPriceColor(if paintBars then if isNightSessionFromMidnight then GlobalColor("Night Session #1") else if isFirstHourTrading then GlobalColor("First Hour Trading") else if isMainSession then GlobalColor("Main Session") else GlobalColor("Night Session #2") else Color.CURRENT);
#------------------------------------
# Add a Label to show the ratio of Average-to-Cumulative Volume
# the Label color to change from (some dull color) to GREEN,
# when the Cumulative overnight volume is more than X times (an input) the Average Volume
def avg = if isNightSessionFromMidnight then AverageOvernightVolume else avg[1];
def cum = if isNightSessionFromMidnight then CumulativeOvernightVolume else cum[1];
#def vratio_ac = AverageOvernightVolume / CumulativeOvernightVolume;
#def vratio_ca = CumulativeOvernightVolume / AverageOvernightVolume;
def vratio_ac = avg/cum;
def vratio_ca = cum/avg;
input factor = 5;
def ca_isbig = cum > (avg * factor);
addlabel(1, " ", color.black);
addlabel(1, "avg/cum " + vratio_ac , color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "cum/avg " + vratio_ca , (if ca_isbig then color.green else color.gray));
addlabel(1, " ", color.black);
addchartbubble(0,0,
AverageOvernightVolume + " a\n" +
CumulativeOvernightVolume + " c"
, color.yellow, yes);
#