本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Vishal Trades Support & Resistance Zones", overlay=true, max_boxes_count=500, max_bars_back=5000)
//====================================================
// SETTINGS
//====================================================
leftBars = input.int(8, "Pivot Left Bars", minval=2, maxval=50)
rightBars = input.int(8, "Pivot Right Bars", minval=2, maxval=50)
atrLength = input.int(14, "ATR Length", minval=1)
zoneATR = input.float(0.25, "Zone Thickness (ATR)", minval=0.05, maxval=2.0, step=0.05)
showSupport = input.bool(true, "Show Support Zones")
showResistance = input.bool(true, "Show Resistance Zones")
supportColor = input.color(color.blue, "Support Color")
resistanceColor = input.color(color.red, "Resistance Color")
fillTransparency = input.int(85, "Zone Transparency", minval=0, maxval=100)
borderTransparency = input.int(10, "Border Transparency", minval=0, maxval=100)
//====================================================
// CALCULATIONS
//====================================================
atr = ta.atr(atrLength)
pivotHigh = ta.pivothigh(high, leftBars, rightBars)
pivotLow = ta.pivotlow(low, leftBars, rightBars)
//====================================================
// STORE ALL HISTORICAL ZONES
// No automatic deletion of old zones.
//====================================================
var box[] resistanceBoxes = array.new_box()
var box[] supportBoxes = array.new_box()
var bool[] resistanceActive = array.new_bool()
var bool[] supportActive = array.new_bool()
//====================================================
// CREATE NEW RESISTANCE ZONES
//====================================================
if showResistance and not na(pivotHigh) and not na(atr[rightBars])
float thickness = math.max(atr[rightBars] * zoneATR, syminfo.mintick)
box newResistance = box.new(
left=bar_index - rightBars,
top=pivotHigh,
right=bar_index,
bottom=pivotHigh - thickness,
xloc=xloc.bar_index,
extend=extend.right,
bgcolor=color.new(resistanceColor, fillTransparency),
border_color=color.new(resistanceColor, borderTransparency),
border_width=1)
array.push(resistanceBoxes, newResistance)
array.push(resistanceActive, true)
//====================================================
// CREATE NEW SUPPORT ZONES
//====================================================
if showSupport and not na(pivotLow) and not na(atr[rightBars])
float thickness = math.max(atr[rightBars] * zoneATR, syminfo.mintick)
box newSupport = box.new(
left=bar_index - rightBars,
top=pivotLow + thickness,
right=bar_index,
bottom=pivotLow,
xloc=xloc.bar_index,
extend=extend.right,
bgcolor=color.new(supportColor, fillTransparency),
border_color=color.new(supportColor, borderTransparency),
border_width=1)
array.push(supportBoxes, newSupport)
array.push(supportActive, true)
//====================================================
// STOP RESISTANCE EXTENSION WHEN BROKEN
// Keep broken zones visible historically.
//====================================================
if barstate.isconfirmed
int resistanceCount = array.size(resistanceBoxes)
if resistanceCount > 0
for i = 0 to resistanceCount - 1
if array.get(resistanceActive, i)
box currentBox = array.get(resistanceBoxes, i)
float zoneTop = box.get_top(currentBox)
if close > zoneTop
box.set_extend(currentBox, extend.none)
box.set_right(currentBox, bar_index)
array.set(resistanceActive, i, false)
//====================================================
// STOP SUPPORT EXTENSION WHEN BROKEN
// Keep broken zones visible historically.
//====================================================
if barstate.isconfirmed
int supportCount = array.size(supportBoxes)
if supportCount > 0
for i = 0 to supportCount - 1
if array.get(supportActive, i)
box currentBox = array.get(supportBoxes, i)
float zoneBottom = box.get_bottom(currentBox)
if close < zoneBottom
box.set_extend(currentBox, extend.none)
box.set_right(currentBox, bar_index)
array.set(supportActive, i, false)
//====================================================
// ALERT CONDITIONS
//====================================================
resistanceBreak = ta.crossover(close, ta.valuewhen(not na(pivotHigh), pivotHigh, 0))
supportBreak = ta.crossunder(close, ta.valuewhen(not na(pivotLow), pivotLow, 0))
alertcondition(resistanceBreak, title="Resistance Breakout", message="Resistance breakout on {{ticker}}")
alertcondition(supportBreak, title="Support Breakdown", message="Support breakdown on {{ticker}}")