# Net Dollar Volume

#### James2020

##### New member
Hi, I'm trying to track the net dollar volume of the previous 10 mins. The issue I'm running into is how to code it properly in ThinkScript. Does anyone know where I can find a code for this or how write the proper one?

Solution
@James2020 test this and verify that the output is what you want. This is aggregation-sensitive - meaning, it uses the last "x" amount of candles based on your user input. Currently, it is set to use the last 10 bars, so to see the net dollar volume of the last 10 mins you must use a 1 minute chart. Alternatively, you could change the input to "2" and use a 5 min chart.

I didn't include candles where the open is equal to the close. If you want that added to either the buying or selling dollar volume, specify which one you want it added to. Otherwise, it ignores those candles.

Code:
``````input barsback = 10;
def x = isnan(close[-barsback]);
def dv = close * volume;

addlabel(1,"net dv of past " + barsback + " bars",color.gray);

def bdv...``````
Thats the formula for Dollar Volume which is part of it but I'm confused how the code needs to be tweaked to represent the "Net" Dollar Volume over a 10 minute period
@James2020 I'm sorry, I don't understand. What do you mean by "Net"?

As long you don't use MTF aggregations, it will show the dollar volume traded during each individual price bar, be it the 1 min, 5 min, 10 min, 30 min, 1 hr, etc. charts.

Are you trading the 1 min chart but want to know the total dollar volume of the past 10 mins?

As long you don't use MTF aggregations, it will show the dollar volume traded during each individual price bar, be it the 1 min, 5 min, 10 min, 30 min, 1 hr, etc. charts.

Are you trading the 1 min chart but want to know the total dollar volume of the past 10 mins?
So a better way of explaining it may be like this....I would like to take a 10 min period of time and have the code add the dollar volume for the green candles, then add the dollar volume for the red candles, then subtract the red ones from the green ones for that time period. What I don't know is what ThinkScript uses for representing green and red candles in their coding.

@James2020 Green candles can be obtained by using `def green = close > open;` and red candles can be found using `def red = close < open;`. I'll see what I can do and will get back to you on this.

@James2020 test this and verify that the output is what you want. This is aggregation-sensitive - meaning, it uses the last "x" amount of candles based on your user input. Currently, it is set to use the last 10 bars, so to see the net dollar volume of the last 10 mins you must use a 1 minute chart. Alternatively, you could change the input to "2" and use a 5 min chart.

I didn't include candles where the open is equal to the close. If you want that added to either the buying or selling dollar volume, specify which one you want it added to. Otherwise, it ignores those candles.

Code:
``````input barsback = 10;
def x = isnan(close[-barsback]);
def dv = close * volume;

addlabel(1,"net dv of past " + barsback + " bars",color.gray);

def bdv = if x and close > open then bdv[1] + dv else bdv[1];

def sdv = if x and close < open then sdv[1] + dv else sdv[1];
addlabel(1,"selling dv = " + sdv,color.red);

def net = bdv - sdv;
addlabel(1,"net dv = " + net,color.cyan);``````

87k+ Posts
322 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?