#A nice indicator to play with. See notes below.
#Using volume to determine significant areas of support / resistance on intra-day charts.
#This indicator will work on 5 minute charts or below. The green boxes show the major areas
#from the morning sessions; gray boxes are from the mid-day session; and yellow boxes are from
#the late-afternoon session. The gray lines are the significant areas from the previous day.
def Today = if getday() == getlastday() then 1 else 0;
# Split the day into three trading blocks
def block1 = if SecondsFromTime(0930) >= 0 and SecondsTillTime(1100) > 0 then 1 else 0;
def block2 = if SecondsFromTime(1100) >= 0 and SecondsTillTime(1400) > 0 then 1 else 0;
def block3 = if SecondsFromTime(1400) >= 0 and SecondsTillTime(1600) > 0 then 1 else 0;
def startBlock1 = if block1 and !block1[1] then 1 else 0;
def startBlock2 = if block2 and !block2[1] then 1 else 0;
def startBlock3 = if block3 and !block3[1] then 1 else 0;
# Determine the first bar of the day
def nMinutes = GetAggregationPeriod() / 60000;
def nBars = RoundUp(390 / nMinutes, 0);
def FirstBar = if (BarNumber() - 1) % nBars == 0 then 1 else 0;
# Determine day number
def dayNumber = 1 + RoundDown((BarNumber() - 1) / nBars, 0);
# Track volume in each session block
def vol1 = if !block1 then 0 else if block1 and volume(period="5 min" ) > vol1[1] then volume(period="5 min" ) else vol1[1];
def vol2 = if !block2 then 0 else if block2 and volume(period="5 min" ) > vol2[1] then volume(period="5 min" ) else vol2[1];
def vol3 = if !block3 then 0 else if block3 and volume(period="5 min" ) > vol3[1] then volume(period="5 min" ) else vol3[1];
# Determine high / low for each block
def HighB1 = if startBlock1 then high(period="5 min" ) else if block1 and volume(period="5 min" ) > vol1[1] then high(period="5 min" ) else HighB1[1];
def LowB1 = if startBlock1 then low(period="5 min" ) else if block1 and volume(period="5 min" ) > vol1[1] then low(period="5 min" ) else LowB1[1];
def HighB2 = if startBlock2 then high(period="5 min" ) else if block2 and volume(period="5 min" ) > vol2[1] then high(period="5 min" ) else HighB2[1];
def LowB2 = if startBlock2 then low(period="5 min" ) else if block2 and volume(period="5 min" ) > vol2[1] then low(period="5 min" ) else LowB2[1];
def HighB3 = if startBlock3 then high(period="5 min" ) else if block3 and volume(period="5 min" ) > vol3[1] then high(period="5 min" ) else HighB3[1];
def LowB3 = if startBlock3 then low(period="5 min" ) else if block3 and volume(period="5 min" ) > vol3[1] then low(period="5 min" ) else LowB3[1];
# Plot today's data
plot hb1 = HighB1;
plot lb1 = LowB1;
plot hb2 = if block1 and dayNumber == 1 then Double.NaN else HighB2;
plot lb2 = if block1 and dayNumber == 1 then Double.NaN else LowB2;
plot hb3 = if (block1 or block2) and dayNumber == 1 then Double.NaN else HighB3;
plot lb3 = if (block1 or block2) and dayNumber == 1 then Double.NaN else LowB3;
hb1.SetHiding(1);
hb2.SetHiding(1);
hb3.SetHiding(1);
lb1.SetHiding(1);
lb2.SetHiding(1);
lb3.SetHiding(1);
# Color between the lines
def chb1 = if hb1 == hb1[-1] then hb1 else double.nan;
def chb2 = if !block1 and hb2 == hb2[-1] then hb2 else double.nan;
def chb3 = if block3 and hb3 == hb3[-1] then hb3 else double.nan;
AddCloud(chb1, lb1, color.light_green);
AddCloud(chb2, lb2, color.white);
AddCloud(chb3, lb3, color.yellow);
# Plot yesterday's data
def hb2_1 = if daynumber == 1 then double.nan else if firstbar then highb1[1] else hb2_1[1];
def lb2_1 = if daynumber == 1 then double.nan else if firstbar then lowb1[1] else lb2_1[1];
def hb2_2 = if daynumber ==1 then double.nan else if firstbar then highb2[1] else hb2_2[1];
def lb2_2 = if daynumber == 1 then double.nan else if firstbar then lowb2[1] else lb2_2[1];
def hb2_3 = if daynumber ==1 then double.nan else if firstbar then highb3[1] else hb2_3[1];
def lb2_3 = if daynumber == 1 then double.nan else if firstbar then lowb3[1] else lb2_3[1];
plot l1 = hb2_1;
plot l2 = lb2_1;
plot l3 = hb2_2;
plot l4 = lb2_2;
plot l5 = hb2_3;
plot l6 = lb2_3;
l1.setdefaultColor(color.light_gray);
l2.setdefaultcolor(color.light_gray);
l3.setdefaultcolor(color.light_gray);
l4.setdefaultcolor(color.light_gray);
l5.setdefaultcolor(color.light_gray);
l6.setdefaultcolor(color.light_gray);
l1.setpaintingStrategy(paintingStrategy.HORIZONTAL);
l2.setpaintingStrategy(paintingStrategy.HORIZONTAL);
l3.setpaintingStrategy(paintingStrategy.HORIZONTAL);
l4.setpaintingStrategy(paintingStrategy.HORIZONTAL);
l5.setpaintingStrategy(paintingStrategy.HORIZONTAL);
l6.setpaintingStrategy(paintingStrategy.HORIZONTAL);