HTF & Pivot Liquidity Levels

dub4art · study · 448 行 · 点赞 33 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dub4art
 
//@version=6
indicator('HTF & Pivot Liquidity Levels', 'LIQT', true, max_lines_count = 500, max_bars_back=5000)
 
var gHTFLIQ = 'HTF & Pivot Liquidity Levels'
is_tf1 = input(true, '', inline = 'Level1', group = gHTFLIQ)
tf1 = input.timeframe('M', '', inline = 'Level1', group = gHTFLIQ)
upperColorTF1 = input(color.new(color.blue, 0), '', inline = 'Level1', group = gHTFLIQ)
lowerColorTF1 = input(color.new(color.blue, 0), '', inline = 'Level1', group = gHTFLIQ)
widthTF1 = input(6, 'Width', inline = 'Level1', group = gHTFLIQ, display = display.none)
 
is_tf2 = input(true, '', inline = 'Level2', group = gHTFLIQ)
tf2 = input.timeframe('W', '', inline = 'Level2', group = gHTFLIQ)
upperColorTF2 = input(color.new(color.green, 0), '', inline = 'Level2', group = gHTFLIQ)
lowerColorTF2 = input(color.new(color.green, 0), '', inline = 'Level2', group = gHTFLIQ)
widthTF2 = input(5, 'Width', inline = 'Level2', group = gHTFLIQ, display = display.none)
 
is_tf3 = input(true, '', inline = 'Level3', group = gHTFLIQ)
tf3 = input.timeframe('D', '', inline = 'Level3', group = gHTFLIQ)
upperColorTF3 = input(color.new(color.orange, 0), '', inline = 'Level3', group = gHTFLIQ)
lowerColorTF3 = input(color.new(color.orange, 0), '', inline = 'Level3', group = gHTFLIQ)
widthTF3 = input(4, 'Width', inline = 'Level3', group = gHTFLIQ, display = display.none)
 
is_tf4 = input(true, '', inline = 'Level4', group = gHTFLIQ)
tf4 = input.timeframe('240', '', inline = 'Level4', group = gHTFLIQ)
upperColorTF4 = input(color.new(color.fuchsia, 0), '', inline = 'Level4', group = gHTFLIQ)
lowerColorTF4 = input(color.new(color.fuchsia, 0), '', inline = 'Level4', group = gHTFLIQ)
widthTF4 = input(3, 'Width', inline = 'Level4', group = gHTFLIQ, display = display.none)
 
is_tf5 = input(true, '', inline = 'Level5', group = gHTFLIQ)
tf5 = input.timeframe('60', '', inline = 'Level5', group = gHTFLIQ)
upperColorTF5 = input(color.new(color.silver, 0), '', inline = 'Level5', group = gHTFLIQ)
lowerColorTF5 = input(color.new(color.silver, 0), '', inline = 'Level5', group = gHTFLIQ)
widthTF5 = input(2, 'Width', inline = 'Level5', group = gHTFLIQ, display = display.none)
 
is_tf6 = input(true, '', inline = 'Level6', group = gHTFLIQ)
tf6 = input.timeframe('30', '', inline = 'Level6', group = gHTFLIQ)
upperColorTF6 = input(color.new(color.aqua, 0), '', inline = 'Level6', group = gHTFLIQ)
lowerColorTF6 = input(color.new(color.aqua, 0), '', inline = 'Level6', group = gHTFLIQ)
widthTF6 = input(1, 'Width', inline = 'Level6', group = gHTFLIQ, display = display.none)
 
purgeDelayMinutes = input.int(10, '  Clear Purged After', inline = 'purgd1', group = gHTFLIQ, tooltip = "Time in minutes after which HTF purged levels are removed (e.g., 30 for 30 minutes).")
purgedColorHigh = input(color.rgb(0, 255, 0, 0), '', inline = 'purgd1', group = gHTFLIQ)
purgedColorLow = input(color.rgb(255, 0, 0, 0), '', inline = 'purgd1', group = gHTFLIQ)
purgedStyleInput = input.string('Arrow', '', ['Solid', 'Dashed', 'Dotted', 'Arrow'], inline = 'purgd1', group = gHTFLIQ, display = display.none)
 
