# Adding up specific plot values during market hours

#### joekim1

##### New member
I'm trying to add up the values of an indicator when they reach a certain condition to have a total by the end of the day but can't get anything going with sum or compoundvalue. It's doing my head in.

For example, let's say I have an RSI indicator, and I want to add up its peak values only after it crosses below some number like 60. So my indicator would find the highest value between the time it crossed above 60 and crossed below 60. After the market closes, I want to add up all the highest values from the start of the day to the end, that met my condition.

My actual use case is more complicated than this but I'm hoping I can get some clues using this example. Would appreciate any help!

Solution
I'm trying to add up the values of an indicator when they reach a certain condition to have a total by the end of the day but can't get anything going with sum or compoundvalue. It's doing my head in.

For example, let's say I have an RSI indicator, and I want to add up its peak values only after it crosses below some number like 60. So my indicator would find the highest value between the time it crossed above 60 and crossed below 60. After the market closes, I want to add up all the highest values from the start of the day to the end, that met my condition.

My actual use case is more complicated than this but I'm hoping I can get some clues using this example. Would appreciate any help!

draw a bubble on last bar of day...
I'm trying to add up the values of an indicator when they reach a certain condition to have a total by the end of the day but can't get anything going with sum or compoundvalue. It's doing my head in.

For example, let's say I have an RSI indicator, and I want to add up its peak values only after it crosses below some number like 60. So my indicator would find the highest value between the time it crossed above 60 and crossed below 60. After the market closes, I want to add up all the highest values from the start of the day to the end, that met my condition.

My actual use case is more complicated than this but I'm hoping I can get some clues using this example. Would appreciate any help!

draw a bubble on last bar of day, with
..sum of prices,
..quantity of peaks in a day
..average of the peaks in a day

Code:
``````#sum_peaks_in_day_00

#Adding up specific plot values during market hours

declare lower;

def na = double.nan;
def bn = barnumber();

def data = rsi();

input peak_level = 60;
#input valley_level = 40;

def newday = getday() != getday();
def dayend = getday() != getday()[-1];

def xpkup = data crosses above peak_level;
def xpkdwn = data crosses below peak_level;

def pkactive = data > peak_level;

def pkcnt;
def pkhi;
def pkdaysum;
if bn == 1 then {
pkcnt = 0;
pkhi = 0;
pkdaysum = 0;
} else if newday and !pkactive then {
pkcnt = 0;
pkhi = 0;
pkdaysum = 0;
} else if newday and pkactive then {
pkcnt = 0;
pkhi = data;
pkdaysum = 0;
} else if xpkdwn or (dayend and pkactive) then {
pkdaysum = round(pkdaysum + pkhi,2);
pkcnt = pkcnt+1;
pkhi = 0;
} else if xpkup then {
pkdaysum = pkdaysum;
pkcnt = pkcnt;
pkhi = data;
} else {
pkdaysum = pkdaysum;
pkcnt = pkcnt;
pkhi = if pkactive then max(pkhi, data) else 0;
}

def pkdayavg = if pkcnt == 0 then 0 else round(pkdaysum/pkcnt,2);

plot z1 = data;
plot z2 = peak_level;

input show_daily_numbers = yes;
pkdaysum + " sum\n" +
pkcnt + " cnt\n" +
pkdayavg + " avg"
, color.green, yes);

input show_day_lines = yes;

input test1 = no;
xpkup + " up\n" +
xpkdwn + " dwn\n" +
pkactive + " act\n" +
pkhi + " pkhi\n" +
pkdaysum + " sum\n" +
pkcnt + " cnt\n" +
pkdayavg + " avg"
, color.yellow, no);

#``````

INTC 15min
3 peaks above 60
sum them , 211
average them , 70.47 ### Not the exact question you're looking for?

87k+ Posts
384 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?