NexusFi: Find Your Edge


Home Menu

 





Question about if statement/expressions


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one bb117 with 3 posts (0 thanks)
    2. looks_two Daytrader999 with 1 posts (1 thanks)
    3. looks_3 kevinkdog with 1 posts (0 thanks)
    4. looks_4 block1 with 1 posts (0 thanks)
    1. trending_up 4,581 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
bb117
Miami, Florida
 
Posts: 3 since Nov 2021
Thanks Given: 1
Thanks Received: 0

I'm thinking of creating several conditions and if they are all true, have an arrow painted on the screen. But there's a problem.
What I'm using is Thinkscript from Thinkorswim and it's saying that it expected an 'else block' where it says 'if', and I just don't get it, nor understand why that if statement is wrong.

def con1 = (MovAvgExponential("length" = 9)."AvgExp" crosses above
MovAvgExponential("length" = 20)."AvgExp" within 2 bars);

plot signal = if con1 is true
then SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Orban at 29pct as Hungary Votes Tomorrow -- McIlroy Surg …
Prediction Markets & Event Contracts
$24.5 Billion Record Month: Prediction Markets Shatter A …
Prediction Markets & Event Contracts
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
Commodities
S&P 500 Holds the Line: No Fast Track for SpaceX, Op …
Stocks and ETFs
One Wallet Made $200K in Hours: AP Probes Polymarket Cea …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
205 thanks
Sober Journey With S&P
21 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
Thanks Mike. Godspeed.
7 thanks
  #2 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,737 since Jul 2012
Thanks Given: 1,917
Thanks Received: 7,476


bb117 View Post
I'm thinking of creating several conditions and if they are all true, have an arrow painted on the screen. But there's a problem.
What I'm using is Thinkscript from Thinkorswim and it's saying that it expected an 'else block' where it says 'if', and I just don't get it, nor understand why that if statement is wrong.

def con1 = (MovAvgExponential("length" = 9)."AvgExp" crosses above
MovAvgExponential("length" = 20)."AvgExp" within 2 bars);

plot signal = if con1 is true
then SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

You are posting in the Tradestation EasyLanguage forum. Maybe a mod will move this to the TOS section.


Follow me on X Reply With Quote
  #3 (permalink)
 
Daytrader999's Avatar
 Daytrader999 
Ilsede, Germany
Site Moderator
 
Experience: Advanced
Platform: NinjaTrader 8
Broker: Rithmic / CQG / Ninja Trader Brokerage
Trading: NQ
Posts: 1,492 since Sep 2011
Thanks Given: 2,078
Thanks Received: 2,320



kevinkdog View Post
You are posting in the Tradestation EasyLanguage forum. Maybe a mod will move this to the TOS section.


Done....


"If you don't design your own life plan, chances are you'll fall into someone else's plan. And guess what they have planned for you? Not much." - Jim Rohn
Reply With Quote
Thanked by:
  #4 (permalink)
bb117
Miami, Florida
 
Posts: 3 since Nov 2021
Thanks Given: 1
Thanks Received: 0

Yeah sorry about that, first time here and didn't even realize the ThinkOrSwim sub-forum, I created the account and this thread all while I was in a different page that had another coding question I had, answered, and it was under the EasyLanguage sub-forum and forgot to check/change the forum I was in.


Reply With Quote
  #5 (permalink)
 Miesto 
Monte Carlo, Monaco
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader 8
Broker: NinjaTrader Brokerage
Trading: Futures
Posts: 720 since May 2012
Thanks Given: 883
Thanks Received: 1,281

Note that in thinkScript®, the "else" block is mandatory.

Try to add "ELSE" with no expression like:

plot signal = if con1 is true then SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP) ELSE ;

or use a dummy statement like:

plot signal = if con1 is true then SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP) ELSE dummy=0;

It wants to know what to do in case con1 is false.


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
bb117
Miami, Florida
 
Posts: 3 since Nov 2021
Thanks Given: 1
Thanks Received: 0

thank you for your reply in the end I tried something different, just gotta tweak the parameters and conditions until I get the result I want.


Reply With Quote
  #7 (permalink)
 
Jern's Avatar
 Jern 
Eastern NC
 
Experience: Intermediate
Platform: ThinkorSwim
Trading: Futures
Posts: 7 since Oct 2021
Thanks Given: 42
Thanks Received: 15

It's probably looking for Double.NaN, which means Not a Number. It doesn't plot anything when the condition is false.

Here is some code I've used before.

plot arrowAddUp = if con1 then low else Double.NaN;
plot arrowAddDn = if con2 then high else Double.NaN;


And then this defines the plot.

arrowAddUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
arrowAddUp.SetDefaultColor(CreateColor(143, 239, 191));
arrowAddUp.SetLineWeight(1);

arrowAddDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrowAddDn.SetDefaultColor(CreateColor(255, 126, 156));
arrowAddDn.SetLineWeight(1);


Reply With Quote
  #8 (permalink)
block1
Hartford, Ct
 
Posts: 1 since Oct 2021
Thanks Given: 0
Thanks Received: 0

New to thinkscript so there may be a better way to code this but the below paints the arrows it looks like your after

def con1 = (MovAvgExponential("length" = 9)."AvgExp" crosses above
MovAvgExponential("length" = 20)."AvgExp" within 2 bars);
def con2 = con1 is true;
plot con3 = con2;
con3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


Reply With Quote




Last Updated on December 19, 2021


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts