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")
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.