The Victor Special V1

CunnyFuntTrades · study · 104 行 · 点赞 28 · TradingView 原页

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

Pine Script

//@version=6
indicator("The Victor Special V1", shorttitle="Victor V1", overlay=true, max_boxes_count=11, max_labels_count=12)
 
freshFill = input.color(color.new(#8B7CFF, 86), "Fresh FVG")
freshLine = input.color(color.new(#8B7CFF, 35), "Fresh FVG border")
bullFill = input.color(color.new(#16B8A6, 86), "Bullish inversion")
bearFill = input.color(color.new(#F05A67, 86), "Bearish inversion")
bullLine = input.color(color.new(#16B8A6, 35), "Bullish inversion border")
bearLine = input.color(color.new(#F05A67, 35), "Bearish inversion border")
zoneBars = input.int(12, "Gap display length (bars)", minval=1, maxval=500)
sequenceCount = input.int(2, "Fresh gaps per direction", minval=1, maxval=5)
 
isM1 = timeframe.isminutes and timeframe.multiplier == 1
newBullGap = isM1 and barstate.isconfirmed and low > high[2]
newBearGap = isM1 and barstate.isconfirmed and high < low[2]
 
var array<box> gaps = array.new<box>()
var array<label> markers = array.new<label>()
var array<float> tops = array.new<float>()
var array<float> bottoms = array.new<float>()
var array<int> directions = array.new<int>()
var box lastInvertedGap = na
var label lastInvertedMarker = na
var label lastInversionSignal = na
var float lastInvertedTop = na
var float lastInvertedBottom = na
var bool lastInversionBull = false
 
// Clear an IFVG after a confirmed close through its opposite edge.
if isM1 and barstate.isconfirmed and not na(lastInvertedGap)
    invalidated = lastInversionBull ? close < lastInvertedBottom : close > lastInvertedTop
    if invalidated
        box.delete(lastInvertedGap)
        label.delete(lastInvertedMarker)
        label.delete(lastInversionSignal)
        lastInvertedGap := na
        lastInvertedMarker := na
        lastInversionSignal := na
        lastInvertedTop := na
        lastInvertedBottom := na
 
if newBullGap or newBearGap
    direction = newBullGap ? 1 : -1
    top = newBullGap ? low : low[2]
    bottom = newBullGap ? high[2] : high
    sameCount = 0
    oldestSame = -1
    if array.size(gaps) > 0
        for j = 0 to array.size(gaps) - 1
            if array.get(directions, j) == direction
                sameCount += 1
                if oldestSame == -1
                    oldestSame := j
    if sameCount >= sequenceCount
        box.delete(array.remove(gaps, oldestSame))
        label.delete(array.remove(markers, oldestSame))
        array.remove(tops, oldestSame)
        array.remove(bottoms, oldestSame)
        array.remove(directions, oldestSame)
    gap = box.new(bar_index - 2, top, bar_index + zoneBars, bottom, xloc=xloc.bar_index, extend=extend.none, bgcolor=freshFill, border_color=freshLine, border_width=1)
    marker = label.new(bar_index + zoneBars, (top + bottom) / 2, "FVG", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, color=color.new(#8B7CFF, 10), textcolor=color.white, size=size.small)
    array.push(gaps, gap)
    array.push(markers, marker)
    array.push(tops, top)
    array.push(bottoms, bottom)
    array.push(directions, direction)
 
bool bullInversion = false
bool bearInversion = false
if isM1 and barstate.isconfirmed and array.size(gaps) > 0
    i = 0
    while i < array.size(gaps)
        direction = array.get(directions, i)
        top = array.get(tops, i)
        bottom = array.get(bottoms, i)
        invertBull = direction == -1 and close > top
        invertBear = direction == 1 and close < bottom
        if invertBull or invertBear
            if not na(lastInvertedGap)
                box.delete(lastInvertedGap)
            if not na(lastInvertedMarker)
                label.delete(lastInvertedMarker)
            if not na(lastInversionSignal)
                label.delete(lastInversionSignal)
            gap = array.remove(gaps, i)
            label.delete(array.remove(markers, i))
            array.remove(tops, i)
            array.remove(bottoms, i)
            array.remove(directions, i)
            box.set_bgcolor(gap, invertBull ? bullFill : bearFill)
            box.set_border_color(gap, invertBull ? bullLine : bearLine)
            lastInvertedGap := gap
            lastInvertedTop := top
            lastInvertedBottom := bottom
            lastInversionBull := invertBull
            lastInvertedMarker := label.new(box.get_right(gap), (top + bottom) / 2, "IFVG", xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, color=invertBull ? #16B8A6 : #F05A67, textcolor=color.white, size=size.small)
            lastInversionSignal := label.new(bar_index, invertBull ? low : high, "", xloc=xloc.bar_index, yloc=invertBull ? yloc.belowbar : yloc.abovebar, style=invertBull ? label.style_triangleup : label.style_triangledown, color=invertBull ? #16B8A6 : #F05A67, textcolor=color.white, size=size.tiny)
            bullInversion := invertBull
            bearInversion := invertBear
        else
            i += 1
 
alertcondition(bullInversion, title="Bullish M1 FVG inversion", message="Bullish M1 FVG inversion: {{ticker}} @ {{close}}")
alertcondition(bearInversion, title="Bearish M1 FVG inversion", message="Bearish M1 FVG inversion: {{ticker}} @ {{close}}")

← 返回列表