OPEN-SOURCE SCRIPT
Мой скрипт

//version=5
indicator("Market Structure BOS/CHoCH", overlay=true, max_labels_count=500)
// === Settings ===
swingLen = input.int(3, "Swing Length", minval=1)
showBOS = input.bool(true, "Show BOS")
showCHoCH = input.bool(true, "Show CHoCH")
// === Identify swing highs and lows ===
var float lastHigh = na
var float lastLow = na
swingHigh = ta.pivothigh(high, swingLen, swingLen)
swingLow = ta.pivotlow(low, swingLen, swingLen)
if not na(swingHigh)
lastHigh := swingHigh
if not na(swingLow)
lastLow := swingLow
// === Determine HH, HL, LH, LL ===
hh = not na(swingHigh) and swingHigh > lastHigh
hl = not na(swingLow) and swingLow > lastLow
lh = not na(swingHigh) and swingHigh < lastHigh
ll = not na(swingLow) and swingLow < lastLow
// === Plot labels for structure points ===
if hh
label.new(bar_index, swingHigh, "HH", style=label.style_label_down, color=color.green, textcolor=color.white, yloc=yloc.abovebar)
if hl
label.new(bar_index, swingLow, "HL", style=label.style_label_up, color=color.green, textcolor=color.white, yloc=yloc.belowbar)
if lh
label.new(bar_index, swingHigh, "LH", style=label.style_label_down, color=color.red, textcolor=color.white, yloc=yloc.abovebar)
if ll
label.new(bar_index, swingLow, "LL", style=label.style_label_up, color=color.red, textcolor=color.white, yloc=yloc.belowbar)
// === BOS (Break of Structure) detection ===
bosUp = ta.crossover(close, lastHigh)
bosDown = ta.crossunder(close, lastLow)
if showBOS and bosUp
label.new(bar_index, high, "BOS ↑", style=label.style_label_down, color=color.blue, textcolor=color.white, yloc=yloc.abovebar)
if showBOS and bosDown
label.new(bar_index, low, "BOS ↓", style=label.style_label_up, color=color.blue, textcolor=color.white, yloc=yloc.belowbar)
// === CHoCH (Change of Character) detection ===
var int trend = 0 // 1 = uptrend, -1 = downtrend
if hh or hl
trend := 1
if lh or ll
trend := -1
chochUp = trend == -1 and bosUp
chochDown = trend == 1 and bosDown
if showCHoCH and chochUp
label.new(bar_index, high, "CHoCH ↑", style=label.style_label_down, color=color.lime, textcolor=color.white, yloc=yloc.abovebar)
if showCHoCH and chochDown
label.new(bar_index, low, "CHoCH ↓", style=label.style_label_up, color=color.lime, textcolor=color.white, yloc=yloc.belowbar)
// === Arrows for signals ===
plotshape(bosUp, title="BOS Buy Arrow", location=location.belowbar, color=color.blue, style=shape.labelup, size=size.small, text="↑ BOS")
plotshape(bosDown, title="BOS Sell Arrow", location=location.abovebar, color=color.blue, style=shape.labeldown, size=size.small, text="↓ BOS")
plotshape(chochUp, title="CHoCH Buy Arrow", location=location.belowbar, color=color.lime, style=shape.labelup, size=size.small, text="↑ CHoCH")
plotshape(chochDown, title="CHoCH Sell Arrow", location=location.abovebar, color=color.lime, style=shape.labeldown, size=size.small, text="↓ CHoCH")
indicator("Market Structure BOS/CHoCH", overlay=true, max_labels_count=500)
// === Settings ===
swingLen = input.int(3, "Swing Length", minval=1)
showBOS = input.bool(true, "Show BOS")
showCHoCH = input.bool(true, "Show CHoCH")
// === Identify swing highs and lows ===
var float lastHigh = na
var float lastLow = na
swingHigh = ta.pivothigh(high, swingLen, swingLen)
swingLow = ta.pivotlow(low, swingLen, swingLen)
if not na(swingHigh)
lastHigh := swingHigh
if not na(swingLow)
lastLow := swingLow
// === Determine HH, HL, LH, LL ===
hh = not na(swingHigh) and swingHigh > lastHigh
hl = not na(swingLow) and swingLow > lastLow
lh = not na(swingHigh) and swingHigh < lastHigh
ll = not na(swingLow) and swingLow < lastLow
// === Plot labels for structure points ===
if hh
label.new(bar_index, swingHigh, "HH", style=label.style_label_down, color=color.green, textcolor=color.white, yloc=yloc.abovebar)
if hl
label.new(bar_index, swingLow, "HL", style=label.style_label_up, color=color.green, textcolor=color.white, yloc=yloc.belowbar)
if lh
label.new(bar_index, swingHigh, "LH", style=label.style_label_down, color=color.red, textcolor=color.white, yloc=yloc.abovebar)
if ll
label.new(bar_index, swingLow, "LL", style=label.style_label_up, color=color.red, textcolor=color.white, yloc=yloc.belowbar)
// === BOS (Break of Structure) detection ===
bosUp = ta.crossover(close, lastHigh)
bosDown = ta.crossunder(close, lastLow)
if showBOS and bosUp
label.new(bar_index, high, "BOS ↑", style=label.style_label_down, color=color.blue, textcolor=color.white, yloc=yloc.abovebar)
if showBOS and bosDown
label.new(bar_index, low, "BOS ↓", style=label.style_label_up, color=color.blue, textcolor=color.white, yloc=yloc.belowbar)
// === CHoCH (Change of Character) detection ===
var int trend = 0 // 1 = uptrend, -1 = downtrend
if hh or hl
trend := 1
if lh or ll
trend := -1
chochUp = trend == -1 and bosUp
chochDown = trend == 1 and bosDown
if showCHoCH and chochUp
label.new(bar_index, high, "CHoCH ↑", style=label.style_label_down, color=color.lime, textcolor=color.white, yloc=yloc.abovebar)
if showCHoCH and chochDown
label.new(bar_index, low, "CHoCH ↓", style=label.style_label_up, color=color.lime, textcolor=color.white, yloc=yloc.belowbar)
// === Arrows for signals ===
plotshape(bosUp, title="BOS Buy Arrow", location=location.belowbar, color=color.blue, style=shape.labelup, size=size.small, text="↑ BOS")
plotshape(bosDown, title="BOS Sell Arrow", location=location.abovebar, color=color.blue, style=shape.labeldown, size=size.small, text="↓ BOS")
plotshape(chochUp, title="CHoCH Buy Arrow", location=location.belowbar, color=color.lime, style=shape.labelup, size=size.small, text="↑ CHoCH")
plotshape(chochDown, title="CHoCH Sell Arrow", location=location.abovebar, color=color.lime, style=shape.labeldown, size=size.small, text="↓ CHoCH")
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.