jayy

volume 5 min smiley Jayy

65 0 3
This script plots volume . Intraday volume forms a smiley high at both ends and low in the middle at least for the cash session which is what this script concerns itself with. I created this as a curiosity but I figure others might be interested. If you are using 5 min charts then it will also plot the average for that particular time slot going back 10, 20 or 30 days and presents the mean for that bar as a black line. It also calculates the standard deviation over that period of time. Clearly the volume data is positively skewed so the mean and standard deviation are a little misleading. That aside it does provide a interesting perspective. The script likely could be reduced in size to accomplish the same thing with less tedium but it is what it is.
I likely will add an option for 15 minutes in the future.
If you are using BATS data you will find errors in low volume stocks because BATS data sometimes misses bars. The calculation relies on 78 5 min bars in a day (9:30 to 16:00 hrs). I built a little checker in the format. If the red line does not show at the beginning of the day then smiley will not work. For example SPY             works well but NUGT             does not. I have not found an issue will real time data.

There are a few options for bar colouring. They will be obvious when you play with them. current close versus last close, close versus open and volume relative to last bar.
Remove from Favorite Scripts Add to Favorite Scripts
study("volume 5 min smiley Jayy", overlay=false)
voldir= input(false, title="color vol based on previous bar close?")
voldird= input(true, title="color by vol increasing or decreasing ?")


//
//period is 5 mins?
highTimeFrame = input("D", type=resolution)
sessSpec = input("0930-1600", type=session, title="session for test of bars")
test=input(false, title=" Test for missing bars BATs data")
lb=input(20, title= "lookback period choose 5, 10, 20 or 30 only")
shosma=input(false, title=" show moving exp average of volume")
leng=input(5, title= "period of ema")


vlb= lb==5?sm78[390]:lb==10?sm78[780]:lb==20?sm78[1560]:lb==30?sm78[2340]:na

countr= nz(countr[1])==78?1:nz(countr[1])+1 
is_newbar(res, sess) =>
   t = time(res, sess)
//     change(t) != 0 ? 1 : 0
newbart = is_newbar(highTimeFrame, sessSpec)

m78= newbart ? volume :0// nz(sm[1])
zero= m78[0]==0?true:false
rtota78= zero and countr!=1?nz(rtota78[78]):m78[0]>0?(m78[0]+nz(rtota78[78])-nz(m78[1560])):zero and countr==1?nz(m78[78]):na 
ravge= nz(rtota78[0])/10
plot(period=="5"?ravge:na, color=test and countr==1?red:na, style=histogram, linewidth=3)


count= nz(count[1])==78?1:nz(count[1])+1 
is_newbar78(res78, sess78) =>
    t78 = time(res78, sess78)

    
