# \$ Volume & 20day avg \$ Column

#### axlerod

##### Member
Hello,
Having a silly mental block today just can't understand if it's cuz i haven't slept in 2 days lol but need some help.

I have a custom column I am trying to do. 2 Custom Columns OUTPUT and \$ Dollar Volume

1. Volume Converted To \$ Dollar Volume Traded

EXAMPLE
CCTL 1d \$ Volume on 8/11 was \$1,224,723 and the volume was 365,589,039

I am trying to convert the VOLUME into \$ Volume on 1D time frame and can't get it to match I'm off by a few hundred.

Code:
``````plot DollarVolume = hl2 * Volume;

#also it's missing the , (commas) cuz it's showing the full 9 digits but without commas as I read on ThinkScript I can do AsDollars to make it have commas but didn't work.``````

2. OUTPUT
THEN I am trying to get this formula to match this equation. Todays \$ Volume / (divided) by the 20 day average \$ Dollar Volume.

EXAMPLE:
Output on 8/11 should be 9 but im getting something different. (Basically stating that on 8/11 the \$ Volume Traded TODAY was 9x greater than the 20day average)

Code:
``````def days20dollarvol = Average(volume, 20)*hl2;

def todaydollarvol = hl2 * volume;

plot output = todaydollarvol / days20dollarvol;``````

PREVIOUS 20 Days Data - I TYPED UP all the data for the Volume, \$ Volume and Output that it SHOULD BE when converted to the columns but it isn't working when I coded it in the columns. Google Sheets - https://docs.google.com/spreadsheets/d/1eC1kyAd0uCCaIBJReLLygPi3cRjG1jY5WtO3_asvNXc/edit?usp=sharing

If anyone can help me with this mental block that be great! Thank you god bless and hope everyone is safe and healthy!

Last edited:

#### SuryaKiranC

##### Well-known member
@axlerod Try the following code in your custom column and let me know. Please note, my values is 30, you can change this to what you need.

Code:
``````# DollarTraded
# Version 0.1
# Created: 08/12/2020
# Created by: Surya Kiran C #

def length = 30;
def VolDayAvg = Average(volume(period = "DAY")[1], length);
def DollarVolume = hl2 * Volume(period = "DAY");
def DaysDollarVol = VolDayAvg * hl2;

#### axlerod

##### Member
So i tried that for 20 day and got 66k but it should be 18k rounded.

I typed it out long handed lol idk if easier way to type it up but take a look let me know.

Code:
``````# def avg20dayss = Average(hl2 * volume, 5);
def avg20days=
(

hl2 [1]* volume[1]
[LIST]
[*]hl2 [2]* volume[2]
[*]hl2 [3]* volume[3]
[*]hl2 [4]* volume[4]
[*]hl2 [5]* volume[5]
[*]hl2 [6]* volume[6]
[*]hl2 [7]* volume[7]
[*]hl2 [8]* volume[8]
[*]hl2 [9]* volume[9]
[*]hl2 [10]* volume[10]
[*]hl2 [11]* volume[11]
[*]hl2 [12]* volume[12]
[*]hl2 [13]* volume[13]
[*]hl2 [14]* volume[14]
[*]hl2 [15]* volume[15]
[*]hl2 [16]* volume[16]
[*]hl2 [17]* volume[17]
[*]hl2 [18]* volume[18]
[*]hl2 [19]* volume[19]
[*]hl2 [20]* volume[20]
[/LIST]

# + hl2 [21]* volume[21]
)

/ 20;

#### SuryaKiranC

##### Well-known member
Well, this answers Part 2, the following should cover the first part, unless I misunderstood your requirement.

Code:
``````def DollarVolume = hl2 * Volume(period = "DAY");

Just that they need to be in their own columns.

#### SuryaKiranC

##### Well-known member
you have a screenshot of what you are looking at? @axlerod

#### SuryaKiranC

##### Well-known member
Also give me a ticker you are looking at, probably a low volume ticker, so easier for calculations.

-Surya

#### axlerod

##### Member
Also give me a ticker you are looking at, probably a low volume ticker, so easier for calculations.

-Surya
So I got it working but 1 last step i am struggling with haha

This is for the Column Called TODAYS \$ VOL

Trying to get this label to be 0 as right now it's showing yesterdays Daily Candle \$ Volume.

I wanna have it show up until 9:30am and then once 9:30am hits it resets to 0

input OpenTime = 0930;
input DurationHours = 1;

def durationSec = DurationHours * 60 * 60;
def secondsPassed = SecondsFromTime(OpenTime);

plot Price = if secondsPassed >= 0 and secondsPassed <= durationSec then close else double.NaN;

But trying to get it to integrate with my add label...lmk what you can do.

Code:
``````def DollarVolume = round(hl2 * volume);

AddLabel (yes, "\$" + DollarVolume, if DollarVolume >= (1000000) then Color.CYAN else if DollarVolume >= (500000) then color.green  else if DollarVolume >= (100000) then color.yellow else color.white);``````

#### wesam

##### New member
So I got it working but 1 last step i am struggling with haha

This is for the Column Called TODAYS \$ VOL

Trying to get this label to be 0 as right now it's showing yesterdays Daily Candle \$ Volume.

I wanna have it show up until 9:30am and then once 9:30am hits it resets to 0

input OpenTime = 0930;
input DurationHours = 1;

def durationSec = DurationHours * 60 * 60;
def secondsPassed = SecondsFromTime(OpenTime);

plot Price = if secondsPassed >= 0 and secondsPassed <= durationSec then close else double.NaN;

But trying to get it to integrate with my add label...lmk what you can do.

Code:
``````def DollarVolume = round(hl2 * volume);

AddLabel (yes, "\$" + DollarVolume, if DollarVolume >= (1000000) then Color.CYAN else if DollarVolume >= (500000) then color.green  else if DollarVolume >= (100000) then color.yellow else color.white);``````

hi did you end up having the scanner work, if so may you share @axlerod

Last edited:

#### Pumper

##### New member
Probably a really simple question, but I'm not sure how to code this.

That's a few tickers from my scanner.. How do I have a section for the \$ Volume (which is in millions) divided by the market cap (which is also in millions)

##### Well-known member
VIP
@Pumper Reposting won't get you an answer any faster... I saw your initial post last night but you didn't provide any of your code so I didn't bother answering... You already know that you want to do division... Just add another Custom Watchlist Column and do the math... Or post the code you already have there... Did you do the initial coding...???

#### Pumper

##### New member
@Pumper Reposting won't get you an answer any faster... I saw your initial post last night but you didn't provide any of your code so I didn't bother answering... You already know that you want to do division... Just add another Custom Watchlist Column and do the math... Or post the code you already have there... Did you do the initial coding...???
Here is coding that I borrowed from youtube

Code:
``plot DollarVolume = Round("number" = (hl2 * volume / 1000000), "numberOfDigits" = 1);``

Can you help me out brother?

Last edited: