PROTECTED SOURCE SCRIPT

dih revamped

102
//version=5
indicator("Discretionary Model - Clean", overlay=true, max_labels_count=100)

// ==================== INPUTS ====================
// Time Window
startHour = input.int(9, "Start Hour", minval=0, maxval=23, group="Time Filter")
startMin = input.int(35, "Start Minute", minval=0, maxval=59, group="Time Filter")
endHour = input.int(10, "End Hour", minval=0, maxval=23, group="Time Filter")
endMin = input.int(0, "End Minute", minval=0, maxval=59, group="Time Filter")

// Settings
dispThreshold = input.float(0.4, "Displacement Threshold %", minval=0.1, maxval=2.0, step=0.1, group="Settings")
liqLookback = input.int(20, "Liquidity Lookback", minval=5, maxval=50, group="Settings")
eqThreshold = input.float(0.1, "Equal High/Low Threshold %", minval=0.05, maxval=0.5, step=0.05, group="Settings")
targetPoints = input.int(30, "Target Points", minval=10, maxval=100, group="Settings")

// Visual Options
showBuySide = input.bool(true, "Show Buy Side Liquidity", group="Display")
showSellSide = input.bool(true, "Show Sell Side Liquidity", group="Display")
showReversalSetups = input.bool(true, "Show Reversal Setups", group="Display")

// ==================== TIME FILTER ====================
inTimeWindow() =>
t = time(timeframe.period, "0935-1000:23456")
not na(t)

// ==================== CORE FUNCTIONS ====================

// Displacement detection
isDisplacementUp(thresh) =>
bodySize = close - open
bodyPct = (bodySize / open) * 100
close > open and bodyPct >= thresh and close > high[1]

isDisplacementDown(thresh) =>
bodySize = open - close
bodyPct = (bodySize / open) * 100
close < open and bodyPct >= thresh and close < low[1]

// Buy Side Liquidity (Equal Highs) - WHERE STOPS ARE
isBuySideLiquidity() =>
result = false
currentHigh = high
for i = 1 to liqLookback
diff = math.abs(currentHigh - high)
pctDiff = (diff / currentHigh) * 100
if pctDiff <= eqThreshold and pctDiff > 0
result := true
break
result

// Sell Side Liquidity (Equal Lows) - WHERE STOPS ARE
isSellSideLiquidity() =>
result = false
currentLow = low
for i = 1 to liqLookback
diff = math.abs(currentLow - low)
pctDiff = (diff / currentLow) * 100
if pctDiff <= eqThreshold and pctDiff > 0
result := true
break
result

// ==================== LIQUIDITY DETECTION ====================
buySideLiq = isBuySideLiquidity()
sellSideLiq = isSellSideLiquidity()

// Liquidity swept
buySideSwept = buySideLiq and close > high[1]
sellSideSwept = sellSideLiq and close < low[1]

// ==================== REVERSAL SEQUENCE TRACKING ====================
var bool lookingForReversal = false
var float reversalLevel = na
var int reversalCount = 0
var bool isReversalShort = false

// Start tracking after liquidity sweep
if buySideSwept and inTimeWindow() and not lookingForReversal
lookingForReversal := true
reversalLevel := high
reversalCount := 0
isReversalShort := true

if sellSideSwept and inTimeWindow() and not lookingForReversal
lookingForReversal := true
reversalLevel := low
reversalCount := 0
isReversalShort := false

// Count candles
if lookingForReversal
reversalCount += 1

// Reset after 5 candles
if reversalCount > 5
lookingForReversal := false
reversalCount := 0

// ==================== ENTRY SIGNALS ====================
var float entryPrice = na
var float stopLoss = na
var float takeProfit = na

reversalShortSignal = false
reversalLongSignal = false

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน