upper band connecting highs and lower band connecting lows or channel ?

Drmoh1800

Member
VIP
I am trying to connect previous highs and lows
Looking to last 20 bars
TOjM1Gf.jpg
 
Solution
I am trying to connect previous highs and lows
Looking to last 20 bars

this will,
...find peaks and draw lines between them.
...find valleys and draw lines between them.

a peak is defined as the highest high within 7 bars behind current bar and 7 bars ahead of bar.
valleys are similar.

Code:
# peaks_valley_diag_lines_00

#------------------------
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# define swing low points , robert payne
# modifified by halcyonguy to ignore last bar
#------------------------

def bn = BarNumber();
def na = double.nan;

input length = 7;

def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn)...
I am trying to connect previous highs and lows
Looking to last 20 bars

here is a hint,
when a plot formula has values of numbers and double.nan,
the numbers will have a line connecting them, IF EnableApproximation() is used.

Code:
# draw a line from every 20th bar
def t = 20;
# if the current barnumber/20  has no remainder, then true
def x = if (barnumber() % t ) == 0 then 1 else 0;
plot z = if x then close else double.nan;
z.EnableApproximation();

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/EnableApproximation
 

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

I am trying to connect previous highs and lows
Looking to last 20 bars

this will,
...find peaks and draw lines between them.
...find valleys and draw lines between them.

a peak is defined as the highest high within 7 bars behind current bar and 7 bars ahead of bar.
valleys are similar.

Code:
# peaks_valley_diag_lines_00

#------------------------
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# define swing low points , robert payne
# modifified by halcyonguy to ignore last bar
#------------------------

def bn = BarNumber();
def na = double.nan;

input length = 7;

def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);

input ignore_last_bar = yes;
def ignorelast = if (ignore_last_bar and bn == lastbar) then 0 else 1;

def peak = ignorelast and high > highest(high[1], length - 1) and high == GetValue(highest(high, length), -offset);
def valley = ignorelast and low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);

#-------------------------------------

input show_dots_on_peaks_valleys = yes;
def vert = 0.002;
plot z1 = if show_dots_on_peaks_valleys and peak then high*(1+vert) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(3);
z1.hidebubble();

plot z2 = if show_dots_on_peaks_valleys and valley then low*(1-vert) else na;
z2.SetPaintingStrategy(PaintingStrategy.POINTS);
z2.SetDefaultColor(Color.cyan);
z2.setlineweight(3);
z2.hidebubble();


plot zp = if peak then high else double.nan;
zp.EnableApproximation();

plot zv = if valley then low else double.nan;
zv.EnableApproximation();
#

OTv6fyP.jpg
 
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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