Looking For Another Version Of Trendline w/ Breaks

LPFibonacci317811

New member
Would it be possible to accomplish a similar type of script to this:
https://usethinkscript.com/threads/trendlines-with-breaks-lux-for-thinkorswim.12025/#post-108235
but only with these parameters ?

1. Automatic trendline that only gets drawn when there's a minimum of at least 3 or more touches? (customizable up to say 5)

2. First candle that fully breaks and closes above (or below depending on the trend) the trendline gets highlighted in cyan. (only that candle)

3. The high and lows (including wicks) of that specific (cyan) candle then gets drawn a rectangular box that is projected to the right for a certain number of days (customizable for example on a daily, weekly or monthly chart)

I have included a picture below of what I am trying to describe and hopefully I am describing this correctly. Also I searched this before posting this on here because this was the closest indicator forum that described what I was looking for.

Thank you kindly.

 
Last edited by a moderator:
Would it be possible to accomplish a similar type of script to this:
https://usethinkscript.com/threads/trendlines-with-breaks-lux-for-thinkorswim.12025/#post-108235
but only with these parameters ?

1. Automatic trendline that only gets drawn when there's a minimum of at least 3 or more touches? (customizable up to say 5)

2. First candle that fully breaks and closes above (or below depending on the trend) the trendline gets highlighted in cyan. (only that candle)

3. The high and lows (including wicks) of that specific (cyan) candle then gets drawn a rectangular box that is projected to the right for a certain number of days (customizable for example on a daily, weekly or monthly chart)

I have included a picture below of what I am trying to describe and hopefully I am describing this correctly. Also I searched this before posting this on here because this was the closest indicator forum that described what I was looking for.

Thank you kindly.

you may not realize, that what you are asking for is very complicated and may not be possible.
i don't think it's been done on this site yet.
i have some ideas and am working on something, but no guarantees.

'touches' is vague. 2 signals will almost never have the same value on the same bar, so you can't use,
when a = b
i would use a 'near' tolerance. maybe something like , if high is within +- $0.02 of a trendline, then it is considered touching it.
 
Last edited:

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

you may not realize, that what you are asking for is very complicated and may not be possible.
i don't think it's been done on this site yet.
i have some ideas and am working on something, but no guarantees.

'touches' is vague. 2 signals will almost never have the same value on the same bar, so you can't use,
when a = b i would use a 'near' tolerance. maybe something like , if high is within +- $0.02 of a trendline, then it is considered touching it.
Ok, I did not realize that, yes that makes sense, thank you much @halcyonguy and whatever you can come up with is greatly appreciated. :)
 
Last edited:
Hi @halcyonguy, I was researching this on TradingView and realized that @samer800 has already converted HoanGhetti's version of "Pivot Trendlines with Breaks" for thinkorswim https://usethinkscript.com/threads/pivot-trendlines-with-breaks-hg-for-thinkorswim.15277/

I realize that what I am asking for is very complicated but maybe @samer800 's conversion will help with accomplishing what I was asking for? Thanks for your time.

Here is HoanGhetti's original code link and pictures which look a little bit closer to what I was originally looking for.

Link: https://www.tradingview.com/script/0ecaiSnU-Pivot-Trendlines-with-Breaks-HG/




Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HoanGhetti

//@version=5
indicator("Pivot Trendlines with Breaks [HG]", overlay = true, max_lines_count = 500)

import HoanGhetti/SimpleTrendlines/4 as tl

input_len       = input.int(defval = 20, title = 'Pivot Length', minval = 1)
input_pivotType = input.string(defval = 'Normal', title = 'Pivot Type', options = ['Normal', 'Fast'], tooltip = 'Normal: Uses Pine\'s built-in pivot system.\n\nFast: Uses a custom pivot system that tracks every reversal.')
input_repaint   = input.bool(defval = true, title = 'Repainting', tooltip = 'If disabled, it will wait for bar confirmation to avoid printing false alerts.')
input_targets   = input.bool(defval = false, title = 'Target Levels')
input_bearC     = input.color(defval = color.red, title = 'Bear Breakout', group = 'Styling')
input_bullC     = input.color(defval = color.green, title = 'Bull Breakout', group = 'Styling')
input_extend    = input.string(defval = extend.none, title = 'Extend', options = [extend.none, extend.right, extend.left, extend.both], group = 'Styling')
input_style     = input.string(defval = line.style_dotted, title = 'Trendline Style', options = [line.style_dotted, line.style_dashed, line.style_solid], group = 'Styling')
input_tstyle    = input.string(defval = line.style_dashed, title = 'Target Style', options = [line.style_dotted, line.style_dashed, line.style_solid], group = 'Styling')
input_override  = input.bool(defval = false, title = 'Override Source', group = 'Override', tooltip = 'Overriding the source will allow the script to create trendlines on any specified source.')
input_useSrc    = input.bool(defval = true, title = 'Use Source for Cross Detection', group = 'Override', tooltip = 'Instead of checking if the close value crossed trendline, check for the specified source.')
input_source    = input.source(defval = low, title = 'Source', group = 'Override')

pl = fixnan(ta.pivotlow(input_override ? input_source : low, input_pivotType == 'Normal' ? input_len : 1, input_len))
ph = fixnan(ta.pivothigh(input_override ? input_source : high, input_pivotType == 'Normal' ? input_len : 1, input_len))

pivot(float pType) =>
    pivot = pType == pl ? pl : ph
    xAxis = ta.valuewhen(ta.change(pivot), bar_index, 0) - ta.valuewhen(ta.change(pivot), bar_index, 1)
    prevPivot = ta.valuewhen(ta.change(pivot), pivot, 1)
    pivotCond = ta.change(pivot) and (pType == pl ? pivot > prevPivot : pivot < prevPivot)
    pData = tl.new(x_axis = xAxis, offset = input_len, strictMode = true, strictType = pType == pl ? 0 : 1)
    pData.drawLine(pivotCond, prevPivot, pivot, input_override ? input_source : na)
    pData

breakout(tl.Trendline this, float pType) =>
    var bool hasCrossed = false
    if ta.change(this.lines.startline.get_y1())
        hasCrossed := false
    this.drawTrendline(not hasCrossed)
    confirmation = not hasCrossed and (input_repaint ? not hasCrossed : barstate.isconfirmed)
    if (pType == pl ? (input_override and input_useSrc ? input_source : close) < this.lines.trendline.get_y2() : (input_override and input_useSrc ? input_source : close) > this.lines.trendline.get_y2()) and confirmation
        hasCrossed := true
        this.lines.startline.set_xy2(this.lines.trendline.get_x2(), this.lines.trendline.get_y2())
        this.lines.trendline.set_xy2(na, na)
        this.lines.startline.copy()
    hasCrossed

plData = pivot(pl)
phData = pivot(ph)

style(tl.Trendline this, color col) =>
    this.lines.startline.set_color(col), this.lines.trendline.set_color(col)
    this.lines.startline.set_width(2), this.lines.trendline.set_width(2)
    this.lines.trendline.set_style(input_style), this.lines.trendline.set_extend(input_extend)
style(plData, input_bearC), style(phData, input_bullC)

cu = breakout(plData, pl)
co = breakout(phData, ph)
plotshape(ta.change(cu) and cu ? plData.lines.startline.get_y2() : na, title = 'Bearish Breakout', style = shape.labeldown, color = input_bearC, textcolor = color.white, location = location.absolute, text = 'Br')
plotshape(ta.change(co) and co ? phData.lines.startline.get_y2() : na, title = 'Bullish Breakout', style = shape.labelup, color = input_bullC, textcolor = color.white, location = location.absolute, text = 'Br')
alertcondition(ta.change(cu) and cu, 'Bearish Breakout')
alertcondition(ta.change(co) and co, 'Bullish Breakout')

// Target Levels [v4 Update]
phData_target = tl.new(phData.values.changeInX)
plData_target = tl.new(plData.values.changeInX)
phData_target.drawLine(ta.change(phData.values.y1) and input_targets, phData.values.y2, phData.values.y2)
plData_target.drawLine(ta.change(plData.values.y1) and input_targets, plData.values.y2, plData.values.y2)

target_style(tl.Trendline this, color col) =>
    this.lines.startline.set_style(input_tstyle)
    this.lines.trendline.set_style(input_tstyle)
    this.lines.startline.set_color(col)
    this.lines.trendline.set_color(col)
target_style(plData_target, input_bearC)
target_style(phData_target, input_bullC)
breakout(phData_target, ph)
breakout(plData_target, pl)
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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