#### traderintheroom

##### Member

I am using the ThinkScript VolumeAvg ("length" = 60) . "volavg"

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter traderintheroom
- Start date

I am using the ThinkScript VolumeAvg ("length" = 60) . "volavg"

Use this instead.

Ruby:

```
def avgVol = Average(volume, 60);
AddLabel(yes, Round(avgVol, 0));
```

I am trying to code an info box to convert average daily volume into a Tick count for tick charts. I am not well versed in coding or thinkscript.

Basically, if the volLast30DayAvg meets a certaincriteria, then it will show one of the calculations A through F in the Tick Counter Box on my chart. Any tips? Thanks.

Code:

```
plot Data = close;
declare lower;
input TickCounter = yes;
#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
# Variables:
def a;
def b;
def c;
def d;
def e;
def f;
# Calculations
a = 144;
b = 333;
c = 800;
d = 1600;
e = 3200;
f = 10000;
def SHowTickNumber = if VolLast30DayAvg < 5000000 then plot a;
AddLabel (TickCounter, "TICK: " + ShowTickNumber);
```

I am having some trouble displaying a watchlist item (5min volume % based on a 30 day avg) that is displayed in a chart but not in the watchlist.

In summary, I am looking to display the 5 min volume total as a percentage of the 30 day volume average.

This is basically a guide to highlight how much volume has been traded in the current 5 min window compared to a 30 day average.

Any thoughts what can be done to see the plot (5min vol / 30day vol)?

plot percentofMinVol = Round((currentMinVolNow / volLast30DayAvg) * 100, 0);

Visual of the item requested (see yellow arrow):

Watchlist code (note the plot item)

In summary, I am looking to display the 5 min volume total as a percentage of the 30 day volume average.

This is basically a guide to highlight how much volume has been traded in the current 5 min window compared to a 30 day average.

Any thoughts what can be done to see the plot (5min vol / 30day vol)?

plot percentofMinVol = Round((currentMinVolNow / volLast30DayAvg) * 100, 0);

Visual of the item requested (see yellow arrow):

Watchlist code (note the plot item)

Code:

```
# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17
declare lower;
#Inputs WORKING PRIOR WITH 5min%Avg
input Show30DayAvg = no;
input ShowTodayVolume = no;
input ShowPercentOf30DayAvg = no;
input UnusualVolumePercent = 200;
input Show30BarAvg = no;
input Show10BarAvg = no;
input ShowCurrentBar = no;
input ShowCurrent3MinVBar = no;
input ShowCurrentMinVBar = yes;
#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def currentMinVolNow = volume(period = "5 MIN");
plot percentofMinVol = Round((currentMinVolNow / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
#def avg10Bars = VolumeAvg(10).VolAvg;
def avg10Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10]) / 10;
def curVolume = volume;
# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if curVolume >= avg30Bars then Color.GREEN else Color.ORANGE));
AddLabel(ShowCurrentMinVBar, + percentofMinVol + "%", (if percentofMinVol >= UnusualVolumePercent then Color.GREEN else if percentofMinVol >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show10BarAvg, "Avg 10 Bars: " + Round(avg10Bars, 0), Color.LIGHT_GRAY);
```

Last edited:

Code:

```
# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17
declare lower;
#Inputs WORKING PRIOR WITH 5min%Avg
input ShowPercentOf30DayAvg = no;
input UnusualVolumePercent = 200;
input ShowCurrent3MinVBar = no;
input ShowCurrentMinVBar = yes;
#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def currentMinVolNow = volume(period = "5 MIN");
plot percentofMinVol = Round((currentMinVolNow / volLast30DayAvg) * 100, 0);
def curVolume = volume;
```

Well, I found out that TOS does not support Daily and intraday calculations within the watchlist and that the intraday time frame only allows 5-6 days worth of data.

I then removed the 30 day avg reference and expanded what I could of the available intraday data until TOS was giving me errors inside the watchlist area (I then knew how much data a 5 min period could hold)

The key take away from this is if you want something bad enough, you kind of have to stick with it long enough to make it work.

Ideally, this watchlist column would capture 30 days average volume and compare against the current 5 min period but that is not possible in TOS. I did what I could based on the limitations of the system.

This is basically taking 120 periods of data on a 5 min period starting from 141 period ago and comparing the most recent period against that average to compute a figure which gives a relative sign of strength (or lack there of) based on the current 5 min volume bar.

If anyone can use the code, feel free to use it.

Thank you for reading.

