OPEN-SOURCE SCRIPT
Intraday Equal Peaks Levels (final)

//version=6
indicator("Intraday Equal Peaks Levels (final)", overlay=true, max_lines_count=500, max_labels_count=500)
// ===== INPUTS =====
leftBars = input.int(5, "Bars Left", minval=1)
rightBars = input.int(5, "Bars Right", minval=1)
marketType = input.string("Crypto", "Market Type", options=["Crypto", "Stocks"])
cryptoThresh = input.float(1.0, "Crypto Threshold %", minval=0.0, maxval=3.0, step=0.1)
stockThreshC = input.int(1, "Stocks Threshold (cents)", minval=0) // 1 -> 0.01 price units
showPanel = input.bool(true, "Show Equal Peaks Panel (top-right)")
// ===== DAY CHANGE =====
isNewDay = time("D") != time("D")[1] // true on first bar of new calendar day
// ===== PIVOT DETECTION =====
pHigh = ta.pivothigh(high, leftBars, rightBars)
pLow = ta.pivotlow(low, leftBars, rightBars)
// ===== THRESHOLD CHECK =====
f_within_threshold(oldLevel, newLevel) =>
if marketType == "Stocks"
threshPrice = stockThreshC * 0.01
math.abs(newLevel - oldLevel) <= threshPrice
else
pct = oldLevel != 0 ? math.abs((newLevel - oldLevel) / oldLevel * 100.0) : 0.0
pct <= cryptoThresh
// ===== STORAGE =====
var array<line> arrLines = array.new_line()
var array<float> arrPrices = array.new_float()
var array<color> arrColors = array.new_color()
var array<int> arrTypes = array.new_int() // 1 = resistance, -1 = support
// helper to clear (delete graphical objects then clear arrays)
f_clear_all() =>
for i = array.size(arrLines) - 1 to 0
ln = array.get(arrLines, i)
if not na(ln)
line.delete(ln)
array.clear(arrLines)
array.clear(arrPrices)
array.clear(arrColors)
array.clear(arrTypes)
// reset on new calendar day
if isNewDay
f_clear_all()
// ===== ADD PEAK (grouping logic) =====
f_add_peak(level, isRes) =>
grouped = false
targetType = isRes ? 1 : -1
// scan existing lines; only group with same type
for i = 0 to array.size(arrPrices) - 1
if array.get(arrTypes, i) == targetType
oldLvl = array.get(arrPrices, i)
if f_within_threshold(oldLvl, level)
grouped := true
// mark the existing line as yellow (if not already)
if array.get(arrColors, i) != color.yellow
array.set(arrColors, i, color.yellow)
lnobj = array.get(arrLines, i)
line.set_color(lnobj, color.yellow)
break
// if not grouped -> create new line from this pivot
if not grouped
startBar = bar_index - rightBars
lncol = isRes ? color.red : color.green
ln = line.new(x1 = startBar, y1 = level, x2 = bar_index, y2 = level, xloc = xloc.bar_index, extend = extend.right, color = lncol, width = 2)
array.push(arrLines, ln)
array.push(arrPrices, level)
array.push(arrColors, lncol)
array.push(arrTypes, targetType)
// ===== DELETE LINES WHEN BROKEN (close beyond) =====
for i = array.size(arrPrices) - 1 to 0
lvl = array.get(arrPrices, i)
typ = array.get(arrTypes, i)
ln = array.get(arrLines, i)
// For resistance (1): delete when close > lvl
if typ == 1 and close > lvl
line.delete(ln)
array.remove(arrLines, i)
array.remove(arrPrices, i)
array.remove(arrColors, i)
array.remove(arrTypes, i)
// For support (-1): delete when close < lvl
else if typ == -1 and close < lvl
line.delete(ln)
array.remove(arrLines, i)
array.remove(arrPrices, i)
array.remove(arrColors, i)
array.remove(arrTypes, i)
// ===== HANDLE NEW PIVOTS =====
if not na(pHigh)
f_add_peak(pHigh, true)
if not na(pLow)
f_add_peak(pLow, false)
// ===== INFO PANEL (top-right) =====
var table t = table.new(position.top_right, 1, 2, border_width = 1)
if showPanel and barstate.islast
yellow_count = 0
yellow_prices = array.new_string()
for i = 0 to array.size(arrPrices) - 1
if array.get(arrColors, i) == color.yellow
yellow_count += 1
lvl = array.get(arrPrices, i)
s = str.tostring(lvl, format.mintick)
array.push(yellow_prices, s)
priceTxt = "None"
if array.size(yellow_prices) > 0
joined = ""
for j = 0 to array.size(yellow_prices) - 1
part = array.get(yellow_prices, j)
joined := j == 0 ? part : joined + ", " + part
priceTxt := joined
table.cell(t, 0, 0, "Equal peaks: " + str.tostring(yellow_count), text_halign = text.align_left, text_size = size.small, bgcolor = color.new(color.black, 0), text_color = color.white)
table.cell(t, 0, 1, "Equal peaks price: " + priceTxt, text_halign = text.align_left, text_size = size.small, bgcolor = color.new(color.black, 0), text_color = color.white)
else
table.clear(t, 0, 0)
indicator("Intraday Equal Peaks Levels (final)", overlay=true, max_lines_count=500, max_labels_count=500)
// ===== INPUTS =====
leftBars = input.int(5, "Bars Left", minval=1)
rightBars = input.int(5, "Bars Right", minval=1)
marketType = input.string("Crypto", "Market Type", options=["Crypto", "Stocks"])
cryptoThresh = input.float(1.0, "Crypto Threshold %", minval=0.0, maxval=3.0, step=0.1)
stockThreshC = input.int(1, "Stocks Threshold (cents)", minval=0) // 1 -> 0.01 price units
showPanel = input.bool(true, "Show Equal Peaks Panel (top-right)")
// ===== DAY CHANGE =====
isNewDay = time("D") != time("D")[1] // true on first bar of new calendar day
// ===== PIVOT DETECTION =====
pHigh = ta.pivothigh(high, leftBars, rightBars)
pLow = ta.pivotlow(low, leftBars, rightBars)
// ===== THRESHOLD CHECK =====
f_within_threshold(oldLevel, newLevel) =>
if marketType == "Stocks"
threshPrice = stockThreshC * 0.01
math.abs(newLevel - oldLevel) <= threshPrice
else
pct = oldLevel != 0 ? math.abs((newLevel - oldLevel) / oldLevel * 100.0) : 0.0
pct <= cryptoThresh
// ===== STORAGE =====
var array<line> arrLines = array.new_line()
var array<float> arrPrices = array.new_float()
var array<color> arrColors = array.new_color()
var array<int> arrTypes = array.new_int() // 1 = resistance, -1 = support
// helper to clear (delete graphical objects then clear arrays)
f_clear_all() =>
for i = array.size(arrLines) - 1 to 0
ln = array.get(arrLines, i)
if not na(ln)
line.delete(ln)
array.clear(arrLines)
array.clear(arrPrices)
array.clear(arrColors)
array.clear(arrTypes)
// reset on new calendar day
if isNewDay
f_clear_all()
// ===== ADD PEAK (grouping logic) =====
f_add_peak(level, isRes) =>
grouped = false
targetType = isRes ? 1 : -1
// scan existing lines; only group with same type
for i = 0 to array.size(arrPrices) - 1
if array.get(arrTypes, i) == targetType
oldLvl = array.get(arrPrices, i)
if f_within_threshold(oldLvl, level)
grouped := true
// mark the existing line as yellow (if not already)
if array.get(arrColors, i) != color.yellow
array.set(arrColors, i, color.yellow)
lnobj = array.get(arrLines, i)
line.set_color(lnobj, color.yellow)
break
// if not grouped -> create new line from this pivot
if not grouped
startBar = bar_index - rightBars
lncol = isRes ? color.red : color.green
ln = line.new(x1 = startBar, y1 = level, x2 = bar_index, y2 = level, xloc = xloc.bar_index, extend = extend.right, color = lncol, width = 2)
array.push(arrLines, ln)
array.push(arrPrices, level)
array.push(arrColors, lncol)
array.push(arrTypes, targetType)
// ===== DELETE LINES WHEN BROKEN (close beyond) =====
for i = array.size(arrPrices) - 1 to 0
lvl = array.get(arrPrices, i)
typ = array.get(arrTypes, i)
ln = array.get(arrLines, i)
// For resistance (1): delete when close > lvl
if typ == 1 and close > lvl
line.delete(ln)
array.remove(arrLines, i)
array.remove(arrPrices, i)
array.remove(arrColors, i)
array.remove(arrTypes, i)
// For support (-1): delete when close < lvl
else if typ == -1 and close < lvl
line.delete(ln)
array.remove(arrLines, i)
array.remove(arrPrices, i)
array.remove(arrColors, i)
array.remove(arrTypes, i)
// ===== HANDLE NEW PIVOTS =====
if not na(pHigh)
f_add_peak(pHigh, true)
if not na(pLow)
f_add_peak(pLow, false)
// ===== INFO PANEL (top-right) =====
var table t = table.new(position.top_right, 1, 2, border_width = 1)
if showPanel and barstate.islast
yellow_count = 0
yellow_prices = array.new_string()
for i = 0 to array.size(arrPrices) - 1
if array.get(arrColors, i) == color.yellow
yellow_count += 1
lvl = array.get(arrPrices, i)
s = str.tostring(lvl, format.mintick)
array.push(yellow_prices, s)
priceTxt = "None"
if array.size(yellow_prices) > 0
joined = ""
for j = 0 to array.size(yellow_prices) - 1
part = array.get(yellow_prices, j)
joined := j == 0 ? part : joined + ", " + part
priceTxt := joined
table.cell(t, 0, 0, "Equal peaks: " + str.tostring(yellow_count), text_halign = text.align_left, text_size = size.small, bgcolor = color.new(color.black, 0), text_color = color.white)
table.cell(t, 0, 1, "Equal peaks price: " + priceTxt, text_halign = text.align_left, text_size = size.small, bgcolor = color.new(color.black, 0), text_color = color.white)
else
table.clear(t, 0, 0)
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.