Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ___ ____________ _____ _ __
- // / | / ____/ ____/ / ___/(_)___ _____ ____ _/ /
- // / /| |/ / __/ / __ \__ \/ / __ `/ __ \/ __ `/ /
- // / ___ / /_/ / /_/ / ___/ / / /_/ / / / / /_/ / /
- // /_/ |_\____/\____/ /____/_/\__, /_/ /_/\__,_/_/
- // /____/
- // ==========================================================================
- // @description The simplest version of the indicator automatically draws trendLine on your charts, with newest type features, with build-in functions only.
- // @version 1.0
- // @date 2022/12/28
- // @author feibilanceon
- // You can use it anywhere but please keep the author info.
- //@version=5
- indicator("Pivot TrendLine with type", shorttitle="P_L_t", overlay=true)
- // Config
- pivotLength = input(20, title = "Pivot Length")
- leftBars = pivotLength
- rightBars = pivotLength
- onlyLastLine = input(true, title = "Only show last trend line")
- // Type
- type pivotPoint
- int barIndex
- float price
- var highPivots = array.new<pivotPoint>()
- var lowPivots = array.new<pivotPoint>()
- // Pivot High
- swh = ta.pivothigh(leftBars, rightBars)
- if swh
- array.push(highPivots, pivotPoint.new(bar_index - rightBars, swh))
- // Pivot Low
- swl = ta.pivotlow(leftBars, rightBars)
- if swl
- array.push(lowPivots, pivotPoint.new(bar_index - rightBars, swl))
- // Plot
- var lineHigh = line.new(0,0,0,0, extend=extend.right)
- pivotPoint lastHighPivot = array.size(highPivots) > 2 ? array.get(highPivots,array.size(highPivots) - 1) : na
- pivotPoint secondLastHighPivot = array.size(highPivots) > 2 ? array.get(highPivots,array.size(highPivots) - 2) : na
- if array.size(highPivots) > 2
- if lastHighPivot.barIndex != secondLastHighPivot.barIndex
- if onlyLastLine
- line.delete(lineHigh)
- line.set_color(lineHigh, color.new(color.red, 80))
- line.set_extend(lineHigh, extend.none)
- lineHigh := line.new(secondLastHighPivot.barIndex, secondLastHighPivot.price, lastHighPivot.barIndex, lastHighPivot.price, extend=extend.right, color=color.red)
- var lineLow = line.new(0,0,0,0, extend=extend.right)
- pivotPoint lastLowPivot = array.size(lowPivots) > 2 ? array.get(lowPivots,array.size(lowPivots) - 1) : na
- pivotPoint secondLastLowPivot = array.size(lowPivots) > 2 ? array.get(lowPivots,array.size(lowPivots) - 2) : na
- if array.size(lowPivots) > 2
- if lastLowPivot.barIndex != secondLastLowPivot.barIndex
- if onlyLastLine
- line.delete(lineLow)
- line.set_color(lineLow, color.new(color.green, 80))
- line.set_extend(lineLow, extend.none)
- lineLow := line.new(secondLastLowPivot.barIndex, secondLastLowPivot.price, lastLowPivot.barIndex, lastLowPivot.price, extend=extend.right,color=color.green)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement