OPEN-SOURCE SCRIPT
ABCD Strategy (v7 Ready)

//version=6
indicator("ABCD Strategy v7 – MTF S/R Filter", overlay=true, max_lines_count=300, max_labels_count=300)
//━━━━━━━━━━━━━━━━━━━━━
// INPUTS
//━━━━━━━━━━━━━━━━━━━━━
pivotLen = input.int(5, "Swing Strength", minval=2)
bcMin = input.float(0.618, "BC Min Fib")
bcMax = input.float(0.786, "BC Max Fib")
cdMin = input.float(1.272, "CD Min Extension")
cdMax = input.float(1.618, "CD Max Extension")
htfTF = input.timeframe("240", "Higher Timeframe (S/R)")
srLookback = input.int(200, "HTF S/R Lookback")
srTolerance = input.float(0.002, "S/R Zone Tolerance (0.2%)")
showSR = input.bool(true, "Show HTF S/R Zones")
showTargets = input.bool(true, "Show Targets")
//━━━━━━━━━━━━━━━━━━━━━
// HIGHER TF SUPPORT / RESISTANCE
//━━━━━━━━━━━━━━━━━━━━━
htfHigh = request.security(syminfo.tickerid, htfTF, ta.highest(high, srLookback))
htfLow = request.security(syminfo.tickerid, htfTF, ta.lowest(low, srLookback))
srHighZoneTop = htfHigh * (1 + srTolerance)
srHighZoneBottom = htfHigh * (1 - srTolerance)
srLowZoneTop = htfLow * (1 + srTolerance)
srLowZoneBottom = htfLow * (1 - srTolerance)
//━━━━━━━━━━━━━━━━━━━━━
// DRAW HTF ZONES
//━━━━━━━━━━━━━━━━━━━━━
if showSR
box.new(bar_index - 5, srHighZoneTop, bar_index + 5, srHighZoneBottom,
bgcolor=color.new(color.red, 85), border_color=color.red)
box.new(bar_index - 5, srLowZoneTop, bar_index + 5, srLowZoneBottom,
bgcolor=color.new(color.green, 85), border_color=color.green)
//━━━━━━━━━━━━━━━━━━━━━
// SWING DETECTION
//━━━━━━━━━━━━━━━━━━━━━
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
var float A = na
var float B = na
var float C = na
var float D = na
var int Ab = na
var int Bb = na
var int Cb = na
var int Db = na
if not na(pl)
A := B
Ab := Bb
B := C
Bb := Cb
C := low[pivotLen]
Cb := bar_index[pivotLen]
if not na(ph)
A := B
Ab := Bb
B := C
Bb := Cb
C := high[pivotLen]
Cb := bar_index[pivotLen]
//━━━━━━━━━━━━━━━━━━━━━
// ABCD LOGIC
//━━━━━━━━━━━━━━━━━━━━━
ab = math.abs(B - A)
bc = math.abs(C - B)
bcFib = bc / ab
validBC = bcFib >= bcMin and bcFib <= bcMax
bull = C > B
cdMinPrice = bull ? C - bc * cdMin : C + bc * cdMin
cdMaxPrice = bull ? C - bc * cdMax : C + bc * cdMax
inDzone = low <= cdMaxPrice and high >= cdMinPrice
//━━━━━━━━━━━━━━━━━━━━━
// MTF STRUCTURE FILTER
//━━━━━━━━━━━━━━━━━━━━━
nearResistance = close <= srHighZoneTop and close >= srHighZoneBottom
nearSupport = close <= srLowZoneTop and close >= srLowZoneBottom
structureOK =
(bull and nearSupport) or
(not bull and nearResistance)
//━━━━━━━━━━━━━━━━━━━━━
// FINAL D CONFIRMATION
//━━━━━━━━━━━━━━━━━━━━━
if validBC and inDzone and structureOK
D := close
Db := bar_index
//━━━━━━━━━━━━━━━━━━━━━
// TARGETS
//━━━━━━━━━━━━━━━━━━━━━
tp1 = bull ? D + math.abs(D - C) * 0.382 : D - math.abs(D - C) * 0.382
tp2 = bull ? D + math.abs(D - C) * 0.618 : D - math.abs(D - C) * 0.618
//━━━━━━━━━━━━━━━━━━━━━
// DRAW PATTERN
//━━━━━━━━━━━━━━━━━━━━━
if not na(D)
line.new(Ab, A, Bb, B, width=2, color=color.blue)
line.new(Bb, B, Cb, C, width=2, color=color.orange)
line.new(Cb, C, Db, D, width=2, color=color.green)
label.new(Db, D, "D (HTF CONFIRMED)", style=label.style_label_down, color=color.yellow)
if showTargets
line.new(Db, tp1, Db + 12, tp1, color=color.green)
line.new(Db, tp2, Db + 12, tp2, color=color.teal)
alertcondition(validBC and inDzone and structureOK,
"ABCD v7 Confirmed",
"ABCD Pattern confirmed at Higher-Timeframe Support/Resistance — wait for price action.")
indicator("ABCD Strategy v7 – MTF S/R Filter", overlay=true, max_lines_count=300, max_labels_count=300)
//━━━━━━━━━━━━━━━━━━━━━
// INPUTS
//━━━━━━━━━━━━━━━━━━━━━
pivotLen = input.int(5, "Swing Strength", minval=2)
bcMin = input.float(0.618, "BC Min Fib")
bcMax = input.float(0.786, "BC Max Fib")
cdMin = input.float(1.272, "CD Min Extension")
cdMax = input.float(1.618, "CD Max Extension")
htfTF = input.timeframe("240", "Higher Timeframe (S/R)")
srLookback = input.int(200, "HTF S/R Lookback")
srTolerance = input.float(0.002, "S/R Zone Tolerance (0.2%)")
showSR = input.bool(true, "Show HTF S/R Zones")
showTargets = input.bool(true, "Show Targets")
//━━━━━━━━━━━━━━━━━━━━━
// HIGHER TF SUPPORT / RESISTANCE
//━━━━━━━━━━━━━━━━━━━━━
htfHigh = request.security(syminfo.tickerid, htfTF, ta.highest(high, srLookback))
htfLow = request.security(syminfo.tickerid, htfTF, ta.lowest(low, srLookback))
srHighZoneTop = htfHigh * (1 + srTolerance)
srHighZoneBottom = htfHigh * (1 - srTolerance)
srLowZoneTop = htfLow * (1 + srTolerance)
srLowZoneBottom = htfLow * (1 - srTolerance)
//━━━━━━━━━━━━━━━━━━━━━
// DRAW HTF ZONES
//━━━━━━━━━━━━━━━━━━━━━
if showSR
box.new(bar_index - 5, srHighZoneTop, bar_index + 5, srHighZoneBottom,
bgcolor=color.new(color.red, 85), border_color=color.red)
box.new(bar_index - 5, srLowZoneTop, bar_index + 5, srLowZoneBottom,
bgcolor=color.new(color.green, 85), border_color=color.green)
//━━━━━━━━━━━━━━━━━━━━━
// SWING DETECTION
//━━━━━━━━━━━━━━━━━━━━━
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
var float A = na
var float B = na
var float C = na
var float D = na
var int Ab = na
var int Bb = na
var int Cb = na
var int Db = na
if not na(pl)
A := B
Ab := Bb
B := C
Bb := Cb
C := low[pivotLen]
Cb := bar_index[pivotLen]
if not na(ph)
A := B
Ab := Bb
B := C
Bb := Cb
C := high[pivotLen]
Cb := bar_index[pivotLen]
//━━━━━━━━━━━━━━━━━━━━━
// ABCD LOGIC
//━━━━━━━━━━━━━━━━━━━━━
ab = math.abs(B - A)
bc = math.abs(C - B)
bcFib = bc / ab
validBC = bcFib >= bcMin and bcFib <= bcMax
bull = C > B
cdMinPrice = bull ? C - bc * cdMin : C + bc * cdMin
cdMaxPrice = bull ? C - bc * cdMax : C + bc * cdMax
inDzone = low <= cdMaxPrice and high >= cdMinPrice
//━━━━━━━━━━━━━━━━━━━━━
// MTF STRUCTURE FILTER
//━━━━━━━━━━━━━━━━━━━━━
nearResistance = close <= srHighZoneTop and close >= srHighZoneBottom
nearSupport = close <= srLowZoneTop and close >= srLowZoneBottom
structureOK =
(bull and nearSupport) or
(not bull and nearResistance)
//━━━━━━━━━━━━━━━━━━━━━
// FINAL D CONFIRMATION
//━━━━━━━━━━━━━━━━━━━━━
if validBC and inDzone and structureOK
D := close
Db := bar_index
//━━━━━━━━━━━━━━━━━━━━━
// TARGETS
//━━━━━━━━━━━━━━━━━━━━━
tp1 = bull ? D + math.abs(D - C) * 0.382 : D - math.abs(D - C) * 0.382
tp2 = bull ? D + math.abs(D - C) * 0.618 : D - math.abs(D - C) * 0.618
//━━━━━━━━━━━━━━━━━━━━━
// DRAW PATTERN
//━━━━━━━━━━━━━━━━━━━━━
if not na(D)
line.new(Ab, A, Bb, B, width=2, color=color.blue)
line.new(Bb, B, Cb, C, width=2, color=color.orange)
line.new(Cb, C, Db, D, width=2, color=color.green)
label.new(Db, D, "D (HTF CONFIRMED)", style=label.style_label_down, color=color.yellow)
if showTargets
line.new(Db, tp1, Db + 12, tp1, color=color.green)
line.new(Db, tp2, Db + 12, tp2, color=color.teal)
alertcondition(validBC and inDzone and structureOK,
"ABCD v7 Confirmed",
"ABCD Pattern confirmed at Higher-Timeframe Support/Resistance — wait for price action.")
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.