Round Number Levels [QuantAlgo]

QuantAlgo · study · 317 行 · 点赞 90 · TradingView 原页

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

Pine Script

// This script is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © QuantAlgo
 
//@version=6
indicator("Round Number Levels [QuantAlgo]", overlay = true, max_lines_count = 500, max_labels_count = 250)
 
//              ╔════════════════════════════════╗              //
//              ║      USER-DEFINED SETTINGS     ║              //
//              ╚════════════════════════════════╝              //
 
var string level_settings    = "════════ Level Settings ════════"
var string reaction_settings = "════════ Reaction Settings ════════"
var string visual_settings   = "════════ Visualization Settings ════════"
 
tooltip_step_mode    = "How the distance between round levels is set. Auto scales the step to the price's order of magnitude by dividing the power of ten at or below the price by Auto Divisions, so the levels stay proportionate on any symbol, and the step changes by a factor of ten when price moves into a new power of ten, such as from 9,500 to 10,500. Custom keeps the fixed distance set by Custom Step on every bar, which suits markets with established round numbers, such as whole dollars on a stock or specific pip intervals on a currency pair."
tooltip_auto_div     = "Number of levels per power of ten in Auto mode. At 10, a price between 10,000 and 100,000 gets levels every 1,000 and a price between 1 and 10 gets levels every 0.1. Values that divide a power of ten evenly, such as 2, 4, 5, 20, 25, or 50, keep every level on a round number, while others, such as 3 or 6, place levels at repeating fractions, such as every 3,333.33 on a five-digit price. Higher values (20-100) produce finer levels, such as every 500 or every 100 on a five-digit price, while lower values (1, 2, or 5) keep only the most prominent numbers. Only used when Step Mode is set to Auto."
tooltip_custom_step  = "Fixed distance between round levels in price units, such as 1000 for levels every 1,000 points, 5 for levels every five dollars on a stock, or 0.01 for levels every 100 pips on most currency pairs. Only used when Step Mode is set to Custom."
tooltip_grid_range   = "Which round levels are drawn. Around Price draws only Levels Each Side around the current price, so the grid follows price and keeps the chart focused on the nearest levels. Full History draws every level within the high-low range of the bars loaded on the chart, along with Levels Each Side around the current price, so the levels where price traded earlier remain drawn for reference as price moves on. Each side of price holds at most 125 levels, which keeps the lines and labels within TradingView's drawing limits, so with a fine step over a wide price range the levels farthest from price are left out. In Auto mode the whole grid takes the latest step, so in price areas from another power of ten it can be coarser or finer than the step that touches there were judged with."
tooltip_count        = "Number of round levels drawn on each side of the current price, counting the nearest level at or below price on the lower side so both sides hold the same number. Under Around Price these are the only levels drawn, so higher values map a wider range for context while lower values keep the chart focused on the levels nearest price. Under Full History it sets the minimum on each side, so when price trades near the edge of the loaded range, levels beyond it still show. Levels at or below zero are left out."
tooltip_half         = "Enable/disable the half levels, dotted lines halfway between each pair of drawn round levels, such as 75,500 between 75,000 and 76,000. They mark finer reference points between the main levels and are not used in the touch statistics or alerts."
tooltip_window       = "Number of bars after a touch over which its reaction is judged, as set by Hold Rule. A touch is a closed bar whose range reaches a round level after a close more than the Min Approach Distance away from it, and the side of that close sets whether the level was approached from above or below. When a bar reaches several levels, the touch is taken at the one furthest from that close, and when it reaches levels on both sides of that close, the side the bar closed toward decides. Touches are followed one at a time, so a touch during an open window is treated as part of that reaction and is neither marked nor counted again. Higher values (10-20) judge the reaction over a longer stretch, while lower values (1-3) capture the immediate response."
tooltip_min_approach = "A bar that reaches a round level counts as a touch only when the previous close was more than this distance from that level, measured as a percentage of the step, so bars drifting along a level are not counted as fresh tests. At 0, any bar that reaches a level counts unless the previous close sat exactly on it, while higher values (25-50) keep only touches that arrive from farther away."
tooltip_hold_rule    = "How each touch is judged once the Reaction Window passes. Window Close counts it as held if the close at the end of the window is at the level or on the side price approached from, so a close through the level along the way still counts as held if price recovers by then. No Close Through counts it as held only if no close from the touch bar to the end of the window went through the level, so any close through it counts as a break. No Wick Through counts it as held only if price never traded through the level over those same bars, wicks included, the view of a stop placed just beyond it, so even a wick through that closes back counts as a break. Each rule is stricter than the one before it, so on the same touches the held shares read equal or lower in that order. A close or wick counts as through the level only when it clears the Break Buffer, and at a buffer of 0 even the touch bar's own wick breaks the touch under No Wick Through if it trades past the level, so that rule is meant to be paired with a buffer set to the stop distance being tested."
tooltip_buffer       = "Distance beyond a touched level, as a percentage of the level's price, that a close must exceed to count as through the level when touches are judged, or a wick under No Wick Through, where it works as the distance of a stop beyond the level. At 0, any move beyond the level counts, while higher values (0.1-0.5) treat shallow moves through it as noise, so only decisive ones count as breaks. It applies to the touch statistics and the held figures in alert messages, not to the cross alert, which fires on any close through a level."
tooltip_max_touches  = "Number of most recent judged touches kept for each side. Once a side reaches this count, each new judged touch replaces its oldest one, so the Held and Broke shares follow a rolling sample. Lower values (50-100) make the shares reflect recent behavior, while higher values draw on a longer history. Each side can only collect the touches within the bars loaded on the chart, so the Count row in the dashboard shows how many are in use."
tooltip_approach     = "Distance to the nearest round level, as a percentage of price, at which the approach alert fires. The alert fires on the closed bar where the close first comes within this distance after a close farther away, giving notice ahead of a possible touch. Lower values (0.05-0.1) wait until price is almost at the level, while higher values (0.5-1) give earlier notice. The Any alert() function call option sends each approach, cross, and touch with the round level's price and direction, adding for approaches and touches the share of judged touches from that side that held."
tooltip_color_preset = "Pre-configured color schemes for different chart themes and visual preferences. Classic uses traditional green and red. Aqua provides ocean-inspired blue and orange. Cosmic offers futuristic cyan and purple. Cyber features cool cyan and warm orange contrast. Neon delivers high-contrast yellow and magenta for maximum visibility. Each preset applies its first color to the round levels, their labels, the touch markers, the step figure, and the Held figures in the dashboard, and its second color to the Broke figures, while Custom uses the Held Color, Broke Color, and Round Level Color set below. The Half Level Color applies under every preset. On light chart backgrounds, colors too bright to stand out are darkened automatically, and on dark backgrounds colors too dark to stand out are lightened, so every preset and custom color stays readable on either theme."
tooltip_held         = "Color applied to the Held figures in the dashboard, the share of judged touches where the level held. Use a vibrant color to set holds apart from breaks. Its shade adapts to light and dark chart backgrounds as described under Color Preset. Only used when Color Preset is set to Custom."
tooltip_broke        = "Color applied to the Broke figures in the dashboard, the share of judged touches where the level broke. Use a warning color to highlight breaks. Its shade adapts to light and dark chart backgrounds as described under Color Preset. Only used when Color Preset is set to Custom."
tooltip_level_color  = "Color of the round levels, their labels, the touch markers, and the step figure in the dashboard, set separately from the Held Color so the level grid can take a color of its own. Its shade adapts to light and dark chart backgrounds as described under Color Preset. Only used when Color Preset is set to Custom."
tooltip_half_color   = "Color of the dotted half levels. It applies under every Color Preset, so the half levels stay distinct from the round levels whichever preset is selected. Its shade adapts to light and dark chart backgrounds as described under Color Preset."
tooltip_labels       = "Enable/disable the labels at the right end of each round level, which show the level's price and its distance from the current price as a percentage of price. Distances gain decimal places as they shrink, so levels very close to price stay distinguishable."
tooltip_touch_marks  = "Enable/disable the circles above the bar that mark each touch starting a reaction window. Each one prints once the bar closes, stays in place, and takes the color of the round levels."
tooltip_dashboard    = "Enable/disable the dashboard, which lists the current step, the nearest round levels above and below price with their distances, and how touches of round levels have resolved, split by the side price approached from. Count is the number of judged touches in the sample, and Held and Broke split them by how each resolved under the Hold Rule and Break Buffer. The figures cover the bars loaded on the chart, which depend on the symbol's history, the chart timeframe, and the TradingView plan. Hovering over each heading explains its figure."
tooltip_dash_pos     = "Position on the chart where the dashboard is anchored, covering every corner, the middle of each edge, and the center. Tables from other indicators placed at the same position overlap with it. Only applies when Show Dashboard is turned on."
tooltip_text_size    = "Text size for the level labels and every row and figure in the dashboard. Tiny and Small keep them compact on the chart, while Normal and Large suit presentation and screen recording."
 
