GEX Levels + Breakout Structure + Session AVWAP — ES/SPX/SPY

TLADe_TradeLikeaDealer · study · 377 行 · 点赞 2,441 · TradingView 原页

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

Pine Script

// GEX Levels Dashboard - ES/SPX/SPY Gamma Exposure Levels
// Data exported in ES Futures terms - Select your ticker in settings
// Alert system contribution by @_prodigy_dev
// v6.8: TURNOVER FIX - Closest GEX levels to spot protected, profile bars always visible
//@version=6
indicator("GEX Levels Dashboard - ES/SPX/SPY Gamma Exposure", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500)
 
// ============== INPUTS ==============
groupTicker = "Ticker Settings"
groupGen = "General Settings"
groupLevels = "Level Visibility"
groupLines = "Price Levels Style"
groupCol = "Colors"
groupAlerts = "Alerts"
 
// TICKER SELECTION
tickerChoice = input.string("ES", "Display Ticker", options=["ES", "SPX", "SPY"], group=groupTicker, tooltip="Select the instrument to display levels in. Data is exported in ES terms and converted based on this selection.")
 
// ES-SPX Spread captured at export time
var float esSpxSpread = 24
 
// v6.5: UNIFIED DATA INPUT - Format: L:levels|P:profile
// Paste data to update BOTH levels AND profile
gexDataInput = input.text_area("L:6980,ZG,ZERO GAMMA,Zero Gamma~Key pivot where dealer gamma flips~Price magnet,0;6984,MP,MAX PAIN,Max Pain~Strike with maximum option pain~Expiry target,0;6987,EH,EM HIGH,Expected Move HIGH~1-sigma upper boundary~Statistical resistance,0;6896,EL,EM LOW,Expected Move LOW~1-sigma lower boundary~Statistical support,0;7003,VH,VOL HIGH,Vol Band HIGH~Volatility-based resistance~ZG + 25% EM,0;6957,VL,VOL LOW,Vol Band LOW~Volatility-based support~ZG - 25% EM,0;6999,CW,Call Wall,Strike: 6999~From Spot: +0.62%~Tot GEX: 768.51M~C/P Ratio: 6.1~Hold: 68% | Break: 32%,768.5;7049,CW,Call Wall,Strike: 7049~From Spot: +1.34%~Tot GEX: 824.87M~C/P Ratio: 30.8~Hold: 68% | Break: 32%,824.9;7054,CW,Call Wall,Strike: 7054~From Spot: +1.41%~Tot GEX: 731.20M~C/P Ratio: 141.5~Hold: 66% | Break: 34%,731.2;6974,PW,Put Wall,Strike: 6974~From Spot: +0.26%~Tot GEX: -202.88M~C/P Ratio: 0.5~Hold: 66% | Break: 34%,202.9;7024,CW,Call Wall,Strike: 7024~From Spot: +0.98%~Tot GEX: 309.51M~C/P Ratio: 8.3~Hold: 64% | Break: 36%,309.5;6899,PW,Put Wall,Strike: 6899~From Spot: -0.82%~Tot GEX: -1.11B~C/P Ratio: 0.0~Hold: 49% | Break: 51%,1112.6;6924,PW,Put Wall,Strike: 6924~From Spot: -0.46%~Tot GEX: -410.32M~C/P Ratio: 0.1~Hold: 51% | Break: 49%,410.3;6949,PW,Put Wall,Strike: 6949~From Spot: -0.10%~Tot GEX: -404.18M~C/P Ratio: 0.1~Hold: 62% | Break: 38%,404.2;6884,PW,Put Wall,Strike: 6884~From Spot: -1.04%~Tot GEX: -227.84M~C/P Ratio: 0.0~Hold: 64% | Break: 36%,227.8;6914,PW,Put Wall,Strike: 6914~From Spot: -0.60%~Tot GEX: -157.34M~C/P Ratio: 0.2~Hold: 52% | Break: 48%,157.3;6954,PW,Put Wall,Strike: 6954~From Spot: -0.03%~Tot GEX: -21.59M~C/P Ratio: 0.8~Hold: 65% | Break: 35%,21.6;6944,PW,Put Wall,Strike: 6944~From Spot: -0.17%~Tot GEX: -26.27M~C/P Ratio: 0.7~Hold: 62% | Break: 38%,26.3;6874,PW,Put Wall,Strike: 6874~From Spot: -1.18%~Tot GEX: -130.40M~C/P Ratio: 0.1~Hold: 58% | Break: 42%,130.4;7027,PDH,PDH,Prior Day High~Previous session high~Key resistance,0;6886,PDL,PDL,Prior Day Low~Previous session low~Key support,0;7043,PWH,PWH,Prior Week High~Previous week high~Major resistance,0;6879,PWL,PWL,Prior Week Low~Previous week low~Major support,0|P:6524,-0.1,-1;6574,-0.3,-1;6624,-0.3,-1;6674,-0.1,-1;6704,-0.1,-1;6709,-0.1,-1;6714,-0.1,-1;6724,-0.4,-1;6729,-0.1,-1;6734,-0.1,-1;6739,-0.3,-1;6744,-0.7,-1;6749,-0.7,-1;6754,-0.2,-1;6764,-0.2,-1;6769,-0.1,-1;6774,-0.7,-1;6779,-0.1,-1;6784,-2.3,-1;6789,-0.1,-1;6794,-2.6,-1;6799,-0.3,-1;6804,-0.2,-1;6809,-0.7,-1;6814,-0.2,-1;6819,-0.3,-1;6824,-1.4,-1;6829,-0.3,-1;6834,-0.3,-1;6839,-0.5,-1;6844,-0.3,-1;6849,-1.1,-1;6854,-0.3,-1;6859,-0.2,-1;6864,-0.4,-1;6869,-0.6,-1;6874,-1.2,-1;6879,-0.4,-1;6884,-2.0,-1;6889,-0.3,-1;6894,-0.8,-1;6899,-10.0,-1;6904,-0.4,-1;6909,-0.9,-1;6914,-1.4,-1;6919,-0.7,-1;6924,-3.7,-1;6929,-0.6,-1;6934,-0.6,-1;6939,-0.2,-1;6944,-0.2,-1;6949,-3.6,-1;6954,-0.2,-1;6959,-0.6,-1;6969,-0.2,-1;6974,-1.8,-1;6979,1.1,1;6984,-9.0,-1;6989,0.2,1;6994,0.4,1;6999,6.9,1;7004,0.5,1;7014,1.2,1;7019,0.6,1;7024,2.8,1;7029,1.7,1;7034,1.3,1;7039,0.7,1;7044,1.4,1;7049,7.4,1;7054,6.6,1;7059,1.2,1;7064,1.5,1;7069,1.2,1;7074,6.0,1;7079,0.5,1;7084,0.9,1;7089,0.5,1;7094,0.9,1;7099,0.8,1;7104,0.5,1;7109,0.4,1;7114,0.4,1;7119,0.4,1;7124,0.9,1;7129,2.2,1;7134,2.5,1;7139,0.3,1;7144,0.3,1;7149,0.3,1;7154,0.4,1;7164,0.4,1;7169,0.2,1;7174,0.4,1;7184,0.2,1;7194,0.1,1;7199,0.2,1;7224,0.1,1", title="GEX Data (copy/paste to update)", group=groupGen, tooltip="Paste new data to update levels and profile.")
 
