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 автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения.
Отказ от ответственности
Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.