string stepModeInput    = input.string("Auto", "Step Mode", group = level_settings, options = ["Auto", "Custom"], tooltip = tooltip_step_mode)
int autoDivInput        = input.int(10, "Auto Divisions", group = level_settings, minval = 1, maxval = 1000, tooltip = tooltip_auto_div)
float customStepInput   = input.float(1000.0, "Custom Step", group = level_settings, minval = 0.00000001, tooltip = tooltip_custom_step)
string gridRangeInput   = input.string("Around Price", "Grid Range", group = level_settings, options = ["Around Price", "Full History"], tooltip = tooltip_grid_range)
int countInput          = input.int(5, "Levels Each Side", group = level_settings, minval = 1, maxval = 125, tooltip = tooltip_count)
bool halfInput          = input.bool(true, "Show Half Levels", group = level_settings, tooltip = tooltip_half)
 
int windowInput         = input.int(5, "Reaction Window (Bars)", group = reaction_settings, minval = 1, tooltip = tooltip_window)
float minApproachInput  = input.float(10.0, "Min Approach Distance (% of Step)", group = reaction_settings, minval = 0.0, step = 5.0, tooltip = tooltip_min_approach)
string holdRuleInput    = input.string("Window Close", "Hold Rule", group = reaction_settings, options = ["Window Close", "No Close Through", "No Wick Through"], tooltip = tooltip_hold_rule)
float bufferInput       = input.float(0.0, "Break Buffer (%)", group = reaction_settings, minval = 0.0, step = 0.05, tooltip = tooltip_buffer)
int maxTouchesInput     = input.int(100000, "Max Touches per Side", group = reaction_settings, minval = 1, maxval = 100000, tooltip = tooltip_max_touches)
float approachInput     = input.float(0.25, "Approach Alert (%)", group = reaction_settings, minval = 0.0, step = 0.05, tooltip = tooltip_approach)
 
