Gold Precision | Psychological Zones

krisskross18 · study · 44 行 · 点赞 49 · TradingView 原页

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

Pine Script

//@version=6
indicator("Gold Precision | Psychological Zones", overlay = true, max_boxes_count = 100)
 
// Price-based zones: identical levels on every chart timeframe.
spacing = input.float(25.0, "Psychological spacing ($)", minval = 0.1)
width = input.float(3.0, "Total zone width ($)", minval = 0.1)
count = input.int(4, "Levels above and below price", minval = 1, maxval = 20)
history = input.int(150, "Visible rectangle length (bars)", minval = 10, maxval = 500)
majorSpacing = input.float(100.0, "Major spacing ($)", minval = 1)
showPrice = input.bool(true, "Show level price")
quarterFill = input.color(color.new(color.aqua, 85), "Quarter-zone fill")
majorFill = input.color(color.new(color.blue, 78), "Major-zone fill")
 
var array<box> zones = array.new<box>()
 
if barstate.islast
    for oldZone in zones
        box.delete(oldZone)
    array.clear(zones)
 
    float nearest = math.round(close / spacing) * spacing
    float halfWidth = width / 2.0
 
    for offset = -count to count
        float level = nearest + offset * spacing
        bool major = math.abs(level / majorSpacing - math.round(level / majorSpacing)) < 0.00001
        color border = major ? color.blue : color.new(color.blue, 40)
        color fill = major ? majorFill : quarterFill
        string caption = showPrice ? str.tostring(level, format.mintick) : ""
 
        box zone = box.new(
             left = math.max(0, bar_index - history),
             top = level + halfWidth,
             right = bar_index + 10,
             bottom = level - halfWidth,
             border_color = border,
             border_width = major ? 2 : 1,
             extend = extend.right,
             bgcolor = fill,
             text = caption,
             text_color = border,
             text_size = size.tiny,
             text_halign = text.align_right)
        array.push(zones, zone)

← 返回列表