//newbar78 = is_newbar78(highTimeFrame, sessSpec) 
newbar78 = count== 1?is_newbar78(highTimeFrame, "0930-1600"):count==2?is_newbar78(highTimeFrame, "0935-1600"):
    count==3?is_newbar78(highTimeFrame, "0940-1600"):count==4?is_newbar78(highTimeFrame, "0945-1600"):
    count==5?is_newbar78(highTimeFrame, "0950-1600"):count==6?is_newbar78(highTimeFrame, "0955-1600"):
    count==7?is_newbar78(highTimeFrame, "1000-1600"):count==8?is_newbar78(highTimeFrame, "1005-1600"):
    count==9?is_newbar78(highTimeFrame, "1010-1600"):count==10?is_newbar78(highTimeFrame, "1015-1600"):
    count==11?is_newbar78(highTimeFrame, "1020-1600"):count==12?is_newbar78(highTimeFrame, "1025-1600"):
    count==13?is_newbar78(highTimeFrame, "1030-1600"):count==14?is_newbar78(highTimeFrame, "1035-1600"):
    count==15?is_newbar78(highTimeFrame, "1040-1600"):count==16?is_newbar78(highTimeFrame, "1045-1600"):
    count==17?is_newbar78(highTimeFrame, "1050-1600"):count==18?is_newbar78(highTimeFrame, "1055-1600"):
    count==19?is_newbar78(highTimeFrame, "1100-1600"):count==20?is_newbar78(highTimeFrame, "1105-1600"):
    count==21?is_newbar78(highTimeFrame, "1110-1600"):count==22?is_newbar78(highTimeFrame, "1115-1600"):
    count==23?is_newbar78(highTimeFrame, "1120-1600"):count==24?is_newbar78(highTimeFrame, "1125-1600"):
    count==25?is_newbar78(highTimeFrame, "1130-1600"):count==26?is_newbar78(highTimeFrame, "1135-1600"):
    count==27?is_newbar78(highTimeFrame, "1140-1600"):count==28?is_newbar78(highTimeFrame, "1145-1600"):
    count==29?is_newbar78(highTimeFrame, "1150-1600"):count==30?is_newbar78(highTimeFrame, "1155-1600"):
    count==31?is_newbar78(highTimeFrame, "1200-1600"):count==32?is_newbar78(highTimeFrame, "1205-1600"):
    count==33?is_newbar78(highTimeFrame, "1210-1600"):count==34?is_newbar78(highTimeFrame, "1215-1600"):
    count==35?is_newbar78(highTimeFrame, "1220-1600"):count==36?is_newbar78(highTimeFrame, "1225-1600"):
    count==37?is_newbar78(highTimeFrame, "1230-1600"):count==38?is_newbar78(highTimeFrame, "1235-1600"):
    count==39?is_newbar78(highTimeFrame, "1240-1600"):count==40?is_newbar78(highTimeFrame, "1245-1600"):
    count==41?is_newbar78(highTimeFrame, "1250-1600"):count==42?is_newbar78(highTimeFrame, "1255-1600"):
    count==43?is_newbar78(highTimeFrame, "1300-1600"):count==44?is_newbar78(highTimeFrame, "1305-1600"):
    count==45?is_newbar78(highTimeFrame, "1310-1600"):count==46?is_newbar78(highTimeFrame, "1315-1600"):
    count==47?is_newbar78(highTimeFrame, "1320-1600"):count==48?is_newbar78(highTimeFrame, "1325-1600"):
    count==49?is_newbar78(highTimeFrame, "1330-1600"):count==50?is_newbar78(highTimeFrame, "1335-1600"):
    count==51?is_newbar78(highTimeFrame, "1340-1600"):count==52?is_newbar78(highTimeFrame, "1345-1600"):
    count==53?is_newbar78(highTimeFrame, "1350-1600"):count==54?is_newbar78(highTimeFrame, "1355-1600"):
    count==55?is_newbar78(highTimeFrame, "1400-1600"):count==56?is_newbar78(highTimeFrame, "1405-1600"):
    count==57?is_newbar78(highTimeFrame, "1410-1600"):count==58?is_newbar78(highTimeFrame, "1415-1600"):
    count==59?is_newbar78(highTimeFrame, "1420-1600"):count==60?is_newbar78(highTimeFrame, "1425-1600"):
    count==61?is_newbar78(highTimeFrame, "1430-1600"):count==62?is_newbar78(highTimeFrame, "1435-1600"):
    count==63?is_newbar78(highTimeFrame, "1440-1600"):count==64?is_newbar78(highTimeFrame, "1445-1600"):
    count==65?is_newbar78(highTimeFrame, "1450-1600"):count==66?is_newbar78(highTimeFrame, "1455-1600"):
    count==67?is_newbar78(highTimeFrame, "1500-1600"):count==68?is_newbar78(highTimeFrame, "1505-1600"):
    count==69?is_newbar78(highTimeFrame, "1510-1600"):count==70?is_newbar78(highTimeFrame, "1515-1600"):
    count==71?is_newbar78(highTimeFrame, "1520-1600"):count==72?is_newbar78(highTimeFrame, "1525-1600"):
    count==73?is_newbar78(highTimeFrame, "1530-1600"):count==74?is_newbar78(highTimeFrame, "1535-1600"):
    count==75?is_newbar78(highTimeFrame, "1540-1600"):count==76?is_newbar78(highTimeFrame, "1545-1600"):
    count==77?is_newbar78(highTimeFrame, "1550-1600"):count==78?is_newbar78(highTimeFrame, "1555-1600"):na
   


sm78= newbar78 ? volume :0// nz(sm[1])

zero78= sm78[0]==0?true:false
rtot78= zero78 and count!=1?nz(rtot78[78]):sm78[0]>0?(sm78[0]+nz(rtot78[78])-nz(sm78[1560])):zero78 and count==1?nz(sm78[78]):na 