enablePivots = input.bool(true, 'Chart Pivots', inline = 'pv2', group = gHTFLIQ, tooltip = 'Finds extra liquidity levels directly on the chart timeframe via pivot high/low detection, catching pivots that fall between the sampled HTF levels above. Subject to stacking priority, so an HTF level at the same price always wins.')
pivotColorHi = input.color(color.new(color.gray, 0), '', inline = 'pv2', group = gHTFLIQ)
pivotColorLo = input.color(color.new(color.gray, 0), '', inline = 'pv2', group = gHTFLIQ)
pivotWidth = input.int(1, 'Width', inline = 'pv2', group = gHTFLIQ)
pivotBarsLeft = input.int(4, '  Pivot Bars Left', minval = 0, maxval = 100, inline = 'pv1', group = gHTFLIQ)
pivotBarsRight = input.int(3, '  Right', minval = 0, maxval = 100, inline = 'pv1', group = gHTFLIQ)
pivotDelayBars = input.int(2, '  Clear Purged Pivots After (Bars)', minval = 0, tooltip = 'Number of bars after mitigation before a pivot-discovered level is removed from the chart.', group = gHTFLIQ)
pivotQueueMin = input.int(10, '  Minimum Pivot Levels Kept', minval = 0, tooltip = 'Always keeps at least this many active chart-pivot levels (combined highs + lows), even under heavy line pressure. More are kept automatically when there is spare room in the shared 500-line budget, but higher-timeframe levels are always protected first.', group = gHTFLIQ)
 
marker_start = input.int(11, 'Active Level Marker Location', inline = 'mark1', group = gHTFLIQ, tooltip = "Coordinates of Level Side Marker Lines. Each value represents bar offset")
marker_end = input.int(13, '', inline = 'mark1', group = gHTFLIQ)
purged_offset = input(-8, 'Marker Offset for Purged Levels', group = gHTFLIQ, display = display.none)
showCountdown = input.bool(true, 'Countdown Timer', tooltip = 'Display remaining time until purged level is removed from the chart', inline = 'timer1', group = gHTFLIQ)
countdownColor = input(color.silver, '', inline = 'timer1', group = gHTFLIQ)
countdownSize = input.string('small', '', ['tiny', 'small', 'normal', 'large'], inline = 'timer1', group = gHTFLIQ)
hide_above = input.timeframe("2", "  Hide Timer Above", group = gHTFLIQ, tooltip = "Due to pine limitations above 1m the timer may be inaccurate")
enableStacking = input.bool(true, 'Enable HTF Stacking', tooltip = 'When several liquidity sources resolve to the same price, they are combined into a single level to prevent overwriting the same level with multiple lines', group = gHTFLIQ)
enable_proximity = input.bool(true, 'Extend Marker Line on Proximity  ', inline = 'prox1', group = gHTFLIQ)
proximityMode = input.string('ATR Multiple', 'Mode', options = ['Fixed Points', 'ATR Multiple'], inline = 'prox1', group = gHTFLIQ, tooltip = 'Fixed Points is a raw price distance (only meaningful for one market at a time, e.g. futures). ATR Multiple scales automatically to the current symbol\'s volatility, so the same setting works across futures, forex, and stocks.')
proximityAtrLength = input.int(14, '  ATR Length', inline = 'prox2', group = gHTFLIQ)
proximityAtrMult = input.float(1.5, 'Multiplier', step = 0.5, tooltip = 'Used only when Proximity Distance Mode is set to ATR Multiple. E.g. 1.5 means "within 1.5x the current ATR".', inline = 'prox2', group = gHTFLIQ)
auto_atr = input.bool(true, 'Auto', inline = 'prox2', group = gHTFLIQ)
proximityDistance = input.float(20.0, '  Indices Proximity Distance (Fixed Points)', tooltip = 'Used only when Proximity Distance Mode is set to Fixed Points which should work well for indices', group = gHTFLIQ)
extender_end = input.int(2, '  Proximity Line Ends at bar', inline = "lw2", group = gHTFLIQ)
ln_style = input.string(defval=line.style_solid, options=[line.style_dashed, line.style_dotted, line.style_solid], title = "", inline = "lw2", group = gHTFLIQ)
enable_glow = input.bool(true, 'Glow Effect', inline = "lw3", group = gHTFLIQ, tooltip = "Active Levels will glow if price is in proximity. Effect width is proportionally multiplied for HTF levels to make more important levels stand out more")
glow_transp = input.int(75, 'Transparency & Width', inline = "lw3", group = gHTFLIQ)
glow_width = input.int(2, '', inline = "lw3", group = gHTFLIQ)
showPivotDots = input.bool(true, 'Show Pivot Dots', inline = 'pv3', group = gHTFLIQ, tooltip = "Purely visual, independent of 'Chart Pivots', it may be useful to see.")
pivotDotColor = input.color(color.new(color.gray, 0), '', inline = 'pv3', group = gHTFLIQ)
pivotDotLookback = input.int(200, 'Last (bars)', minval = 20, maxval = 1000, inline = 'pv3', group = gHTFLIQ)
 
allowed = timeframe.in_seconds('') <= timeframe.in_seconds(hide_above)
frx = syminfo.type == "forex"
 
type Level
	float price
	line line
    int purgeTime = na  // Timestamp when level was purged
    label lbl = na  // Label for countdown timer
    int tfSeconds = na  // Timeframe (in seconds) that produced this level, used for stacking priority
    int originTime = na  // Timestamp where the pivot high/low was originally established (bar_time, not bar_index — see xloc.bar_time usage below)
    line proximityLine = na  // Line extending back to originTime, shown only when price is near this level
    box glowBox = na  // Glow box drawn around the proximity line, shown only when price is near this level
    color col = na  // Marker color, reused for the proximity line and glow box
    int lineWidth = na  // Marker width, reused for the proximity line
    bool isPivot = false  // True for levels discovered via chart-timeframe pivot detection (vs HTF sampling)
    int purgeBar = na  // Bar index when the level was purged, used for nBars-based expiry of pivot-discovered levels
 
type Origin
    float high = na
    int highTime = na
    float low = na
    int lowTime = na
 
var highsArray = array.new<Level>()
var lowsArray = array.new<Level>()
var purgedArray = array.new<Level>()
 
resolve_auto_atr() =>
    float result = 0
    if timeframe.in_seconds('') < timeframe.in_seconds('5')
        result := 2.5
    else if timeframe.in_seconds('') == timeframe.in_seconds('5')
        result := 2
    else if timeframe.in_seconds('') >= timeframe.in_seconds('15') and timeframe.in_seconds('') <= timeframe.in_seconds('240')
        result := 1.5
    else if timeframe.in_seconds('') > timeframe.in_seconds('240')
        result := 1
    result
 
resolve_auto_width() => 
    float result = 0
    if timeframe.in_seconds('') < timeframe.in_seconds('1')
        result := 0.5
    if timeframe.in_seconds('') == timeframe.in_seconds('1')
        result := 1
    if timeframe.in_seconds('') > timeframe.in_seconds('1') and timeframe.in_seconds('') <= timeframe.in_seconds('15')
        result := 1.5
    else if timeframe.in_seconds('') >= timeframe.in_seconds('30') and timeframe.in_seconds('') <= timeframe.in_seconds('240')
        result := 2
    else if timeframe.in_seconds('') > timeframe.in_seconds('240')
        result := 2.5
    result
 
effective_multi = auto_atr ? resolve_auto_atr() : proximityAtrMult
 
proximityThreshold = proximityMode == 'Fixed Points' ? proximityDistance : ta.atr(proximityAtrLength) * effective_multi
 
