本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CryptoNejc
//@version=6
indicator("Pivot Support & Resistance Zones [NJ]", "PSRZ", overlay = true, behind_chart = false)
// ✧═════════════════✧
// ║ INPUTS ║
// ✧═════════════════✧
const string g1 = "✧ DISPLAY ✧"
colorMode = input.string("Colored", "Color mode", options = ["Colored", "Neutral"], group = g1)
dispCandles = input.bool(true, "Color candles", group = g1)
maxBoxes = input.int(10, "Maximum zones shown", minval = 1, group = g1)
const string g2 = "✧ CALCULATION ✧"
pivotLen = input.int(40, "Swing strength", 1, group = g2)
// ✧══════════════════════✧
// ║ CALCULATION ║
// ✧══════════════════════✧
// Get pivots
pivotHigh = ta.pivothigh(pivotLen, pivotLen)
pivotLow = ta.pivotlow(pivotLen, pivotLen)
// ✧════════════════✧
// ║ PLOTS ║
// ✧════════════════✧
// Colors
longCol = colorMode == "Colored" ? color.rgb(0, 136, 100) : colorMode == "Neutral" ? color.rgb(179, 179, 179) : na
shortCol = colorMode == "Colored" ? color.rgb(120, 0, 32) : colorMode == "Neutral" ? color.rgb(60, 60, 60) : na
sigCol = close > open ? longCol : close < open ? shortCol : na
// Color candles
plotcandle(
open, high, low, close,
"Colored candles",
dispCandles ? sigCol : na,
dispCandles ? sigCol : na,
bordercolor = dispCandles ? sigCol : na,
display = display.all - display.status_line - display.price_scale)
// Display reversal zones
var array<box> boxes = array.new<box>()
atr = ta.atr(14) * 0.2
zoneAtr = atr[pivotLen]
highPrice = high[pivotLen] + (low[pivotLen] - high[pivotLen]) * 0.1
lowPrice = low[pivotLen] + (high[pivotLen] - low[pivotLen]) * 0.1
if not na(pivotHigh)
newBox = box.new(
left = bar_index - pivotLen,
top = highPrice + zoneAtr,
right = bar_index,
bottom = highPrice - zoneAtr,
xloc = xloc.bar_index,
extend = extend.right,
border_color = shortCol,
bgcolor = color.new(shortCol, 90)
)
array.push(boxes, newBox)
if not na(pivotLow)
newBox = box.new(
left = bar_index - pivotLen,
top = lowPrice + zoneAtr,
right = bar_index,
bottom = lowPrice - zoneAtr,
xloc = xloc.bar_index,
extend = extend.right,
border_color = longCol,
bgcolor = color.new(longCol, 90)
)
array.push(boxes, newBox)
while array.size(boxes) > maxBoxes
oldBox = array.shift(boxes)
box.delete(oldBox)