OPEN-SOURCE SCRIPT

Higher Highs, Higher Lows, Lower Highs, Lower Lows

65
//version=5
indicator("Higher Highs, Higher Lows, Lower Highs, Lower Lows", overlay=true)

// Lookback period for swing detection
length = input(36)

// Detect swing highs and lows
swingHigh = ta.highest(high, length) == high
swingLow = ta.lowest(low, length) == low

// Track previous highs and lows
var float prevHigh = na
var float prevLow = na
var float lastHigh = na
var float lastLow = na

if swingHigh
prevHigh := lastHigh
lastHigh := high

if swingLow
prevLow := lastLow
lastLow := low

// Determine structure: HH, HL, LH, LL
isHH = swingHigh and lastHigh > prevHigh
isHL = swingLow and lastLow > prevLow
isLH = swingHigh and lastHigh < prevHigh
isLL = swingLow and lastLow < prevLow

// Plot labels for HH, HL, LH, LL
labelOffset = 10

if isHH
label.new(x=time, y=high, text="HH", color=color.green, textcolor=color.white, size=size.small, style=label.style_label_down)

if isHL
label.new(x=time, y=low, text="HL", color=color.blue, textcolor=color.white, size=size.small, style=label.style_label_up)

if isLH
label.new(x=time, y=high, text="LH", color=color.red, textcolor=color.white, size=size.small, style=label.style_label_down)

if isLL
label.new(x=time, y=low, text="LL", color=color.orange, textcolor=color.white, size=size.small, style=label.style_label_up)

// Draw connecting lines
var line hhLine = na
var line hlLine = na
var line lhLine = na
var line llLine = na

if isHH
hhLine := line.new(x1=bar_index[length], y1=prevHigh, x2=bar_index, y2=lastHigh, width=2, color=color.green)

if isHL
hlLine := line.new(x1=bar_index[length], y1=prevLow, x2=bar_index, y2=lastLow, width=2, color=color.blue)

if isLH
lhLine := line.new(x1=bar_index[length], y1=prevHigh, x2=bar_index, y2=lastHigh, width=2, color=color.red)

if isLL
llLine := line.new(x1=bar_index[length], y1=prevLow, x2=bar_index, y2=lastLow, width=2, color=color.orange)

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。