[prevHigh1, prevLow1] = request.security(syminfo.tickerid, tf1, [high[1], low[1]], lookahead = barmerge.lookahead_on)
[prevHigh2, prevLow2] = request.security(syminfo.tickerid, tf2, [high[1], low[1]], lookahead = barmerge.lookahead_on)
[prevHigh3, prevLow3] = request.security(syminfo.tickerid, tf3, [high[1], low[1]], lookahead = barmerge.lookahead_on)
[prevHigh4, prevLow4] = request.security(syminfo.tickerid, tf4, [high[1], low[1]], lookahead = barmerge.lookahead_on)
[prevHigh5, prevLow5] = request.security(syminfo.tickerid, tf5, [high[1], low[1]], lookahead = barmerge.lookahead_on)
[prevHigh6, prevLow6] = request.security(syminfo.tickerid, tf6, [high[1], low[1]], lookahead = barmerge.lookahead_on)
 
f_isHigherTimeframe(string timeframe) =>
    timeframe.in_seconds(timeframe) >= timeframe.in_seconds()
 
f_getLineStyle() =>
    switch purgedStyleInput
        'Solid' => line.style_solid
        'Dotted' => line.style_dotted
        'Dashed' => line.style_dashed
        'Arrow' => line.style_arrow_left
 
f_getLabelSize() =>
    switch countdownSize
        'tiny' => size.tiny
        'small' => size.small
        'normal' => size.normal
        'large' => size.large
        => size.small
 
f_formatTime(int ms) =>
    totalSeconds = math.floor(ms / 1000)
    minutes = math.floor(totalSeconds / 60)
    seconds = totalSeconds % 60
    str.format('{0,number,00}:{1,number,00}', minutes, seconds)
 
f_drawLine(float y, color color, int width) =>
    line.new(bar_index, y, bar_index, y, color = color, width = width)
 
method trackOrigin(Origin this, bool isNewPeriod) =>
    _prevHigh = float(na)
    _prevHighTime = int(na)
    _prevLow = float(na)
    _prevLowTime = int(na)
    if isNewPeriod
        _prevHigh := this.high
        _prevHighTime := this.highTime
        _prevLow := this.low
        _prevLowTime := this.lowTime
        this.high := high
        this.highTime := time
        this.low := low
        this.lowTime := time
    else
        if na(this.high) or high > this.high
            this.high := high
            this.highTime := time
        if na(this.low) or low < this.low
            this.low := low
            this.lowTime := time
    [_prevHigh, _prevHighTime, _prevLow, _prevLowTime]
 
method resolveStacking(array<Level> this, float price, int tfSeconds) =>
    _shouldCreate = true
    _size = this.size()
    if _size > 0
        for i = _size - 1 to 0 by 1
            _level = this.get(i)
            if math.abs(_level.price - price) < syminfo.mintick
                if tfSeconds > _level.tfSeconds
                    _old = this.remove(i)
                    _old.line.delete()
                    if not na(_old.proximityLine)
                        _old.proximityLine.delete()
                    if not na(_old.glowBox)
                        _old.glowBox.delete()
                else
                    _shouldCreate := false
                break 
    _shouldCreate
 
f_createLevels(float h, float l, color upperColor, color lowerColor, int width, int tfSeconds, int originHighTime, int originLowTime) =>
    if not enableStacking
        highsArray.push(Level.new(h, f_drawLine(h, upperColor, width), tfSeconds = tfSeconds, originTime = originHighTime, col = upperColor, lineWidth = width))
        lowsArray.push(Level.new(l, f_drawLine(l, lowerColor, width), tfSeconds = tfSeconds, originTime = originLowTime, col = lowerColor, lineWidth = width))
    else
        if highsArray.resolveStacking(h, tfSeconds)
            highsArray.push(Level.new(h, f_drawLine(h, upperColor, width), tfSeconds = tfSeconds, originTime = originHighTime, col = upperColor, lineWidth = width))
        if lowsArray.resolveStacking(l, tfSeconds)
            lowsArray.push(Level.new(l, f_drawLine(l, lowerColor, width), tfSeconds = tfSeconds, originTime = originLowTime, col = lowerColor, lineWidth = width))
 