ravgr78= nz(rtot78[0])/20
//nz(ravg78[0]) + 
ravg78= sm78==0?nz(ravg78[78]):volume
ravg20= lb==5?(nz(ravg78[0]) + nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
     nz(ravg78[312]))/5:
    
     lb==10? (nz(ravg78[0]) + nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
     nz(ravg78[312]) + nz(ravg78[390]) + nz(ravg78[468]) + nz(ravg78[546])+ nz(ravg78[624])
    + nz(ravg78[702]))/10:
    
    lb==20?(nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
     nz(ravg78[312]) + nz(ravg78[390]) + nz(ravg78[468]) + nz(ravg78[546])+
     nz(ravg78[624]) + nz(ravg78[702]) + nz(ravg78[780]) + nz(ravg78[858])+
     nz(ravg78[936]) + nz(ravg78[1014]) + nz(ravg78[1092]) + nz(ravg78[1170])+
     nz(ravg78[1248]) + nz(ravg78[1326]) + nz(ravg78[1404]) + nz(ravg78[1482] + nz(sm78[1560])))/20:
    
    lb==30?(nz(ravg78[0]) + nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
     nz(ravg78[312]) + nz(ravg78[390]) +   nz(ravg78[468]) +  nz(ravg78[546])+
     nz(ravg78[624]) + nz(ravg78[702]) +   nz(ravg78[780]) +  nz(ravg78[858])+
     nz(ravg78[936]) + nz(ravg78[1014]) +  nz(ravg78[1092]) + nz(ravg78[1170])+
     nz(ravg78[1248]) + nz(ravg78[1326]) + nz(ravg78[1404]) + nz(ravg78[1482])+
    nz(ravg78[1560]) + nz(ravg78[1638]) + nz(ravg78[1716]) + nz(ravg78[1794])+
    nz(ravg78[1872]) + nz(ravg78[1950]) + nz(ravg78[2028]) + nz(ravg78[2106])+
     nz(ravg78[2184]) + nz(ravg78[2262]))/30:na
rav= lb==5?(nz(ravg78[0]) + nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
    nz(ravg78[312]))/5:
    
    lb==10? (nz(ravg78[0]) + nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
    nz(ravg78[312]) + nz(ravg78[390]) + nz(ravg78[468]) + nz(ravg78[546])+ nz(ravg78[624])
    + nz(ravg78[702]))/10:
    
    lb==20?(nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
    nz(ravg78[312]) + nz(ravg78[390]) + nz(ravg78[468]) + nz(ravg78[546])+
    nz(ravg78[624]) + nz(ravg78[702]) + nz(ravg78[780]) + nz(ravg78[858])+
    nz(ravg78[936]) + nz(ravg78[1014]) + nz(ravg78[1092]) + nz(ravg78[1170])+
    nz(ravg78[1248]) + nz(ravg78[1326]) + nz(ravg78[1404]) + nz(ravg78[1482] + nz(sm78[1560])))/20:
    
    lb==30?(nz(ravg78[0]) + nz(ravg78[78]) + nz(ravg78[156]) + nz(ravg78[234])+
    nz(ravg78[312]) + nz(ravg78[390]) +   nz(ravg78[468]) +  nz(ravg78[546])+
    nz(ravg78[624]) + nz(ravg78[702]) +   nz(ravg78[780]) +  nz(ravg78[858])+
    nz(ravg78[936]) + nz(ravg78[1014]) +  nz(ravg78[1092]) + nz(ravg78[1170])+
    nz(ravg78[1248]) + nz(ravg78[1326]) + nz(ravg78[1404]) + nz(ravg78[1482])+
	nz(ravg78[1560]) + nz(ravg78[1638]) + nz(ravg78[1716]) + nz(ravg78[1794])+
    nz(ravg78[1872]) + nz(ravg78[1950]) + nz(ravg78[2028]) + nz(ravg78[2106])+
    nz(ravg78[2184]) + nz(ravg78[2262]))/30:na

