# Cumulative Delta for each day

#### Max911

##### Member
Plot CVD = TotalSum(volume*(close-low)/(high-low))-(volume*(high-close)/(high-low));

Hi, when I plot this Cumulative Delta on a 10d 5m chart, I get the Total Sum of the 10 days. Instead of the TotalSum of full chart (eg 10d 5m), I need the TotalSum for each day. If I have to run a backtest, I don't want the TotalSum of the entire chart. I need the right signals for each day.

What should I add in the script so that it only accumulates each day separately even though I use a 10-day chart? How can i get this cumulative delta for each regular trading day? Maybe using aggregation.period, I don't know. Thx.

#### halcyonguy

##### Well-known member
VIP
Plot CVD = TotalSum(volume*(close-low)/(high-low))-(volume*(high-close)/(high-low));

Hi, when I plot this Cumulative Delta on a 10d 5m chart, I get the Total Sum of the 10 days. Instead of the TotalSum of full chart (eg 10d 5m), I need the TotalSum for each day. If I have to run a backtest, I don't want the TotalSum of the entire chart. I need the right signals for each day.

What should I add in the script so that it only accumulates each day separately even though I use a 10-day chart? How can i get this cumulative delta for each regular trading day? Maybe using aggregation.period, I don't know. Thx.

totalsum() , returns the sum of all values from the first bar to the current.
so this isn't the correct function to do what you want.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/TotalSum

if you want a count to reset each day, then you need a way to determine when a new day starts.
this is one way,

Code:
``````declare lower;
def diffday = GetDay() <> GetDay()[1];

def x = (volume*(close-low)/(high-low))-(volume*(high-close)/(high-low));

def y = if diffday then x
else x + y[1];

Plot CVD = y;``````

-------------------------------------

here is another version, that draws a new line each day. it looks at a day counter and plots a line, depending of if day count is even or not.

Code:
``````declare lower;
def bn = barnumber();
def na = double.nan;

def diffday = GetDay() <> GetDay()[1];
def daycnt = if bn == 1 then 1 else if diffday then daycnt[1] + 1 else daycnt[1];
def dayeven = (daycnt % 2) == 0;

def x = (volume*(close-low)/(high-low))-(volume*(high-close)/(high-low));
def y = if diffday then x
else x + y[1];

Plot CVD1 = if dayeven then y else na;
Plot CVD2 = if !dayeven then y else na;``````

Last edited:

##### Member
is it error here?

def x = volume*(close-low)/(high-low))-(volume*(high-close)/(high-low));

#### halcyonguy

##### Well-known member
VIP
is it error here?

def x = volume*(close-low)/(high-low))-(volume*(high-close)/(high-low));

try again
i forgot a a ( and fixed it

## 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?