I then removed the 30 day avg reference and expanded what I could of the available intraday data until TOS was giving me errors inside the watchlist area (I then knew how much data a 5 min period could hold)

The key take away from this is if you want something bad enough, you kind of have to stick with it long enough to make it work.

Ideally, this watchlist column would capture 30 days average volume and compare against the current 5 min period but that is not possible in TOS. I did what I could based on the limitations of the system.

This is basically taking 120 periods of data on a 5 min period starting from 141 period ago and comparing the most recent period against that average to compute a figure which gives a relative sign of strength (or lack there of) based on the current 5 min volume bar.

If anyone can use the code, feel free to use it.

Thank you for reading.

Code:

```
# Box Volume Stats
# Version 1.0
# Created by: PerseveranceTrading
# Created: 12/9/20
declare lower;
#Inputs WORKING PRIOR WITH 5min%Avg
input ShowCurrentMinVBar = yes;
#Volume Data
def volLast3DayAvg = (volume(period = "5 MIN")[141] + volume(period = "5 MIN")[142] + volume(period = “5 MIN”)[143] + volume(period = “5 MIN”)[144] + volume(period = “5 MIN”)[145] + volume(period = “5 MIN”)[146] + volume(period = “5 MIN”)[147] + volume(period = “5 MIN”)[148] + volume(period = “5 MIN”)[149] + volume(period = “5 MIN”)[150] + volume(period = “5 MIN”)[151] + volume(period = “5 MIN”) [152] + volume(period = “5 MIN”)[153] + volume(period = “5 MIN”)[154] + volume(period = “5 MIN”)[155] + volume(period = “5 MIN”)[156] + volume(period = “5 MIN”)[157] + volume(period = “5 MIN”)[158] + volume(period = “5 MIN”)[159] + volume(period = “5 MIN”)[160] + volume(period = “5 MIN”)[161] + volume(period = “5 MIN”)[162] + volume(period = “5 MIN”)[163] + volume(period = “5 MIN”)[164] + volume(period = “5 MIN”)[165] + volume(period = “5 MIN”)[166] + volume(period = “5 MIN”)[167] + volume(period = “5 MIN”)[168] + volume(period = “5 MIN”)[169] + volume(period = “5 MIN”)[170] + volume(period = "5 MIN")[171] + volume(period = "5 MIN")[172] + volume(period = “5 MIN”)[173] + volume(period = “5 MIN”)[174] + volume(period = “5 MIN”)[175] + volume(period = “5 MIN”)[176] + volume(period = “5 MIN”)[177] + volume(period = “5 MIN”)[178] + volume(period = “5 MIN”)[179] + volume(period = “5 MIN”)[180] + volume(period = “5 MIN”)[181] + volume(period = “5 MIN”)[182] + volume(period = “5 MIN”)[183] + volume(period = “5 MIN”)[184] + volume(period = “5 MIN”)[185] + volume(period = “5 MIN”)[186] + volume(period = “5 MIN”)[187] + volume(period = “5 MIN”)[188] + volume(period = “5 MIN”)[189] + volume(period = “5 MIN”)[190] + volume(period = “5 MIN”)[191] + volume(period = “5 MIN”)[192] + volume(period = “5 MIN”)[193] + volume(period = “5 MIN”)[194] + volume(period = “5 MIN”)[195] + volume(period = “5 MIN”)[196] + volume(period = “5 MIN”)[197] + volume(period = “5 MIN”)[198] + volume(period = “5 MIN”)[199] + volume(period = “5 MIN”)[200])+
(volume(period = "5 MIN")[201] + volume(period = "5 MIN")[202] + volume(period = “5 MIN”)[203] + volume(period = “5 MIN”)[204] + volume(period = “5 MIN”)[205] + volume(period = “5 MIN”)[206] + volume(period = “5 MIN”)[207] + volume(period = “5 MIN”)[208] + volume(period = “5 MIN”)[209] + volume(period = “5 MIN”)[210] + volume(period = “5 MIN”)[211] + volume(period = “5 MIN”)[212] + volume(period = “5 MIN”)[213] + volume(period = “5 MIN”)[214] + volume(period = “5 MIN”)[215] + volume(period = “5 MIN”)[216] + volume(period = “5 MIN”)[217] + volume(period = “5 MIN”)[218] + volume(period = “5 MIN”)[219] + volume(period = “5 MIN”)[220] + volume(period = “5 MIN”)[221] + volume(period = “5 MIN”)[222] + volume(period = “5 MIN”)[223] + volume(period = “5 MIN”)[224] + volume(period = “5 MIN”)[225] + volume(period = “5 MIN”)[226] + volume(period = “5 MIN”)[227] + volume(period = “5 MIN”)[228] + volume(period = “5 MIN”)[229] + volume(period = “5 MIN”)[230] + volume(period = "5 MIN")[231] + volume(period = "5 MIN")[232] + volume(period = “5 MIN”)[233] + volume(period = “5 MIN”)[234] + volume(period = “5 MIN”)[235] + volume(period = “5 MIN”)[236] + volume(period = “5 MIN”)[237] + volume(period = “5 MIN”)[238] + volume(period = “5 MIN”)[239] + volume(period = “5 MIN”)[240] + volume(period = “5 MIN”)[241] + volume(period = “5 MIN”)[242] + volume(period = “5 MIN”)[243] + volume(period = “5 MIN”)[244] + volume(period = “5 MIN”)[245] + volume(period = “5 MIN”)[246] + volume(period = “5 MIN”)[247] + volume(period = “5 MIN”)[248] + volume(period = “5 MIN”)[249] + volume(period = “5 MIN”)[250] + volume(period = “5 MIN”)[251] + volume(period = “5 MIN”)[252] + volume(period = “5 MIN”)[253] + volume(period = “5 MIN”)[254] + volume(period = “5 MIN”)[255] + volume(period = “5 MIN”)[256] + volume(period = “5 MIN”)[257] + volume(period = “5 MIN”)[258] + volume(period = “5 MIN”)[259] + volume(period = “5 MIN”)[260])/ 160;
def today = volume(period = “5 MIN”);
def currentMinVolNow = volume(period = "5 MIN");
plot percentofMinVol = Round((currentMinVolNow / volLast3DayAvg) * 100, 0);
def curVolume = volume;
```