ravgsd= lb==5? sqrt((pow(nz(ravg78[0])- rav,2) + pow(nz(ravg78[78]) - nz(rav),2) + pow(nz(ravg78[156])-
     nz(rav),2) + pow(nz(ravg78[234]) - nz(rav),2) + pow(nz(ravg78[312])  -nz(rav),2))/5):
    
    lb==10? sqrt((pow(nz(ravg78[0]) -nz(rav),2) + pow(nz(ravg78[78]) -nz(rav),2) + pow(nz(ravg78[156])
    -nz(rav),2) + pow(nz(ravg78[234]) -nz(rav),2) +
    pow(nz(ravg78[312]) -nz(rav),2) + pow(nz(ravg78[390]) -nz(rav),2) + pow(nz(ravg78[468]) -nz(rav),2)
    + pow(nz(ravg78[546])-nz(rav),2) + pow(nz(ravg78[624])-nz(rav),2) + pow(nz(ravg78[702])-nz(rav),2) + pow(nz(ravg78[1482]) -nz(rav),2))/10):
    
    lb==20? sqrt((
    pow(nz(ravg78[0])    -nz(rav),2) + pow(nz(ravg78[78])   -nz(rav),2) + pow(nz(ravg78[156])  -nz(rav),2) + pow(nz(ravg78[234])  -nz(rav),2) +
    pow(nz(ravg78[312]) -nz(rav),2) + pow(nz(ravg78[390])  -nz(rav),2) + pow(nz(ravg78[468])  -nz(rav),2) + pow(nz(ravg78[546])  -nz(rav),2) +
    pow(nz(ravg78[624]) -nz(rav),2) + pow(nz(ravg78[702])  -nz(rav),2) + pow(nz(ravg78[780])  -nz(rav),2) + pow(nz(ravg78[858])  -nz(rav),2) +
    pow(nz(ravg78[936]) -nz(rav),2) + pow(nz(ravg78[1014]) -nz(rav),2) + pow(nz(ravg78[1092]) -nz(rav),2) + pow(nz(ravg78[1170]) -nz(rav),2) +
    pow(nz(ravg78[1248])-nz(rav),2) + pow(nz(ravg78[1326]) -nz(rav),2) + pow(nz(ravg78[1404]) -nz(rav),2) + pow(nz(ravg78[1482]) -nz(rav),2))/20):
    
    lb==30? sqrt((
    pow(nz(ravg78[0]) -nz(rav),2)  + pow(nz(ravg78[78]) -nz(rav),2) + pow(nz(ravg78[156]) -nz(rav),2) + 
    pow(nz(ravg78[234]) -nz(rav),2) +
    pow(nz(ravg78[312]) -nz(rav),2)  + pow(nz(ravg78[390])  -nz(rav),2) + pow(nz(ravg78[468]) -nz(rav),2) +  pow(nz(ravg78[546])  -nz(rav),2) +
    pow(nz(ravg78[624]) -nz(rav),2)  + pow(nz(ravg78[702])  -nz(rav),2) + pow(nz(ravg78[780]) -nz(rav),2) +  pow(nz(ravg78[858])  -nz(rav),2) +
    pow(nz(ravg78[936]) -nz(rav),2)  + pow(nz(ravg78[1014]) -nz(rav),2) + pow(nz(ravg78[1092]) -nz(rav),2) + pow(nz(ravg78[1170]) -nz(rav),2) +
    pow(nz(ravg78[1248]) -nz(rav),2) + pow(nz(ravg78[1326]) -nz(rav),2) + pow(nz(ravg78[1404]) -nz(rav),2) + pow(nz(ravg78[1482]) -nz(rav),2) +
	pow(nz(ravg78[1560]) -nz(rav),2) + pow(nz(ravg78[1638]) -nz(rav),2) + pow(nz(ravg78[1716]) -nz(rav),2) + pow(nz(ravg78[1794]) -nz(rav),2) +
    pow(nz(ravg78[1872]) -nz(rav),2) + pow(nz(ravg78[1950]) -nz(rav),2) + pow(nz(ravg78[2028]) -nz(rav),2) +
    pow(nz(ravg78[2106]) -nz(rav),2) + pow(nz(ravg78[2184]) -nz(rav),2) + pow(nz(ravg78[2262]) -nz(rav),2))/30):na



sdtot78= zero78 and count!=1?nz(sdtot78[78]):nz(sm78[0])>0?(pow((nz(sm78[0]))- ravg20,2) + nz(sdtot78[78]))
    -pow(nz(vlb)-ravg20,2):zero78 and count==1?(pow(sm78[78]-ravg20,2) + nz(sdtot78[78]))
    -pow(nz(vlb)-ravg20,2) :na
    
  
sd78= sqrt(sdtot78/20)

ht=  close - close[1] 
plotvolup= abs(ht)


plot(period=="5"?rav:na, color=test?na:period=="5"?black:na, linewidth=2, style=histogram, transp=0) //sdtot78
////plot(sdtot78, color=sdtot78<0?black:red, linewidth=2, style=circles, transp=0) //sdtot78
plot(period=="5"?rav+ravgsd:na, color=test?na:period=="5"?black:na, linewidth=1, style=cross, transp=100)
//colorr= voldir
plot(test or voldird==true?na:volume, style=columns, color=voldir==true and close>=open? green:voldir==true and close<open? red:
    voldir==false and close[0]>=close[1]? green:voldir==false and close[0]<close[1]? red:na,transp=50)//test?na:
    
plot(test or voldird==false?na:volume, style=columns, color=voldird==true and volume[0]>=volume[1]? 
    green:voldird==true and volume[1]>=volume[0]? red:na,transp=50)//test?na:   
plot(shosma or test?ema(ravg78, leng):na, color=test?na:blue)
Jayy
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out