string colorPreset      = input.string("Custom", "Color Preset", group = visual_settings, options = ["Custom", "Classic", "Aqua", "Cosmic", "Cyber", "Neon"], tooltip = tooltip_color_preset)
color heldCustomInput   = input.color(#00ffaa, "Held Color", group = visual_settings, tooltip = tooltip_held)
color brokeCustomInput  = input.color(#ff0000, "Broke Color", group = visual_settings, tooltip = tooltip_broke)
color levelColorInput   = input.color(#00ffaa, "Round Level Color", group = visual_settings, tooltip = tooltip_level_color)
color halfColorInput    = input.color(#8c8c8c, "Half Level Color", group = visual_settings, tooltip = tooltip_half_color)
bool labelsInput        = input.bool(true, "Show Level Labels", group = visual_settings, tooltip = tooltip_labels)
bool touchMarksInput    = input.bool(true, "Show Touch Markers", group = visual_settings, tooltip = tooltip_touch_marks)
bool tableInput         = input.bool(true, "Show Dashboard", group = visual_settings, tooltip = tooltip_dashboard)
string tablePosInput    = input.string("Top Right", "Dashboard Position", group = visual_settings, options = ["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], tooltip = tooltip_dash_pos)
string textSizeInput    = input.string("Small", "Text Size", group = visual_settings, options = ["Tiny", "Small", "Normal", "Large"], tooltip = tooltip_text_size)
 
//              ╔════════════════════════════════╗              //
//              ║      PRESET CONFIGURATION      ║              //
//              ╚════════════════════════════════╝              //
 
[heldColor, brokeColor] = switch colorPreset
    "Classic" => [#00ff00, #ff0000]
    "Aqua" => [#00d4ff, #ff8c00]
    "Cosmic" => [#49ffce, #9932cc]
    "Cyber" => [#00cccc, #ff6600]
    "Neon" => [#ffff00, #ff00ff]
    => [heldCustomInput, brokeCustomInput]
 
color levelColor = colorPreset == "Custom" ? levelColorInput : heldColor
 
string textSize = switch textSizeInput
    "Tiny"   => size.tiny
    "Normal" => size.normal
    "Large"  => size.large
    => size.small
 
float bgBright = (color.r(chart.bg_color) * 299.0 + color.g(chart.bg_color) * 587.0 + color.b(chart.bg_color) * 114.0) / 1000.0
bool lightBg   = bgBright >= 128.0
 
themed(color c, float lightCap, float darkFloor) =>
    float cB = (color.r(c) * 299.0 + color.g(c) * 587.0 + color.b(c) * 114.0) / 1000.0
    if lightBg and cB > lightCap
        color.rgb(color.r(c) * lightCap / cB, color.g(c) * lightCap / cB, color.b(c) * lightCap / cB)
    else if not lightBg and cB < darkFloor
        float t = (darkFloor - cB) / (255.0 - cB)
        color.rgb(color.r(c) + (255.0 - color.r(c)) * t, color.g(c) + (255.0 - color.g(c)) * t, color.b(c) + (255.0 - color.b(c)) * t)
    else
        c
 
color heldText  = themed(heldColor, 100.0, 70.0)
color brokeText = themed(brokeColor, 100.0, 70.0)
color levelText = themed(levelColor, 100.0, 70.0)
color halfText  = themed(halfColorInput, 100.0, 70.0)
 
//              ╔════════════════════════════════╗              //
//              ║            FUNCTIONS           ║              //
//              ╚════════════════════════════════╝              //
 
distPct(float level, float price, float tolerance) =>
    math.abs(level - price) <= tolerance ? 0.0 : (level - price) / price * 100.0
 
pctText(float v) =>
    int dec = v != 0 ? math.max(2, math.ceil(-math.log10(math.abs(v))) + 1) : 2
    str.tostring(v, "#." + str.repeat("#", dec)) + "%"
 
fmtPct(float v) =>
    (v > 0 ? "+" : "") + pctText(v)
 
shareText(int part, int total) =>
    total > 0 ? str.tostring(float(part) / total * 100.0, "#.#") + "%" : "n/a"
 
countText(float v, string unit) =>
    str.tostring(v, "#.#") + " " + unit + (v == 1 ? "" : "s")
 
beyondLevel(float price, float level, int side, float bufferPct, float tolerance) =>
    float gap = level * bufferPct / 100.0 + tolerance
    side == 1 ? price < level - gap : price > level + gap
 
sideText(string side, int held, int total) =>
    string basis = " (" + holdRuleInput + ", " + countText(windowInput, "bar") + (bufferInput > 0 ? ", " + pctText(bufferInput) + " buffer" : "") + ")"
    total > 0 ? side + ", " + shareText(held, total) + " of " + str.tostring(total) + (total == 1 ? " judged touch" : " judged touches") + " held" + basis : "No touches " + str.lower(side) + " have been judged yet"
 
//              ╔════════════════════════════════╗              //
//              ║          LEVEL ENGINE          ║              //
//              ╚════════════════════════════════╝              //
 
float tol         = syminfo.mintick * 0.001
float magnitude   = close > 0 ? math.pow(10.0, math.floor(math.log10(close) + 1e-12)) : na
float step        = stepModeInput == "Custom" ? customStepInput : magnitude / autoDivInput
bool stepOk       = close > 0 and not na(step) and step > 0
 
int kBelow        = stepOk ? math.floor((close + tol) / step) : na
float levelBelow  = stepOk ? kBelow * step : na
float levelAbove  = stepOk ? (kBelow + 1) * step : na
float distBelow   = stepOk ? distPct(levelBelow, close, tol) : na
float distAbove   = stepOk ? distPct(levelAbove, close, tol) : na
float nearestDist = stepOk ? math.min(distAbove, -distBelow) : na
 
bool levelCrossed = barstate.isconfirmed and stepOk and not na(close[1]) and math.floor((close + tol) / step) != math.floor((close[1] + tol) / step)
 
//              ╔════════════════════════════════╗              //
//              ║       REACTION STATISTICS      ║              //
//              ╚════════════════════════════════╝              //
 
var bool active              = false
var float tLevel             = na
var int tSide                = 0
var int tBar                 = na
var bool tThrough            = false
var bool tWickThrough        = false
var array<int> aboveOutcomes = array.new<int>()
var array<int> belowOutcomes = array.new<int>()
var int aboveHeld            = 0
var int belowHeld            = 0
 
bool levelTouched = false
 
if barstate.isconfirmed
    if active
        bool through = beyondLevel(close, tLevel, tSide, bufferInput, tol)
        tThrough     := tThrough or through
        tWickThrough := tWickThrough or beyondLevel(tSide == 1 ? low : high, tLevel, tSide, bufferInput, tol)
        if bar_index - tBar >= windowInput
            bool held = switch holdRuleInput
                "No Close Through" => not tThrough
                "No Wick Through"  => not tWickThrough
                => not through
            int heldVal         = held ? 1 : 0
            array<int> outcomes = tSide == 1 ? aboveOutcomes : belowOutcomes
            if array.size(outcomes) >= maxTouchesInput
                int dropped = array.shift(outcomes)
                if tSide == 1
                    aboveHeld -= dropped
                else
                    belowHeld -= dropped
            array.push(outcomes, heldVal)
            if tSide == 1
                aboveHeld += heldVal
            else
                belowHeld += heldVal
            active := false
    if not active and stepOk and not na(close[1])
        int kLow          = math.ceil((low - tol) / step)
        int kHigh         = math.floor((high + tol) / step)
        float downLevel   = kLow * step
        float upLevel     = kHigh * step
        float minGap      = minApproachInput / 100.0 * step + tol
        bool hitFromAbove = kLow <= kHigh and close[1] - downLevel > minGap
        bool hitFromBelow = kLow <= kHigh and upLevel - close[1] > minGap
        if hitFromAbove or hitFromBelow
            bool takeAbove = hitFromAbove and (not hitFromBelow or close <= close[1])
            active       := true
            tLevel       := takeAbove ? downLevel : upLevel
            tSide        := takeAbove ? 1 : -1
            tBar         := bar_index
            tThrough     := beyondLevel(close, tLevel, tSide, bufferInput, tol)
            tWickThrough := beyondLevel(tSide == 1 ? low : high, tLevel, tSide, bufferInput, tol)
            levelTouched := true
 
int fromAbove = array.size(aboveOutcomes)
int fromBelow = array.size(belowOutcomes)
 
//              ╔════════════════════════════════╗              //
//              ║          VISUALIZATION         ║              //
//              ╚════════════════════════════════╝              //
 
var array<line> levelLines   = array.new<line>()
var array<label> levelLabels = array.new<label>()
var float histHigh           = high
var float histLow            = low
 
histHigh := math.max(histHigh, high)
histLow  := math.min(histLow, low)
 
if barstate.islast
    for ln in levelLines
        line.delete(ln)
    array.clear(levelLines)
    for lb in levelLabels
        label.delete(lb)
    array.clear(levelLabels)
    if stepOk
        bool fullHistory = gridRangeInput == "Full History"
        int kFrom        = fullHistory ? math.max(kBelow - 124, math.min(kBelow + 1 - countInput, math.ceil((histLow - tol) / step))) : kBelow + 1 - countInput
        int kTo          = fullHistory ? math.min(kBelow + 125, math.max(kBelow + countInput, math.floor((histHigh + tol) / step))) : kBelow + countInput
        for k = kFrom to kTo
            float lv = k * step
            float hv = lv + step / 2.0
            if lv > tol
                array.push(levelLines, line.new(bar_index - 1, lv, bar_index + 10, lv, extend = extend.left, color = color.new(levelText, 40), width = 1))
                if labelsInput
                    array.push(levelLabels, label.new(bar_index + 10, lv, str.tostring(lv, format.mintick) + " (" + fmtPct(distPct(lv, close, tol)) + ")", style = label.style_label_left, color = color.new(chart.bg_color, 100), textcolor = levelText, size = textSize))
            if halfInput and k < kTo and hv > tol
                array.push(levelLines, line.new(bar_index - 1, hv, bar_index + 10, hv, extend = extend.left, color = color.new(halfText, 70), style = line.style_dotted))
 
plotshape(touchMarksInput and levelTouched, "Level Touch", shape.circle, location.abovebar, color.new(levelText, 40), size = size.tiny, display = display.pane)
 
//              ╔════════════════════════════════╗              //
//              ║            DASHBOARD           ║              //
//              ╚════════════════════════════════╝              //
 
string tablePos = switch tablePosInput
    "Top Left"      => position.top_left
    "Top Center"    => position.top_center
    "Middle Left"   => position.middle_left
    "Middle Center" => position.middle_center
    "Middle Right"  => position.middle_right
    "Bottom Left"   => position.bottom_left
    "Bottom Center" => position.bottom_center
    "Bottom Right"  => position.bottom_right
    => position.top_right
 
var table dash = tableInput ? table.new(tablePos, 3, 7, border_width = 1, border_color = color.new(chart.fg_color, 85), frame_width = 1, frame_color = color.new(chart.fg_color, 70)) : na
 
if barstate.islast and not na(dash)
    color hdrBg  = color.new(chart.fg_color, 85)
    color cellBg = color.new(chart.bg_color, 10)
    color txt    = chart.fg_color
    table.cell(dash, 0, 0, "Round Number Step", text_color = txt, bgcolor = hdrBg, text_size = textSize, text_halign = text.align_left, tooltip = "Distance between round levels on the latest bar, set from the price's order of magnitude in Auto mode or by Custom Step in Custom mode.")
    table.cell(dash, 1, 0, stepOk ? str.tostring(step, format.mintick) : "n/a", text_color = levelText, bgcolor = hdrBg, text_size = textSize)
    table.cell(dash, 2, 0, stepModeInput, text_color = txt, bgcolor = hdrBg, text_size = textSize)
    table.cell(dash, 0, 1, "Next Level Above", text_color = txt, bgcolor = cellBg, text_size = textSize, text_halign = text.align_left, tooltip = "Nearest round level above the current price, with its distance as a percentage of price.")
    table.cell(dash, 1, 1, stepOk ? str.tostring(levelAbove, format.mintick) : "n/a", text_color = txt, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 2, 1, stepOk ? fmtPct(distAbove) : "n/a", text_color = txt, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 0, 2, "Next Level Below", text_color = txt, bgcolor = cellBg, text_size = textSize, text_halign = text.align_left, tooltip = "Nearest round level at or below the current price, with its distance as a percentage of price.")
    table.cell(dash, 1, 2, stepOk ? str.tostring(levelBelow, format.mintick) : "n/a", text_color = txt, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 2, 2, stepOk ? fmtPct(distBelow) : "n/a", text_color = txt, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 0, 3, "Touches (" + countText(windowInput, "Bar") + ")", text_color = txt, bgcolor = hdrBg, text_size = textSize, text_halign = text.align_left, tooltip = "Touches of round levels judged once the Reaction Window passed, split by the side price approached from.")
    table.cell(dash, 1, 3, "From Above", text_color = txt, bgcolor = hdrBg, text_size = textSize, tooltip = "Touches where price came down to the level from above, testing it as support.")
    table.cell(dash, 2, 3, "From Below", text_color = txt, bgcolor = hdrBg, text_size = textSize, tooltip = "Touches where price came up to the level from below, testing it as resistance.")
    table.cell(dash, 0, 4, "Count", text_color = txt, bgcolor = cellBg, text_size = textSize, text_halign = text.align_left, tooltip = "Number of judged touches from each side in the sample, up to Max Touches per Side.")
    table.cell(dash, 1, 4, str.tostring(fromAbove), text_color = txt, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 2, 4, str.tostring(fromBelow), text_color = txt, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 0, 5, "Held", text_color = txt, bgcolor = cellBg, text_size = textSize, text_halign = text.align_left, tooltip = "Share of judged touches that held under the Hold Rule and Break Buffer.")
    table.cell(dash, 1, 5, shareText(aboveHeld, fromAbove), text_color = heldText, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 2, 5, shareText(belowHeld, fromBelow), text_color = heldText, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 0, 6, "Broke", text_color = txt, bgcolor = cellBg, text_size = textSize, text_halign = text.align_left, tooltip = "Share of judged touches that broke, with price through the level beyond the Break Buffer under the Hold Rule.")
    table.cell(dash, 1, 6, shareText(fromAbove - aboveHeld, fromAbove), text_color = brokeText, bgcolor = cellBg, text_size = textSize)
    table.cell(dash, 2, 6, shareText(fromBelow - belowHeld, fromBelow), text_color = brokeText, bgcolor = cellBg, text_size = textSize)
 
//              ╔════════════════════════════════╗              //
//              ║             ALERTS             ║              //
//              ╚════════════════════════════════╝              //
 
bool approaching  = barstate.isconfirmed and stepOk and nearestDist <= approachInput and nz(nearestDist[1]) > approachInput
string symbolText = syminfo.prefix + ":" + syminfo.ticker + " - " + timeframe.period
 
alertcondition(approaching, title = "Approaching Round Level", message = "Round Number Levels: APPROACH of a round level with a close within the approach distance on {{exchange}}:{{ticker}} - {{interval}}")
alertcondition(levelCrossed, title = "Round Level Crossed", message = "Round Number Levels: CROSS of a round level with a close through it on {{exchange}}:{{ticker}} - {{interval}}")
alertcondition(levelTouched, title = "Round Level Touched", message = "Round Number Levels: TOUCH of a round level starting a new reaction window on {{exchange}}:{{ticker}} - {{interval}}")
 
if approaching
    bool aboveNearer = distAbove < -distBelow
    alert("Round Number Levels: approach of the " + str.tostring(aboveNearer ? levelAbove : levelBelow, format.mintick) + " round level from " + (aboveNearer ? "below" : "above") + " with a close " + pctText(nearestDist) + " away on " + symbolText + ". " + (aboveNearer ? sideText("From below", belowHeld, fromBelow) : sideText("From above", aboveHeld, fromAbove)) + ".", alert.freq_once_per_bar_close)
if levelCrossed
    bool crossedUp = math.floor((close + tol) / step) > math.floor((close[1] + tol) / step)
    alert("Round Number Levels: cross " + (crossedUp ? "up with a close at or above the " + str.tostring(levelBelow, format.mintick) : "down with a close below the " + str.tostring(levelAbove, format.mintick)) + " round level on " + symbolText + ".", alert.freq_once_per_bar_close)
if levelTouched
    alert("Round Number Levels: touch of the " + str.tostring(tLevel, format.mintick) + " round level from " + (tSide == 1 ? "above" : "below") + " on " + symbolText + ". " + (tSide == 1 ? sideText("From above", aboveHeld, fromAbove) : sideText("From below", belowHeld, fromBelow)) + ".", alert.freq_once_per_bar_close)
 
//              ╔════════════════════════════════╗              //
//              ║           CREATED BY           ║              //
//              ╚════════════════════════════════╝              //
 
// ██████╗ ██╗   ██╗ █████╗ ███╗   ██╗████████╗     █████╗ ██╗      ██████╗  ██████╗ 
//██╔═══██╗██║   ██║██╔══██╗████╗  ██║╚══██╔══╝    ██╔══██╗██║     ██╔════╝ ██╔═══██╗
//██║   ██║██║   ██║███████║██╔██╗ ██║   ██║       ███████║██║     ██║  ███╗██║   ██║
//██║▄▄ ██║██║   ██║██╔══██║██║╚██╗██║   ██║       ██╔══██║██║     ██║   ██║██║   ██║
//╚██████╔╝╚██████╔╝██║  ██║██║ ╚████║   ██║       ██║  ██║███████╗╚██████╔╝╚██████╔╝
// ╚══▀▀═╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝       ╚═╝  ╚═╝╚══════╝ ╚═════╝  ╚═════╝

← 返回列表