// Level Toggles
showGexLevels = input.bool(true, "Show GEX Levels (Call/Put Walls)", group=groupLevels)
showSystemLevels = input.bool(true, "Show System Levels (ZG, MaxPain, EM, VolBands)", group=groupLevels)
showStructureLevels = input.bool(true, "Show Structure Levels (PDH/PDL/PWH/PWL)", group=groupLevels)
 
// v6.5: Max Visible GEX Levels (System/Structure always visible)
maxLevelsChoice = input.string("10", "Max GEX Levels", options=["5", "10", "15", "20", "25", "30", "All"], group=groupLevels, tooltip="Maximum Call/Put Walls to display. System and Structure levels are always shown.")
int maxVisibleLevels = maxLevelsChoice == "All" ? 999 : int(str.tonumber(maxLevelsChoice))
 
// v6.3: VISIBILITY FILTER (by @_prodigy_dev)
showOnlyNear = input.bool(false, "Show only levels near price", group=groupLevels, tooltip="Hide levels that are far from current price to reduce chart clutter")
nearPct = input.float(3.0, "  ↳ Radius (%)", step=0.5, minval=0.5, maxval=10.0, group=groupLevels, tooltip="Only show levels within this % of current price")
 
// v6.5: GEX MAGNITUDE THRESHOLD
enableThreshold = input.bool(false, "Enable GEX Threshold Filter", group=groupLevels, tooltip="Hide weak GEX levels below a minimum magnitude. Useful to focus on the most significant support/resistance zones.")
gexThreshold = input.float(50.0, "  ↳ Min GEX Magnitude (M)", step=10.0, minval=0.0, maxval=500.0, group=groupLevels, tooltip="Minimum absolute GEX value in millions. Levels with |Tot GEX| below this are hidden. Typical range: 20-100M for significant levels.")
 
