How to connect dots in thinkscript

SmartCoder

New member
Hi,

So I have this thinkscript code that will plot dots on the bars of the chart:

def OB = High > High[1] and low < low[1];
def IB = High < High[1] and low > low[1];
def HH = ((High > High[1]) and (High[1] > High[2]) and (IB == 0 and IB[1] == 0 and IB[2] == 0)) or
(High[1] > High[2] and High[2] > High[3] and (IB == 1 and IB[1] == 0 and IB[2] == 0 and IB[3] == 0)) or
(High > High[2] and High[2] > High[3] and (IB == 0 and IB[1] == 1 and IB[2] == 0 and IB[3] == 0)) or
(High > High[1] and High[1] > High[3] and (IB == 0 and IB[1] == 0 and IB[2] == 1 and IB[3] == 0));

def LL = (Low < Low[1] and Low[1] < Low[2] and (IB == 0 and IB[1] == 0 and IB[2] == 0)) or
(Low[1] < Low[2] and Low[2] < Low[3] and (IB == 1 and IB[1] == 0 and IB[2] == 0 and IB[3] == 0)) or
(Low < Low[2] and Low[2] < Low[3] and (IB == 0 and IB[1] == 1 and IB[2] == 0 and IB[3] == 0)) or
(Low < Low[1] and Low[1] < Low[3] and (IB == 0 and IB[1] == 0 and IB[2] == 1 and IB[3] == 0));


assignPriceColor(if HH then color.green else if LL then color.red else if OB then color.cyan else if IB then color.orange else color.gray);


# 1 - Green
# 2 - Red
# 3 - Gray
def color = if HH then 1 else if LL then 2 else 3;

def HHdot = if (color == 1 and color[1] == 1) then hl2[2] else double.nan;
def LLdot = if (color == 2 and color[1] == 2) then hl2[2] else double.nan;


plot d1 = HHdot[-2];
plot d2 = LLdot[-2];
d1.SetPaintingStrategy(PaintingStrategy.POINTS);
d2.SetPaintingStrategy(PaintingStrategy.POINTS);

I want to connect these dots in a line similar to the Zig Zag High Low, but I am having trouble doing that. Could someone please show me how to do that?
 
Im posting from my phone at the moment, but you would use this:

https://tlc.thinkorswim.com/center/...unctions/Look---Feel/EnableApproximation.html

I can take a deeper look at it later if nobody else has helped you by then.
Hi,

So I was able to figure out how to get the zig-zag line to work, and I was just wondering if you know of a way that I can adjust how far back the line goes. For example, if my code if a certain condition is met, then the line needs to be two bars back whereas if another condition if met then there needs to be an offset of three bars. Here is the code:

Code:
def color = if HH and greenBefore == 2 then 1 else if LL and redBefore == 2 then 2 else 3;


def lower = if low[1] < low[2] then low[1] else low[2];
def higher = if high[1] > high[2] then high[1] else high[2];

def HHdot = if color == 1 then if IB[2] then low[3] else lower else double.nan;
def LLdot = if color == 2 then if IB[2] then high[3] else higher else double.nan;

def d1 = if isNaN(HHdot) then LLdot else HHdot;
plot z = d1[-2];
z.EnableApproximation();

As you can see, there are some situations where the plot z has to be d1[-3] because of low[3] and high[3], and there are some situations where the plot z has to be d1[-2] because of low[2] or high[2], and there are even some situations where the plot z has to be d1[-1] because of low[1] and high[1]. Is there any way I can implement this logic?
 

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
602 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