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)
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.
Script de código aberto
No verdadeiro espirito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam entendê-lo e verificá-lo. Parabéns ao autor Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações e regida pelas Regras da Casa.
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.