review my code for Support and Resistance for ThinkorSwim?

petergluis

Active member
Could you please check my code for Support and Resistance for ThinkorSwim? I converted Support and Resistance for ThinkorSwim. But it doesn't show in a right way.

https://www.tradingview.com/script/JWdq2Bni-RS-Support-and-Resistance-V0/

Ruby:
def window1 = 8;
def window2 = 21;
def condition1 = high >= highest(high, window1);
def top1 = if condition1 then high else 0;
def condition2 =low <= lowest(low, window1);
def bot1 = if condition2 then low else 0;
def condition3 = high >= highest(high, window2);
def top2 = if condition3 then high else 0;
def condition4 = low <= lowest(low, window2);
def bot2 = if condition4 then low else 0;

plot t1 = top1;
plot b1 = bot1;
plot t2 = top2;
plot b2 = bot2;
 
Solution
Could you please check my code for Support and Resistance for ThinkorSwim? I converted Support and Resistance for ThinkorSwim. But it doesn't show in a right way.

https://www.tradingview.com/script/JWdq2Bni-RS-Support-and-Resistance-V0/

Ruby:
def window1 = 8;
def window2 = 21;
def condition1 = high >= highest(high, window1);
def top1 = if condition1 then high else 0;
def condition2 =low <= lowest(low, window1);
def bot1 = if condition2 then low else 0;
def condition3 = high >= highest(high, window2);
def top2 = if condition3 then high else 0;
def condition4 = low <= lowest(low, window2);
def bot2 = if condition4 then low else 0;

plot t1 = top1;
plot b1 = bot1;
plot t2 = top2;
plot b2 = bot2;

do you see spikes on 1...
Could you please check my code for Support and Resistance for ThinkorSwim? I converted Support and Resistance for ThinkorSwim. But it doesn't show in a right way.

https://www.tradingview.com/script/JWdq2Bni-RS-Support-and-Resistance-V0/

Ruby:
def window1 = 8;
def window2 = 21;
def condition1 = high >= highest(high, window1);
def top1 = if condition1 then high else 0;
def condition2 =low <= lowest(low, window1);
def bot1 = if condition2 then low else 0;
def condition3 = high >= highest(high, window2);
def top2 = if condition3 then high else 0;
def condition4 = low <= lowest(low, window2);
def bot2 = if condition4 then low else 0;

plot t1 = top1;
plot b1 = bot1;
plot t2 = top2;
plot b2 = bot2;

do you see spikes on 1 bar?
you are finding a condition on 1 bar, but then going to 0 for the other bars.
you don't have anything to retain a value.

chg this,
def top1 = if condition1 then high else 0;

to this,
def top1 = if condition1 then high else top1[1];
 
Solution

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

do you see spikes on 1 bar?
you are finding a condition on 1 bar, but then going to 0 for the other bars.
you don't have anything to retain a value.

chg this,
def top1 = if condition1 then high else 0;

to this,
def top1 = if condition1 then high else top1[1];
Thank you very much for your help. It is working now after I follow your suggestion.
Ruby:
def window1 = 8;
def window2 = 21;
def condition1 = high >= highest(high, window1);
def top1 = if condition1 then high else top1[1];
def condition2 =low <= lowest(low, window1);
def bot1 = if condition2 then low else bot1[1];
def condition3 = high >= highest(high, window2);
def top2 = if condition3 then high else top2[1];
def condition4 = low <= lowest(low, window2);
def bot2 = if condition4 then low else bot2[1];
plot t1 = top1;
plot b1 = bot1;
plot t2 = top2;
plot b2 = bot2;
Addcloud (t1, t2, color.yellow, color.pink);
Addcloud (b1, b2, color.light_green, color.cyan);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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