f_createPivotLevel(float price, bool isHigh) =>
    _color = isHigh ? pivotColorHi : pivotColorLo
    _tfSeconds = timeframe.in_seconds()
    _originTime = time[pivotBarsRight]
    _target = isHigh ? highsArray : lowsArray
    if not enableStacking
        _target.push(Level.new(price, f_drawLine(price, _color, pivotWidth), tfSeconds = _tfSeconds, originTime = _originTime, col = _color, lineWidth = pivotWidth, isPivot = true))
    else
        if _target.resolveStacking(price, _tfSeconds)
            _target.push(Level.new(price, f_drawLine(price, _color, pivotWidth), tfSeconds = _tfSeconds, originTime = _originTime, col = _color, lineWidth = pivotWidth, isPivot = true))
 
f_findOldestPivotIndex(array<Level> arr) =>
    _idx = -1
    _size = arr.size()
    if _size > 0
        for i = 0 to _size - 1
            if arr.get(i).isPivot
                _idx := i
                break
    _idx
 
f_trimPivotLevels(int minKeep) =>
    _activePivotCount = 0
    for _level in highsArray
        if _level.isPivot
            _activePivotCount += 1
    for _level in lowsArray
        if _level.isPivot
            _activePivotCount += 1
    _purgedPivotCount = 0
    for _level in purgedArray
        if _level.isPivot
            _purgedPivotCount += 1
 
    _nonPivotLines = array.size(line.all) - _activePivotCount - _purgedPivotCount
    _safetyMargin = 15 
    _allowedActive = math.max(minKeep, 500 - _nonPivotLines - _safetyMargin)
 
    while _activePivotCount > _allowedActive
        _hiIdx = f_findOldestPivotIndex(highsArray)
        _loIdx = f_findOldestPivotIndex(lowsArray)
        _removeFromHigh = _hiIdx >= 0 and (_loIdx < 0 or highsArray.get(_hiIdx).originTime <= lowsArray.get(_loIdx).originTime)
        _victim = _removeFromHigh ? highsArray.remove(_hiIdx) : lowsArray.remove(_loIdx)
        _victim.line.delete()
        if not na(_victim.proximityLine)
            _victim.proximityLine.delete()
        if not na(_victim.glowBox)
            _victim.glowBox.delete()
        _activePivotCount -= 1
 
method updatePosition(array<Level> this) =>
    _x1 = bar_index + marker_start
    _x2 = bar_index + marker_end
    for _level in this
        _level.line.set_x1(_x1)
        _level.line.set_x2(_x2)
 
method updatePositionPurged(array<Level> this) =>
    _xp1 = bar_index - purged_offset
    _xp2 = bar_index + 12
    for _level in this
        _level.line.set_x1(_xp1)
        _level.line.set_x2(_xp2)
 
method transferTo(array<Level> this, array<Level> dest, int index) =>
    _level = this.remove(index)
    _level.purgeTime := time    
    _level.purgeBar := bar_index
    if not _level.isPivot and showCountdown and allowed
        _labelX = bar_index + 12
        _level.lbl := label.new(_labelX, _level.price, '', color = color.new(color.black, 100), textcolor = countdownColor, style = label.style_label_left, size = f_getLabelSize())
    dest.push(_level)
 
method highlightPurgedLevel(line this, bool isUpperLevel) =>
    var _style = f_getLineStyle()
    var _width = 1
    this.set_color(isUpperLevel ? purgedColorHigh : purgedColorLow)
    this.set_style(_style)
    this.set_width(_width)
 
f_projectedTime(int offsetBars) =>
    _barMs = na(time[1]) ? timeframe.in_seconds() * 1000 : (time - time[1])
    time + _barMs * offsetBars
 
