Coding errors using GetQuantity()?

Whistlerr

New member
VIP
What's wrong with the following code? The TS editor balks at the bold portions of the if statements. Obviously I would not need both, but what's causing the balks?
Input SetQty = 10000;
Def TrdQty = GetQuantity();
If TrdQty == 0 then TrdQty = SetQty else TrdQty = !isnan;
If GetQuantity() == 0 then TrdQty = SetQty else TrdQty = GetQuantity();
 
Solution
What's wrong with the following code? The TS editor balks at the bold portions of the if statements. Obviously I would not need both, but what's causing the balks?
Input SetQty = 10000;
Def TrdQty = GetQuantity();
If TrdQty == 0 then TrdQty = SetQty else TrdQty = !isnan;
If GetQuantity() == 0 then TrdQty = SetQty else TrdQty = GetQuantity();

in addition to what benten said,

Code:
# ifthen_info_00

#  original
#Input SetQty = 10000;
#Def TrdQty = GetQuantity();
#If TrdQty == 0 then TrdQty = SetQty else TrdQty = !isnan;
#If GetQuantity() == 0 then TrdQty = SetQty else TrdQty = GetQuantity();


input SetQty = 10000;
def TrdQty = GetQuantity();

# you didn't use a def to set a variable to the formula.
#...
Not sure what you're trying to do, but this will fix the syntax errors.

Code:
Input SetQty = 10000;
Def TrdQty = GetQuantity();
def abc = If TrdQty == 0 then TrdQty == SetQty else TrdQty == !double.nan;
def bcd = If GetQuantity() == 0 then TrdQty == SetQty else TrdQty == GetQuantity();

Change "abc" and "bcd" to your liking.
 
What's wrong with the following code? The TS editor balks at the bold portions of the if statements. Obviously I would not need both, but what's causing the balks?
Input SetQty = 10000;
Def TrdQty = GetQuantity();
If TrdQty == 0 then TrdQty = SetQty else TrdQty = !isnan;
If GetQuantity() == 0 then TrdQty = SetQty else TrdQty = GetQuantity();

in addition to what benten said,

Code:
# ifthen_info_00

#  original
#Input SetQty = 10000;
#Def TrdQty = GetQuantity();
#If TrdQty == 0 then TrdQty = SetQty else TrdQty = !isnan;
#If GetQuantity() == 0 then TrdQty = SetQty else TrdQty = GetQuantity();


input SetQty = 10000;
def TrdQty = GetQuantity();

# you didn't use a def to set a variable to the formula.
#   you can't just start out with an if.

#   TrdQty = SetQty
#  when a comparison is within a formula, needs to be a double =
#  TrdQty == SetQty

# TrdQty == SetQty
#   will be evaluated as a boolean , if  TrdQty is equal to SetQty , then it has a value of 1 (true)  else 0


# TrdQty is already defined. 
# if you are trying to set a new value to trdqty, you can't do that.
#  you can't reassign a value to a variable that has already been defined.
# isnan() is a function to check if a variable has an error. ie. isnan(trdqty)
 
# this is wrong. not sure what you want to do with the isnan.
#def a = If TrdQty == 0 then SetQty else !isnan;

def b = If trdqty == 0 then SetQty else trdqty;
#


ps, the above will show an error, because there isn't any output functions used.
sometimes i add this when creating a study, to get rid of the error
addlabel(1, "-");
 
Solution
Thanks all for all the help ... needless to say I'm a green TS coder and there are many idiosyncrasies in TS not covered in documentation.

i agree, the online tos documentation is bad. almost every code example is overly complicated or not helpful.
i learned by looking at studies from several sites. copying them, changing them, and seeing what happens.


https://usethinkscript.com/threads/...l-languages-to-thinkscript.12376/#post-106494
tos onenote archives (need onenote installed for link to work)
jshingler
robert payne


if then else
https://usethinkscript.com/threads/increasing-the-value-of-a-variable.11128/#post-97471


fold loop info
https://usethinkscript.com/threads/coding-help-fold-vs-compoundvalue.11789/#post-101867

https://usethinkscript.com/threads/loops-while.9558/#post-86805
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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