Thinkscript If Statement - ThinkOrSwim Programming | futures io social day trading
futures io futures trading


Thinkscript If Statement
Updated: Views / Replies:4,129 / 11
Created: by newuse Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Thinkscript If Statement

  #1 (permalink)
Trading Apprentice
Atlanta
 
Futures Experience: None
Platform: Think or Swim
Favorite Futures: ES
 
Posts: 9 since May 2015
Thanks: 4 given, 0 received

Thinkscript If Statement

Dear Fellow ThinkScript Coders of Big Mike Trading:

I am a beginning thinkscript programmer and I am learning the syntax of thinkscript pretty fast. However, I am having trouble with the if statements. I understand you can have one statement inside of an if block but is it possible to have multiple statements in an if block?

Not: if (condition) then <this> else <that>;

but: if (condition) then { <this>; <that>;};

Here is example code:

def alertMe =
if (Decrease) then {
Decrease.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Decrease.SetDefaultColor(Color.RED);

Decrease.SetLineWeight(3);
} else if (Increase) then {
Increase.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Increase.SetDefaultColor(Color.BLUE);

Increase.SetLineWeight(3);
};

Alert(alertMe, "ICB", Alert.Bar, Sound.bell);
Alert(!alertMe, "No changes", Alert.Bar, Sound.bell);

Thank you in advanced.


Last edited by newuse; May 5th, 2015 at 07:44 PM. Reason: To add live example code that I wrote.
Reply With Quote
 
  #2 (permalink)
Trading Apprentice
Atlanta
 
Futures Experience: None
Platform: Think or Swim
Favorite Futures: ES
 
Posts: 9 since May 2015
Thanks: 4 given, 0 received

Update:

Dear Fellow ThinkScript Coders of Big Mike Trading:

I am having a problem with this block of code:

def alertMe =
if (Decrease) then {
Decrease.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


Decrease.SetDefaultColor(Color.RED);

Decrease.SetLineWeight(3);
} else if (Increase) then {
Increase.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


Increase.SetDefaultColor(Color.BLUE);

Increase.SetLineWeight(3);
};

Thank you in advanced.

Reply With Quote
 
  #3 (permalink)
Elite Member
Nanjing, NJ
 
Futures Experience: Intermediate
Platform: CQG/TOS
Broker/Data: Optimus/CQG
Favorite Futures: CL
 
Posts: 102 since Jun 2010
Thanks: 33 given, 71 received


i'm not a programmer, but i think you use if/else if when you have 3 conditions, and if/else when you have 2 conditions. looks to me you have 2 conditions, and should try if/else, not if/else if

Reply With Quote
The following user says Thank You to shzhning for this post:
 
  #4 (permalink)
Trading Apprentice
Atlanta
 
Futures Experience: None
Platform: Think or Swim
Favorite Futures: ES
 
Posts: 9 since May 2015
Thanks: 4 given, 0 received

Thank you for your answer @shzhning. I will try out your suggestion. I will update whether this solved the issue.

Reply With Quote
 
  #5 (permalink)
Elite Member
Trubchevsk
 
Futures Experience: Beginner
Platform: tos
Favorite Futures: stocks
 
Posts: 48 since May 2011
Thanks: 34 given, 64 received


newuse View Post
Update:

Dear Fellow ThinkScript Coders of Big Mike Trading:

I am having a problem with this block of code:

def alertMe =
if (Decrease) then {
Decrease.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


Decrease.SetDefaultColor(Color.RED);

Decrease.SetLineWeight(3);
} else if (Increase) then {
Increase.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


Increase.SetDefaultColor(Color.BLUE);

Increase.SetLineWeight(3);
};

Thank you in advanced.


You dont need if-then-else

 
Code
                            
plot Dec Decrease;
plot Inc Increase;
Dec.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Dec.SetDefaultColor(Color.RED);
Dec.SetLineWeight(3);
Inc.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Inc.SetDefaultColor(Color.BLUE);
Inc.SetLineWeight(3); 

Reply With Quote
The following 2 users say Thank You to growex for this post:
 
  #6 (permalink)
Trading Apprentice
Atlanta
 
Futures Experience: None
Platform: Think or Swim
Favorite Futures: ES
 
Posts: 9 since May 2015
Thanks: 4 given, 0 received


growex View Post
You dont need if-then-else

 
Code
                            
