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)
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。