# calculate only once

#### cay7man

##### Member
Any idea how to calculate something only once not every bar? For example, I want to determine if a candle closed below the previous one
and remember that for the rest of the trading session.

Solution
Any idea how to calculate something only once not every bar? For example, I want to determine if a candle closed below the previous one
and remember that for the rest of the trading session.

See if this helps

Ruby:
``````def sessionopen = 930;
def secondsFromOpen = SecondsFromTime(sessionopen);

def cond2 = if secondsFromOpen == 0
then 0
else if close < close[1]
then 1
else cond2[1] >= 1 ;
AddChartBubble(cond2[1] == 0 and cond2 == 1, low, "C<C[1]", Color.LIGHT_RED, no);
AddLabel(cond2 >= 1, "Close is less then Close[1] on " + asprice(getyyyYMMDD()), Color.WHITE);``````
Any idea how to calculate something only once not every bar? For example, I want to determine if a candle closed below the previous one
and remember that for the rest of the trading session.

See if this helps

Ruby:
``````def sessionopen = 930;
def secondsFromOpen = SecondsFromTime(sessionopen);

def cond2 = if secondsFromOpen == 0
then 0
else if close < close[1]
then 1
else cond2[1] >= 1 ;
AddChartBubble(cond2[1] == 0 and cond2 == 1, low, "C<C[1]", Color.LIGHT_RED, no);
AddLabel(cond2 >= 1, "Close is less then Close[1] on " + asprice(getyyyYMMDD()), Color.WHITE);``````

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