method updateLevels(array<Level> this, array<Level> purgedArray, bool isUpperLevel) =>
    _hasPurgedSome = false
    _size = this.size()
    if _size > 0
        for i = _size - 1 to 0 by 1
            _level = this.get(i)
            if isUpperLevel ? high > _level.price : low < _level.price
                _level.line.highlightPurgedLevel(isUpperLevel)
                if not na(_level.proximityLine)
                    _level.proximityLine.delete()
                    _level.proximityLine := na
                if not na(_level.glowBox)
                    _level.glowBox.delete()
                    _level.glowBox := na
                this.transferTo(purgedArray, i)
                _hasPurgedSome := true
            else if not na(_level.originTime)
                _inProximity = math.abs(close - _level.price) <= proximityThreshold
                if _inProximity and enable_proximity
                    _endTime = f_projectedTime(extender_end)
                    if na(_level.proximityLine)
                        _level.proximityLine := line.new(_level.originTime, _level.price, _endTime, _level.price, xloc = xloc.bar_time, color = _level.col, width = _level.lineWidth, style = ln_style)
                    else
                        _level.proximityLine.set_x2(_endTime)
                    if enable_glow
                        _heightOffset = frx ? syminfo.mintick * glow_width / 4 * _level.lineWidth * resolve_auto_width() : syminfo.mintick * glow_width * _level.lineWidth * resolve_auto_width()
                        if na(_level.glowBox)
                            _level.glowBox := box.new(_level.originTime, _level.price + _heightOffset, _endTime, _level.price - _heightOffset, border_color = na, bgcolor = color.new(_level.col, glow_transp), xloc = xloc.bar_time)
                        else
                            _level.glowBox.set_right(_endTime)
                    else if not na(_level.glowBox)
                        _level.glowBox.delete()
                        _level.glowBox := na
                else
                    if not na(_level.proximityLine)
                        _level.proximityLine.delete()
                        _level.proximityLine := na
                    if not na(_level.glowBox)
                        _level.glowBox.delete()
                        _level.glowBox := na
    _hasPurgedSome
 
method clearLevels(array<Level> this) =>
    _size = this.size()
    if _size > 0
        for i = _size - 1 to 0 by 1
            _level = this.remove(i)
            _level.line.delete()
            if not na(_level.proximityLine)
                _level.proximityLine.delete()
            if not na(_level.glowBox)
                _level.glowBox.delete()
 
method updateCountdownLabels(array<Level> this, int delayMinutes) =>
    if showCountdown
        _size = this.size()
        if _size > 0
            _delayMs = delayMinutes * 60 * 1000
            _barProgress = barstate.isrealtime ? (timenow - time) : 0 
            for _level in this
                if not na(_level.purgeTime) and not na(_level.lbl)
                    _elapsed = time - _level.purgeTime + _barProgress
                    _remaining = _delayMs - _elapsed
                    if _remaining > 0
                        _level.lbl.set_text(f_formatTime(_remaining))
                        _level.lbl.set_x(bar_index + 12)
 
method clearExpiredPurgedLevels(array<Level> this, int delayMinutes, int delayBars) =>
    _size = this.size()
    if _size > 0
        _delayMs = delayMinutes * 60 * 1000
        for i = _size - 1 to 0 by 1
            _level = this.get(i)
            _expired = _level.isPivot ? (not na(_level.purgeBar) and (bar_index - _level.purgeBar >= delayBars)) : (not na(_level.purgeTime) and (time - _level.purgeTime >= _delayMs))
            if _expired
                _level.line.delete()
                if not na(_level.lbl)
                    _level.lbl.delete()
                if not na(_level.proximityLine)
                    _level.proximityLine.delete()
                if not na(_level.glowBox)
                    _level.glowBox.delete()
                this.remove(i)
 
var Origin origin1 = Origin.new()
var Origin origin2 = Origin.new()
var Origin origin3 = Origin.new()
var Origin origin4 = Origin.new()
var Origin origin5 = Origin.new()
var Origin origin6 = Origin.new()
 
tf1Changed = timeframe.change(tf1)
tf2Changed = timeframe.change(tf2)
tf3Changed = timeframe.change(tf3)
tf4Changed = timeframe.change(tf4)
tf5Changed = timeframe.change(tf5)
tf6Changed = timeframe.change(tf6)
 
