# Coding Help

#### McCarty

##### New member
VIP
I am modifying some code and I am wondering how does think script handle a previous bar on the initial value. For example. I have a variable called Variable1= does some calculation... I then call Variable1[1]* Variable1... what is the initial value set by thinkscript by Variable[1]? Thanks!!!

Solution
FYI - it appears to look at your formula and elects to place the highest value in that place. It makes sense.
referencing [1] on bar #1 can have different outputs. sometimes it may be 0, sometimes n/a.
i prefer to check if it is on bar #1, then do something different.

def v = volume;
def x = if barnumber() == 1 then v
else x[1] + v;

alternate is to use,
def x = compoundvalue( 1, x[1] + v , v );
.
I am modifying some code and I am wondering how does think script handle a previous bar on the initial value. For example. I have a variable called Variable1= does some calculation... I then call Variable1[1]* Variable1... what is the initial value set by thinkscript by Variable[1]? Thanks!!!
FYI - it appears to look at your formula and elects to place the highest value in that place. It makes sense.

FYI - it appears to look at your formula and elects to place the highest value in that place. It makes sense.
referencing [1] on bar #1 can have different outputs. sometimes it may be 0, sometimes n/a.
i prefer to check if it is on bar #1, then do something different.

def v = volume;
def x = if barnumber() == 1 then v
else x[1] + v;

alternate is to use,
def x = compoundvalue( 1, x[1] + v , v );
.

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