invalidate statement plot 4.1

don't understand, can't see the forest from the trees. can some kindly help me.thanks.

def total = 7;

def items = 0;



plot scan = if items < total

then



add 1 to items



else



double.nan;
 
Solution
don't understand, can't see the forest from the trees. can some kindly help me.thanks.

def total = 7;
def items = 0;
plot scan = if items < total
then add 1 to items
else double.nan;

can you describe in words, what you want to have happen?


...plot scan = if items < total

this compares 2 constants, 0 and 7.
it will always be true.
line #4 will always be processed, but is incorrect.


...then add 1 to items

this if-then section will always be processed. but it is invalid , so the program crashes.
'add' isn't a valid arithmetic opeator.
you can't add a number to a constant.

---------

i have a feeling you want to add 1 to a variable when something happens. to do this you need to read from a variable in the past. you do...
don't understand, can't see the forest from the trees. can some kindly help me.thanks.

def total = 7;
def items = 0;
plot scan = if items < total
then add 1 to items
else double.nan;

can you describe in words, what you want to have happen?


...plot scan = if items < total

this compares 2 constants, 0 and 7.
it will always be true.
line #4 will always be processed, but is incorrect.


...then add 1 to items

this if-then section will always be processed. but it is invalid , so the program crashes.
'add' isn't a valid arithmetic opeator.
you can't add a number to a constant.

---------

i have a feeling you want to add 1 to a variable when something happens. to do this you need to read from a variable in the past. you do this by using an offset.

https://tlc.thinkorswim.com/center/reference/thinkScript/Operators/Arithmetic
 
Solution

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

thank you halcyonguy for trying to help me. My goal is to look only at the last 6 bars for a scan, not the entire chart.

still haven't mentioned what you are looking for, so i will make some guesses.

Code:
def trigger =  a true/false  formula 
input barback = 6;
plot trigsum = if sum(trigger, barback) > 0 then 1 else 0;
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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