I want to declare a variable

Jah Luv

New member
I just want to do a simple thing that can be easily done in any programming language. I want to declare a variable, for example

def Val = 0;

and then I want to, further down, increment it. You'd think that

Val = Val + 1;

would do it but it doesn't. Can somebody help out.

Thanks in advance.

John
 
Solution
It may sound simple, but its not.

The biggest obstacle between traditional programming languages and thinkscript is the iterated nature of the language. ThinkScript is iterated on a bar by bar basis, and each variable is an array of sorts. This would depend on whether you're trying to increment the variable on the same iteration, or among different iterations.

Among different iterations, it would be

Code:
def Val = Val[1] + 1;

However, it can not be incremented within the same iteration. This is not to say that it can not be done, just that the structure of how this could be accomplished is different than what you might be used to. I could show you more easily if you could give me a more fleshed out version of what you're trying to...
It may sound simple, but its not.

The biggest obstacle between traditional programming languages and thinkscript is the iterated nature of the language. ThinkScript is iterated on a bar by bar basis, and each variable is an array of sorts. This would depend on whether you're trying to increment the variable on the same iteration, or among different iterations.

Among different iterations, it would be

Code:
def Val = Val[1] + 1;

However, it can not be incremented within the same iteration. This is not to say that it can not be done, just that the structure of how this could be accomplished is different than what you might be used to. I could show you more easily if you could give me a more fleshed out version of what you're trying to accomplish.
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

If thinkscript accepted variable reassignment, which unfortunately it doesn't, that would result in a 2 if both Boolean expressions returned True.

Are you trying to tabulate some type of score?

If so, it would be:

def out1 = (ohlc4>EMA1) + (EMA1>EMA1[1]);

If just you're trying to determine whether or not both are true, it would be:

def out1 = (ohlc4>EMA1) and (EMA1>EMA1[1]);

This results in a single Boolean value.

You may still need to be more specific.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
280 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top