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.")
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。