plot Dec Decrease;

plot Inc Increase;
Dec.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Dec.SetDefaultColor(Color.RED);
Dec.SetLineWeight(3);
Inc.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Inc.SetDefaultColor(Color.BLUE);
Inc.SetLineWeight(3); 

Does Inc or Dec still paint or show on the graph if the value is 0 or no?

Reply With Quote
 
  #7 (permalink)
Elite Member
Trubchevsk
 
Futures Experience: Beginner
Platform: tos
Favorite Futures: stocks
 
Posts: 48 since May 2011
Thanks: 34 given, 64 received


newuse View Post
Does Inc or Dec still paint or show on the graph if the value is 0 or no?

PaintingStrategy.BOOLEAN_ARROW_DOWN - it will show down arrow only if "Decrease" variable value is true or 1.

Reply With Quote
The following user says Thank You to growex for this post:
 
  #8 (permalink)
Trading Apprentice
pensacola florida
 
Futures Experience: Master
Platform: NinjaTrader, TradeStation, ThinkOrSwim
Favorite Futures: ES
 
Posts: 7 since Jul 2014
Thanks: 0 given, 6 received

For a conditional variable (seems like you were trying to get to this in your post)

## Simple Conditional Variables Test
# Mobius
# V01.07.2014

# Variables:
def o;
def h;
def l;
def c;
def a;
def b;

# Calculations
o = (open + close[1]) / 2;
h = Max(high, close[1]);
l = Min(low, close[1]);
c = (o + h + l + close) / 4;

if c >= o
then {
a = 1;
b = 0;
} else if c < o
then {
a = 0;
b = 1;
} else {
a = Double.NaN;
b = Double.NaN;
}
AddLabel(1, "Close higher = " + a + " Close lower " + b, if a == 1 then color.green else color.red);

Reply With Quote
The following user says Thank You to mobiusrts for this post:
 
  #9 (permalink)
Trading Apprentice
Atlanta
 
Futures Experience: None
Platform: Think or Swim
Favorite Futures: ES
 
Posts: 9 since May 2015
Thanks: 4 given, 0 received


mobiusrts View Post
For a conditional variable (seems like you were trying to get to this in your post)

## Simple Conditional Variables Test
# Mobius
# V01.07.2014

# Variables:
def o;
def h;
def l;
def c;
def a;
def b;

# Calculations
o = (open + close[1]) / 2;
h = Max(high, close[1]);
l = Min(low, close[1]);
c = (o + h + l + close) / 4;

if c >= o
then {
a = 1;
b = 0;
} else if c < o
then {
a = 0;
b = 1;
} else {
a = Double.NaN;
b = Double.NaN;
}
AddLabel(1, "Close higher = " + a + " Close lower " + b, if a == 1 then color.green else color.red);

Thank you for your suggestion and the simple example @mobiusrts. It rejected this structure of the if statement for some reason but I will compare this example with my previous code to gain a better understanding of the if structure.

I just wish the TDAmeritrade Sink or Swim library contained an example that had more than one statement inside the if block. That threw me off along with the Human Readable Syntax following after that example.

Thank you for your time.

Reply With Quote
 
  #10 (permalink)
Trading Apprentice
pensacola florida
 
Futures Experience: Master
Platform: NinjaTrader, TradeStation, ThinkOrSwim
Favorite Futures: ES
 
Posts: 7 since Jul 2014
Thanks: 0 given, 6 received


I copied and pasted my original code from this forum and it plots the label fine. You likely missed some of the code in your copy and paste.

Reply With Quote
The following user says Thank You to mobiusrts for this post:

Reply



futures io > > > > > Thinkscript If Statement

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you interpret/implement this statement? NJAMC Psychology and Money Management 12 January 19th, 2014 07:51 PM
Switch Statement DonStar AmiBroker 7 August 20th, 2012 04:15 PM
Can I use a DataSeries as part of an 'if' statement? magnumdbl NinjaTrader Programming 11 February 11th, 2012 01:24 AM
Jefferies Re-Releases Statement Quick Summary News and Current Events 0 November 3rd, 2011 11:30 AM
Fed repurchase statement Snoop Traders Hideout 1 November 4th, 2010 08:11 AM


All times are GMT -4. The time now is 12:30 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-12 in 0.13 seconds with 19 queries on phoenix via your IP 54.145.16.43