[originHigh1, originHighTime1, originLow1, originLowTime1] = origin1.trackOrigin(tf1Changed)
[originHigh2, originHighTime2, originLow2, originLowTime2] = origin2.trackOrigin(tf2Changed)
[originHigh3, originHighTime3, originLow3, originLowTime3] = origin3.trackOrigin(tf3Changed)
[originHigh4, originHighTime4, originLow4, originLowTime4] = origin4.trackOrigin(tf4Changed)
[originHigh5, originHighTime5, originLow5, originLowTime5] = origin5.trackOrigin(tf5Changed)
[originHigh6, originHighTime6, originLow6, originLowTime6] = origin6.trackOrigin(tf6Changed)
 
if is_tf6 and f_isHigherTimeframe(tf6) and tf6Changed
    f_createLevels(prevHigh6, prevLow6, upperColorTF6, lowerColorTF6, widthTF6, timeframe.in_seconds(tf6), originHighTime6, originLowTime6)
if is_tf5 and f_isHigherTimeframe(tf5) and tf5Changed
    f_createLevels(prevHigh5, prevLow5, upperColorTF5, lowerColorTF5, widthTF5, timeframe.in_seconds(tf5), originHighTime5, originLowTime5)
if is_tf4 and f_isHigherTimeframe(tf4) and tf4Changed
    f_createLevels(prevHigh4, prevLow4, upperColorTF4, lowerColorTF4, widthTF4, timeframe.in_seconds(tf4), originHighTime4, originLowTime4)
if is_tf3 and f_isHigherTimeframe(tf3) and tf3Changed
    f_createLevels(prevHigh3, prevLow3, upperColorTF3, lowerColorTF3, widthTF3, timeframe.in_seconds(tf3), originHighTime3, originLowTime3)
if is_tf2 and f_isHigherTimeframe(tf2) and tf2Changed
    f_createLevels(prevHigh2, prevLow2, upperColorTF2, lowerColorTF2, widthTF2, timeframe.in_seconds(tf2), originHighTime2, originLowTime2)
if is_tf1 and f_isHigherTimeframe(tf1) and tf1Changed
    f_createLevels(prevHigh1, prevLow1, upperColorTF1, lowerColorTF1, widthTF1, timeframe.in_seconds(tf1), originHighTime1, originLowTime1)
 
pivotHi = ta.pivothigh(high, pivotBarsLeft, pivotBarsRight)
pivotLo = ta.pivotlow(low, pivotBarsLeft, pivotBarsRight)
if enablePivots
    if not na(pivotHi)
        f_createPivotLevel(pivotHi, true)
        f_trimPivotLevels(pivotQueueMin)
    if not na(pivotLo)
        f_createPivotLevel(pivotLo, false)
        f_trimPivotLevels(pivotQueueMin)
 
plotshape(showPivotDots and not na(pivotHi) ? high : na, 'Pivot High', shape.square, location.abovebar, na, text = '●', textcolor = pivotDotColor, offset = -pivotBarsRight, size = size.tiny, show_last = pivotDotLookback, display = display.all - display.status_line)
plotshape(showPivotDots and not na(pivotLo) ? low : na, 'Pivot Low', shape.square, location.belowbar, na, text = '●', textcolor = pivotDotColor, offset = -pivotBarsRight, size = size.tiny, show_last = pivotDotLookback, display = display.all - display.status_line)
 
if barstate.islast
    highsArray.updatePosition()
    lowsArray.updatePosition()
    purgedArray.updatePositionPurged()
 
hasPurgedSomeHighs = highsArray.updateLevels(purgedArray, true)
hasPurgedSomeLows = lowsArray.updateLevels(purgedArray, false)
 
purgedArray.updateCountdownLabels(purgeDelayMinutes)
purgedArray.clearExpiredPurgedLevels(purgeDelayMinutes, pivotDelayBars)

← 返回列表