Last edited:

So average 5m volume = (average daily volume /390)*5

What do you guys say?

Thanks for the reply Rogtrader. I believe the problem with watchlists in TOS, if I understand it correctly, is that in order to compute average daily volume in the watchlist, you need to manually gather the daily volume and TOS does not allow one to work with daily data and intraday data in the watchlist (this constraint is not enforced on the charts though). If you do use intraday data (like 5 min), you can only go back a few days. The solution that you present is along the lines of what I was asking for. To get around this limitation, the code above collects as much data as is allowed for the 5min period and compares the most current period against that limited dataset. For what I am doing, this does work as it helps show those tickers with high relative volume in real time.

So average 5m volume = (average daily volume /390)*5

What do you guys say?

Cheers!

Code:

```
# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17
# Improved 01/05/21
declare lower;
#Inputs WORKING PRIOR WITH 5min%Avg
input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = no;
input Show10BarAvg = no;
input ShowCurrentBar = yes;
input ShowCurrentMinVBar = yes;
input ShowCurrent15MinVBar = yes;
input ShowCurrent3MinVBar = yes;
#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def currentMinVolNow = volume(period = "5 MIN");
def current15MinVolNow = volume(period = "15 MIN");
def current3MinVolNow = volume(period = "3 MIN");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def percentofMinVol = Round((currentMinVolNow / volLast30DayAvg) * 100, 0);
def percentof15MinVol = Round((current15MinVolNow / volLast30DayAvg) * 100, 0);
def percentof3MinVol = Round((current3MinVolNow / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
#def avg10Bars = VolumeAvg(10).VolAvg;
def avg10Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10]) / 10;
def curVolume = volume;
# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if curVolume >= avg30Bars then Color.GREEN else Color.ORANGE));
AddLabel(ShowCurrent3MinVBar, "3min%Avg: " + percentof3MinVol + "%", (if percentof3MinVol >= UnusualVolumePercent then Color.GREEN else if percentof3MinVol >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowCurrentMinVBar, "5min%Avg: " + percentofMinVol + "%", (if percentofMinVol >= UnusualVolumePercent then Color.GREEN else if percentofMinVol >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowCurrent15MinVBar, "15min%Avg: " + percentof15MinVol + "%", (if percentof15MinVol >= UnusualVolumePercent then Color.GREEN else if percentof15MinVol >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show10BarAvg, "Avg 10 Bars: " + Round(avg10Bars, 0), Color.LIGHT_GRAY);
```

Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|

D | Average 30 daily Volume Scan Filter | Questions | 7 | |

A | 180 daily moving average volume code? | Questions | 4 | |

K | (ADR) Average daily range crossover | Questions | 0 | |

A | Daily moving average in intraday chart | Questions | 6 | |

D | Show average daily range of SPX | Questions | 2 |