OPEN-SOURCE SCRIPT

Pattern Detection

//version=5
indicator("Pattern Detection", overlay=true)

// Xác định Swing High / Low (đỉnh & đáy)
swingHigh(src, length) =>
ta.highest(src, length) == src

swingLow(src, length) =>
ta.lowest(src, length) == src

// === MÔ HÌNH DOUBLE TOP ===
doubleTop = swingHigh(high, 10) and ta.highest(high, 5) == high
if doubleTop
label.new(x=time, y=high, text="DT", color=color.red, textcolor=color.white, size=size.small)

// === MÔ HÌNH HEAD & SHOULDERS ===
leftShoulder = swingHigh(high, 20)
head = swingHigh(high, 10) and high > ta.highest(high, 20)
rightShoulder = swingHigh(high, 20) and ta.highest(high, 10) < high
headShoulders = leftShoulder and head and rightShoulder
if headShoulders
label.new(x=time, y=high, text="H&S", color=color.orange, textcolor=color.white, size=size.small)

// === MÔ HÌNH CUP & HANDLE ===
cupFormation = swingLow(low, 20) and ta.lowest(low, 10) == low
handleFormation = swingHigh(high, 5) and high < ta.highest(high, 10)
cupHandle = cupFormation and handleFormation
if cupHandle
label.new(x=time, y=low, text="C&H", color=color.green, textcolor=color.white, size=size.small)

// === MÔ HÌNH TAM GIÁC (Triangle) ===
triangleUp = swingHigh(high, 10) and ta.highest(high, 5) < high
triangleDown = swingLow(low, 10) and ta.lowest(low, 5) > low
if triangleUp
label.new(x=time, y=high, text="▲", color=color.blue, textcolor=color.white, size=size.small)
if triangleDown
label.new(x=time, y=low, text="▼", color=color.blue, textcolor=color.white, size=size.small)

免責聲明