OPEN-SOURCE SCRIPT
3-Candle Swing Highs & Lows

//version=5
indicator("3-Candle Swing Highs & Lows", overlay=true, max_lines_count=1000)
// Inputs
highColor = input.color(color.red, "Swing High (Unbroken)")
highBreachCol = input.color(color.green, "Swing High (Breached)")
lowColor = input.color(color.blue, "Swing Low (Unbroken)")
lowBreachCol = input.color(color.orange, "Swing Low (Breached)")
// Arrays for storing lines and prices
var line[] highLines = array.new_line()
var float[] highPrices = array.new_float()
var line[] lowLines = array.new_line()
var float[] lowPrices = array.new_float()
// --- Swing High condition ---
// We check candle[1] (the middle one) against candle[2] and candle[0]
isSwingHigh = high[1] > high[2] and high[1] > high[0]
// --- Swing Low condition ---
isSwingLow = low[1] < low[2] and low[1] < low[0]
// If swing high found (confirmed after bar closes)
if isSwingHigh
newHigh = line.new(bar_index - 1, high[1], bar_index, high[1], extend=extend.right, color=highColor, width=2)
array.push(highLines, newHigh)
array.push(highPrices, high[1])
// If swing low found (confirmed after bar closes)
if isSwingLow
newLow = line.new(bar_index - 1, low[1], bar_index, low[1], extend=extend.right, color=lowColor, width=2)
array.push(lowLines, newLow)
array.push(lowPrices, low[1])
// Update line colours for swing highs
for i = 0 to array.size(highLines) - 1
ln = array.get(highLines, i)
lvl = array.get(highPrices, i)
if close > lvl
line.set_color(ln, highBreachCol)
else
line.set_color(ln, highColor)
// Update line colours for swing lows
for i = 0 to array.size(lowLines) - 1
ln = array.get(lowLines, i)
lvl = array.get(lowPrices, i)
if close < lvl
line.set_color(ln, lowBreachCol)
else
line.set_color(ln, lowColor)
indicator("3-Candle Swing Highs & Lows", overlay=true, max_lines_count=1000)
// Inputs
highColor = input.color(color.red, "Swing High (Unbroken)")
highBreachCol = input.color(color.green, "Swing High (Breached)")
lowColor = input.color(color.blue, "Swing Low (Unbroken)")
lowBreachCol = input.color(color.orange, "Swing Low (Breached)")
// Arrays for storing lines and prices
var line[] highLines = array.new_line()
var float[] highPrices = array.new_float()
var line[] lowLines = array.new_line()
var float[] lowPrices = array.new_float()
// --- Swing High condition ---
// We check candle[1] (the middle one) against candle[2] and candle[0]
isSwingHigh = high[1] > high[2] and high[1] > high[0]
// --- Swing Low condition ---
isSwingLow = low[1] < low[2] and low[1] < low[0]
// If swing high found (confirmed after bar closes)
if isSwingHigh
newHigh = line.new(bar_index - 1, high[1], bar_index, high[1], extend=extend.right, color=highColor, width=2)
array.push(highLines, newHigh)
array.push(highPrices, high[1])
// If swing low found (confirmed after bar closes)
if isSwingLow
newLow = line.new(bar_index - 1, low[1], bar_index, low[1], extend=extend.right, color=lowColor, width=2)
array.push(lowLines, newLow)
array.push(lowPrices, low[1])
// Update line colours for swing highs
for i = 0 to array.size(highLines) - 1
ln = array.get(highLines, i)
lvl = array.get(highPrices, i)
if close > lvl
line.set_color(ln, highBreachCol)
else
line.set_color(ln, highColor)
// Update line colours for swing lows
for i = 0 to array.size(lowLines) - 1
ln = array.get(lowLines, i)
lvl = array.get(lowPrices, i)
if close < lvl
line.set_color(ln, lowBreachCol)
else
line.set_color(ln, lowColor)
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.