// Profile Settings
profileWidth = input.int(50, "GEX Chart Width", group=groupGen, inline="gex1")
barThickness = input.int(8, "GEX Bar Height", group=groupGen, inline="gex1")
profileOffset = input.int(15, "Chart Offset", group=groupGen, inline="gex2")
 
// Color Theme (for levels)
colorScheme = input.string("Wall Street Classic", "Color Theme", options=["Wall Street Classic", "Boreal", "Lady Trader"], group=groupCol, tooltip="Colors for GEX levels and profile bars")
 
// Bar Color Style (for profile bars)
barColorStyle = input.string("Theme Colors", "Bar Color Style", options=["Theme Colors", "Greyscale", "Custom"], group=groupCol, tooltip="Theme = follows skin (inverted: Call=Bear, Put=Bull). Greyscale = neutral. Custom = you choose")
customBarCall = input.color(#ef4444, "Custom Call Bar", group=groupCol, inline="custbar")
customBarPut = input.color(#22c55e, "Custom Put Bar", group=groupCol, inline="custbar")
 
// Fixed colors for non-GEX levels
colorZeroGamma = input.color(#9ca3af, "Zero Gamma", group=groupCol, inline="sys1")
colorMaxPain = input.color(#ef4444, "Max Pain", group=groupCol, inline="sys1")
colorEM = input.color(#3b82f6, "Expected Move", group=groupCol, inline="sys2")
colorVolBand = input.color(#9ca3af, "Vol Bands", group=groupCol, inline="sys2")
colorStructure = input.color(#9ca3af, "Structure Levels", group=groupCol)
 
// Line Style
lineLeftExt = input.int(50, "Line Left Extension", minval=1, group=groupLines)
lineStyleInput = input.string("Dotted", "Line Style", options=["Solid", "Dashed", "Dotted"], group=groupLines)
lineWidth = input.int(1, "Line Width", minval=1, maxval=4, group=groupLines)
 
// v6.3: ALERTS (by @_prodigy_dev)
enableAlerts = input.bool(true, "Enable Level Cross Alerts", group=groupAlerts, tooltip="Get notified when price crosses key GEX levels")
 
var string lineStyleChoice = line.style_dotted
if lineStyleInput == "Solid"
    lineStyleChoice := line.style_solid
else if lineStyleInput == "Dashed"
    lineStyleChoice := line.style_dashed
 
// ============== TICKER CONVERSION FUNCTIONS ==============
f_convertPrice(float esPrice) =>
    float result = esPrice
    if tickerChoice == "SPX"
        result := esPrice - esSpxSpread
    else if tickerChoice == "SPY"
        result := (esPrice - esSpxSpread) / 10
    result
 
f_formatPrice(float esPrice) =>
    float converted = f_convertPrice(esPrice)
    string result = ""
    if tickerChoice == "SPY"
        result := str.tostring(converted, "#.##")
    else
        result := str.tostring(converted, "#")
    result
 
// ============== STATE VARIABLES ==============
var forceBoxes = array.new_box()
var line[] strategicLines = array.new_line()
var label[] strategicLabels = array.new_label()
var string prevGexData = ""
var int prevProfileWidth = 0
var int prevBarThickness = 0
var int prevProfileOffset = 0
var string prevColorScheme = ""
var string prevBarColorStyle = ""
var string prevLineStyle = ""
var int prevLineWidth = 0
var int prevLineLeftExt = 0
var string prevTickerChoice = ""
var label timestampLabel = na
var int lastDrawnBarIndex = -1
 
bool newBar = bar_index != lastDrawnBarIndex
bool settingsChanged = gexDataInput != prevGexData or profileWidth != prevProfileWidth or barThickness != prevBarThickness or profileOffset != prevProfileOffset or colorScheme != prevColorScheme or barColorStyle != prevBarColorStyle or lineStyleInput != prevLineStyle or lineWidth != prevLineWidth or lineLeftExt != prevLineLeftExt or tickerChoice != prevTickerChoice
 
// ============== HELPER COLORS ==============
f_charToNum(string char) =>
    char == "0" ? 0. : char == "1" ? 1. : char == "2" ? 2. : char == "3" ? 3. : char == "4" ? 4. : char == "5" ? 5. : char == "6" ? 6. : char == "7" ? 7. : char == "8" ? 8. : char == "9" ? 9. : char == "a" or char == "A" ? 10. : char == "b" or char == "B" ? 11. : char == "c" or char == "C" ? 12. : char == "d" or char == "D" ? 13. : char == "e" or char == "E" ? 14. : 15.
 
f_hexToColor(string hex, int transp = 0) =>
    r = f_charToNum(str.substring(hex, 1, 2)) * 16 + f_charToNum(str.substring(hex, 2, 3))
    g = f_charToNum(str.substring(hex, 3, 4)) * 16 + f_charToNum(str.substring(hex, 4, 5))
    b = f_charToNum(str.substring(hex, 5, 6)) * 16 + f_charToNum(str.substring(hex, 6, 7))
    color.rgb(int(r), int(g), int(b), transp)
 
f_clear_force() =>
    for b in forceBoxes
        box.delete(b)
    array.clear(forceBoxes)
    for l in strategicLines
        line.delete(l)
    array.clear(strategicLines)
    for lbl in strategicLabels
        label.delete(lbl)
    array.clear(strategicLabels)
    if not na(timestampLabel)
        label.delete(timestampLabel)
 
// ============== DYNAMIC GEX COLORS ==============
color colorPos = na
color colorNeg = na
 
if colorScheme == "Boreal"
    colorPos := #22d3ee
    colorNeg := #f472b6
else if colorScheme == "Wall Street Classic"
    colorPos := #22c55e
    colorNeg := #ef4444
else if colorScheme == "Lady Trader"
    colorPos := #2dd4bf
    colorNeg := #c084fc
 
// ============== DRAW EVERYTHING ==============
if barstate.islast and (settingsChanged or newBar)
    f_clear_force()
    lastDrawnBarIndex := bar_index
    string tickerLabel = tickerChoice
    timestampLabel := label.new(bar_index + profileOffset, high + (syminfo.mintick * 50), "GEX " + tickerLabel, color=color.new(color.gray, 100), style=label.style_label_center, textcolor=color.new(color.gray, 40), size=size.tiny)
 
    // ============== PARSE DATA FORMAT L:|P: ==============
    string levelsData = ""
    string profileData = ""
    
    if str.contains(gexDataInput, "|P:")
        int pipePos = str.pos(gexDataInput, "|P:")
        string beforePipe = str.substring(gexDataInput, 0, pipePos)
        profileData := str.substring(gexDataInput, pipePos + 3)
        if str.startswith(beforePipe, "L:")
            levelsData := str.substring(beforePipe, 2)
    else
        // Legacy format - just profile data
        profileData := gexDataInput
 
    // ============== PARSE AND DRAW DYNAMIC LEVELS ==============
    if levelsData != ""
        string[] levelPairs = str.split(levelsData, ";")
        // v6.8 FIX: Split 50/50 above/below current price + PROTECT closest to spot
        int gexAboveDrawn = 0
        int gexBelowDrawn = 0
        int halfMax = math.ceil(maxVisibleLevels / 2)
        
        // v6.8: Find closest GEX level above and below spot (PROTECTED from limit)
        float closestAbove = na
        float closestAboveDist = 999999.0
        float closestBelow = na
        float closestBelowDist = 999999.0
        
        for lvlPair in levelPairs
            string[] lvlParts = str.split(lvlPair, ",")
            if array.size(lvlParts) >= 3
                float lvlStrike = str.tonumber(array.get(lvlParts, 0))
                string lvlType = array.get(lvlParts, 1)
                if not na(lvlStrike)
                    bool isGex = lvlType == "CW" or lvlType == "PW" or lvlType == "GL"
                    if isGex
                        float convertedLvl = f_convertPrice(lvlStrike)
                        float dist = math.abs(convertedLvl - close)
                        if convertedLvl > close and dist < closestAboveDist
                            closestAboveDist := dist
                            closestAbove := convertedLvl
                        else if convertedLvl <= close and dist < closestBelowDist
                            closestBelowDist := dist
                            closestBelow := convertedLvl
        
        // Main drawing loop
        for lvlPair in levelPairs
            string[] lvlParts = str.split(lvlPair, ",")
            if array.size(lvlParts) >= 3
                float lvlStrike = str.tonumber(array.get(lvlParts, 0))
                string lvlType = array.get(lvlParts, 1)
                string lvlLabel = array.get(lvlParts, 2)
                // v6.5: 4th field is tooltip (uses ~ for newlines), 5th is magnitude in millions
                string lvlTooltip = array.size(lvlParts) >= 4 ? str.replace_all(array.get(lvlParts, 3), "~", "\n") : ""
                float lvlMagnitude = array.size(lvlParts) >= 5 ? str.tonumber(array.get(lvlParts, 4)) : 0.0
                
                if not na(lvlStrike)
                    float convertedLvl = f_convertPrice(lvlStrike)
                    bool inRange = not showOnlyNear or (math.abs(close - convertedLvl) / close * 100.0 <= nearPct)
                    
                    // Determine category and check toggle
                    bool isGex = lvlType == "CW" or lvlType == "PW" or lvlType == "GL"
                    bool isSystem = lvlType == "ZG" or lvlType == "MP" or lvlType == "EH" or lvlType == "EL" or lvlType == "VH" or lvlType == "VL"
                    bool isStructure = lvlType == "PDH" or lvlType == "PDL" or lvlType == "PWH" or lvlType == "PWL"
                    
                    // v6.5: Threshold filter (only applies to GEX levels, magnitude 0 = always show)
                    bool passesThreshold = not enableThreshold or not isGex or lvlMagnitude >= gexThreshold or lvlMagnitude == 0.0
                    
                    // v6.8: Check if above or below current price
                    bool isAbovePrice = convertedLvl > close
                    bool isBelowPrice = convertedLvl <= close
                    
                    // v6.8: Is this level protected? (closest to spot)
                    bool isProtected = (not na(closestAbove) and convertedLvl == closestAbove) or (not na(closestBelow) and convertedLvl == closestBelow)
                    
                    bool shouldShow = false
                    // v6.8 FIX: Protected levels always show, others follow 50/50 limit
                    if isGex and showGexLevels and passesThreshold
                        if isProtected
                            shouldShow := true  // Protected: always show
                        else if isAbovePrice and gexAboveDrawn < halfMax
                            shouldShow := true
                        else if isBelowPrice and gexBelowDrawn < halfMax
                            shouldShow := true
                    else if isSystem and showSystemLevels
                        shouldShow := true
                    else if isStructure and showStructureLevels
                        shouldShow := true
                    
                    if shouldShow and inRange
                        // Determine color and style based on type
                        color lvlColor = color.gray
                        int styleCode = 0
                        string finalTooltip = lvlTooltip
                        
                        if lvlType == "CW"
                            bool flipped = convertedLvl < close
                            lvlColor := flipped ? colorPos : colorNeg
                            styleCode := flipped ? 1 : 0
                            if not isProtected
                                if isAbovePrice
                                    gexAboveDrawn += 1
                                else
                                    gexBelowDrawn += 1
                            finalTooltip := lvlTooltip + "\n" + (flipped ? "FLIPPED (Res→Sup)" : "Resistance")
                        else if lvlType == "PW"
                            bool flipped = convertedLvl > close
                            lvlColor := flipped ? colorNeg : colorPos
                            styleCode := flipped ? 1 : 0
                            if not isProtected
                                if isAbovePrice
                                    gexAboveDrawn += 1
                                else
                                    gexBelowDrawn += 1
                            finalTooltip := lvlTooltip + "\n" + (flipped ? "FLIPPED (Sup→Res)" : "Support")
                        else if lvlType == "ZG"
                            lvlColor := colorZeroGamma
                            styleCode := 0
                        else if lvlType == "MP"
                            lvlColor := colorMaxPain
                            styleCode := 2
                        else if lvlType == "EH" or lvlType == "EL"
                            lvlColor := colorEM
                            styleCode := 1
                        else if lvlType == "VH" or lvlType == "VL"
                            lvlColor := colorVolBand
                            styleCode := 2
                        else if isStructure
                            lvlColor := colorStructure
                            styleCode := 2
                        
                        // Draw line and label with rich tooltip
                        array.push(strategicLines, line.new(bar_index - lineLeftExt, convertedLvl, bar_index + profileOffset, convertedLvl, color=lvlColor, style=styleCode == 2 ? line.style_dotted : styleCode == 1 ? line.style_dashed : line.style_solid, width=lineWidth))
                        string displayLabel = f_formatPrice(lvlStrike) + " | " + lvlType + " | " + lvlLabel
                        array.push(strategicLabels, label.new(bar_index - lineLeftExt, convertedLvl, displayLabel, color=lvlColor, style=label.style_label_left, textcolor=color.white, size=size.small, tooltip=finalTooltip))
 
    // ============== DRAW PROFILE BARS ==============
    if profileData != ""
        string forzaData = str.replace_all(profileData, "\n", "")
        string[] forzaPairs = str.split(forzaData, ";")
        
        float[] forzaStrikes = array.new_float()
        float[] forzaValues = array.new_float()
        float[] forzaSigns = array.new_float()
        
        for pair in forzaPairs
            string[] parts = str.split(pair, ",")
            if array.size(parts) == 3
                array.push(forzaStrikes, str.tonumber(array.get(parts, 0)))
                array.push(forzaValues, str.tonumber(array.get(parts, 1)))
                array.push(forzaSigns, str.tonumber(array.get(parts, 2)))
        
        if array.size(forzaValues) > 0
            float maxAbsForza = 10.0 
            float boxHeight = barThickness * syminfo.mintick 
            int x_zero = bar_index + profileOffset
 
            for i = 0 to array.size(forzaValues) - 1
                float esStrike = array.get(forzaStrikes, i)
                float convertedStrike = f_convertPrice(esStrike)
                float forza = array.get(forzaValues, i)
                float sign = array.get(forzaSigns, i)
                
                int barLength = int((forza / maxAbsForza) * profileWidth)
                float intensity = math.abs(forza) / maxAbsForza
                int fillTransp = int(80 - (intensity * 50)) 
                
                // v6.5: Bar colors INVERTED - Call=Bear(colorNeg), Put=Bull(colorPos)
                color barCall = barColorStyle == "Greyscale" ? #a0a0a0 : barColorStyle == "Custom" ? customBarCall : colorNeg
                color barPut = barColorStyle == "Greyscale" ? #505050 : barColorStyle == "Custom" ? customBarPut : colorPos
                color baseColor = sign >= 0 ? barCall : barPut
                color fillColor = color.new(baseColor, fillTransp)
                color borderColor = color.new(baseColor, 0)
                
                box forzaBox = box.new(left=x_zero, top=convertedStrike + (boxHeight / 2), right=x_zero + barLength, bottom=convertedStrike - (boxHeight / 2), border_color=borderColor, border_width=1, bgcolor=fillColor)
                array.push(forceBoxes, forzaBox)
 
    prevGexData := gexDataInput
    prevProfileWidth := profileWidth
    prevBarThickness := barThickness
    prevProfileOffset := profileOffset
    prevColorScheme := colorScheme
    prevBarColorStyle := barColorStyle
    prevLineStyle := lineStyleInput
    prevLineWidth := lineWidth
    prevLineLeftExt := lineLeftExt
    prevTickerChoice := tickerChoice
 
// ============== ALERT SYSTEM (by @_prodigy_dev) ==============
var float[] alertPrices = array.new_float(0)
 
if barstate.isfirst
    array.push(alertPrices, f_convertPrice(7053.60))
    array.push(alertPrices, f_convertPrice(7048.60))
    array.push(alertPrices, f_convertPrice(7023.60))
    array.push(alertPrices, f_convertPrice(6998.60))
    array.push(alertPrices, f_convertPrice(6973.60))
    array.push(alertPrices, f_convertPrice(6953.60))
    array.push(alertPrices, f_convertPrice(6948.60))
    array.push(alertPrices, f_convertPrice(6943.60))
    array.push(alertPrices, f_convertPrice(6923.60))
    array.push(alertPrices, f_convertPrice(6913.60))
    array.push(alertPrices, f_convertPrice(6898.60))
    array.push(alertPrices, f_convertPrice(6883.60))
    array.push(alertPrices, f_convertPrice(6873.60))
    array.push(alertPrices, f_convertPrice(6979.79))
 
if enableAlerts and array.size(alertPrices) > 0
    for i = 0 to array.size(alertPrices) - 1
        float price = array.get(alertPrices, i)
        bool inRange = not showOnlyNear or (math.abs(close - price) / close * 100.0 <= nearPct)
        if inRange
            bool touched = (high >= price and low <= price)
            bool crossUp = touched and (close >= price) and (open < price or low < price)
            bool crossDown = touched and (close <= price) and (open > price or high > price)
            if crossUp or crossDown
                string dir = crossUp ? "⬆️ Cross UP " : "⬇️ Cross DOWN "
                string crossTxt = dir + str.tostring(price, format.mintick) + " | " + str.tostring(time, "HH:mm")
                alert(crossTxt, alert.freq_once_per_bar)

← 返回列表