OPEN-SOURCE SCRIPT
Perp Imbalance Zones • Pro (clean)

USD Premium (perp vs spot) → (Perp − Spot) / Spot.
Imbalance (z-score of that premium) → how extreme the current premium is relative to its own history over lenPrem bars.
Hysteresis state machine → flips to a SHORT bias when perp-long pressure is extreme; flips to LONG bias when perp-short pressure is extreme. It exits only after the imbalance cools (prevents whipsaw).
Price stretch filter (±σ) → optional Bollinger check so signals only fire when price is already stretched.
HTF confirmation (optional) → require higher-timeframe imbalance to agree with the current-TF bias.
Gradient visuals → line + background tint deepen as |z| grows (more extreme pressure).
What you see on the pane
A single line (z):
Above 0 = perp richer than spot (perp longs pressing).
Below 0 = perp cheaper than spot (perp shorts pressing).
Guides: dotted levels at ±enterZ (entry) and ±exitZ (cool-off/exit).
Background tint:
Red when state = SHORT bias (perp longs heavy).
Blue when state = LONG bias (perp shorts heavy).
Tint intensity scales with |z| (via hotZ).
Labels (optional): prints when bias flips.
Alerts (optional): “Enter SHORT/LONG bias” and “Exit bias”.
How to use it (playbook)
Attach & set symbols
Put the script on your chart.
Set Spot symbol and Perp symbol to the venue you trade (e.g., BINANCE:BTCUSDT + BINANCE:BTCUSDTPERP).
Read the bias
SHORT bias (red background): perp longs over-extended. Look for short entries if price is at resistance, σ-stretched, or your PA system agrees.
LONG bias (blue background): perp shorts over-extended. Look for long entries at support/σ-stretched down.
Entries
Use the bias flip as a context/confirm. Combine with your structure trigger (OB/level sweep, rejection wick, micro-break in market structure, etc.).
If useSigma=true, only trade when price is already ≥ upper band (shorts) or ≤ lower band (longs).
Exits
Bias auto-exits when |z| falls below exitZ.
You can also take profits at your levels or when the line fades back toward 0 while price mean-reverts to the middle band.
Tuning (what each knob does)
enterZ / exitZ (signal strictness + hysteresis)
Higher enterZ → fewer, cleaner signals (e.g., 1.8–2.2).
exitZ should be lower than enterZ (e.g., 0.6–1.0) to prevent flicker.
lenPrem (context window for z)
Larger (50–100) = steadier baseline, fewer signals.
Smaller (20–30) = more reactive, more signals.
smoothLen (EMA on z)
2–3 = snappier; 5–7 = smoother/laggier but cleaner.
useSigma, bbLen, bbK (price-stretch filter)
On filters chop. Try bbLen=100, bbK=1.0–1.5.
Off if you want more frequent signals or you already gate with your own σ/Keltner.
useHTF, htfTF, htfZmin (trend/confirmation)
Turn on to require higher-TF imbalance agreement (e.g., trading 1H → confirm with 4H htfTF=240, htfZmin≈0.6–1.0).
hotZ (visual intensity)
Lower (2.0–2.5) heats up faster; higher (4.0) is more subtle.
Ready-made presets
Conservative swing (fewer, higher-conviction):
enterZ=2.0, exitZ=1.0, lenPrem=60–80, smoothLen=5, useSigma=true, bbK=1.5, useHTF=true (240/0.8).
Balanced intraday (default feel):
enterZ=1.6–1.8, exitZ=0.8–1.0, lenPrem=50, smoothLen=3–4, useSigma=true, bbK=1.0–1.25, useHTF=false/true depending on trendiness.
Aggressive scalping (more signals):
enterZ=1.2–1.4, exitZ=0.6–0.8, lenPrem=20–30, smoothLen=2–3, useSigma=false, useHTF=false.
Practical tips
Don’t trade the line in isolation. Use it to time trades into your levels: VWAP bands, Monday high/low, prior POC/VAH/VAL, order blocks, etc.
Perp-led reversals often snap—be ready to scale out quickly back to mid-bands.
Venue matters. Keep spot & perp from the same exchange family to avoid cross-venue quirks.
Alerts: enable after you’ve tuned thresholds for your timeframe so you only get high-quality pings.
Imbalance (z-score of that premium) → how extreme the current premium is relative to its own history over lenPrem bars.
Hysteresis state machine → flips to a SHORT bias when perp-long pressure is extreme; flips to LONG bias when perp-short pressure is extreme. It exits only after the imbalance cools (prevents whipsaw).
Price stretch filter (±σ) → optional Bollinger check so signals only fire when price is already stretched.
HTF confirmation (optional) → require higher-timeframe imbalance to agree with the current-TF bias.
Gradient visuals → line + background tint deepen as |z| grows (more extreme pressure).
What you see on the pane
A single line (z):
Above 0 = perp richer than spot (perp longs pressing).
Below 0 = perp cheaper than spot (perp shorts pressing).
Guides: dotted levels at ±enterZ (entry) and ±exitZ (cool-off/exit).
Background tint:
Red when state = SHORT bias (perp longs heavy).
Blue when state = LONG bias (perp shorts heavy).
Tint intensity scales with |z| (via hotZ).
Labels (optional): prints when bias flips.
Alerts (optional): “Enter SHORT/LONG bias” and “Exit bias”.
How to use it (playbook)
Attach & set symbols
Put the script on your chart.
Set Spot symbol and Perp symbol to the venue you trade (e.g., BINANCE:BTCUSDT + BINANCE:BTCUSDTPERP).
Read the bias
SHORT bias (red background): perp longs over-extended. Look for short entries if price is at resistance, σ-stretched, or your PA system agrees.
LONG bias (blue background): perp shorts over-extended. Look for long entries at support/σ-stretched down.
Entries
Use the bias flip as a context/confirm. Combine with your structure trigger (OB/level sweep, rejection wick, micro-break in market structure, etc.).
If useSigma=true, only trade when price is already ≥ upper band (shorts) or ≤ lower band (longs).
Exits
Bias auto-exits when |z| falls below exitZ.
You can also take profits at your levels or when the line fades back toward 0 while price mean-reverts to the middle band.
Tuning (what each knob does)
enterZ / exitZ (signal strictness + hysteresis)
Higher enterZ → fewer, cleaner signals (e.g., 1.8–2.2).
exitZ should be lower than enterZ (e.g., 0.6–1.0) to prevent flicker.
lenPrem (context window for z)
Larger (50–100) = steadier baseline, fewer signals.
Smaller (20–30) = more reactive, more signals.
smoothLen (EMA on z)
2–3 = snappier; 5–7 = smoother/laggier but cleaner.
useSigma, bbLen, bbK (price-stretch filter)
On filters chop. Try bbLen=100, bbK=1.0–1.5.
Off if you want more frequent signals or you already gate with your own σ/Keltner.
useHTF, htfTF, htfZmin (trend/confirmation)
Turn on to require higher-TF imbalance agreement (e.g., trading 1H → confirm with 4H htfTF=240, htfZmin≈0.6–1.0).
hotZ (visual intensity)
Lower (2.0–2.5) heats up faster; higher (4.0) is more subtle.
Ready-made presets
Conservative swing (fewer, higher-conviction):
enterZ=2.0, exitZ=1.0, lenPrem=60–80, smoothLen=5, useSigma=true, bbK=1.5, useHTF=true (240/0.8).
Balanced intraday (default feel):
enterZ=1.6–1.8, exitZ=0.8–1.0, lenPrem=50, smoothLen=3–4, useSigma=true, bbK=1.0–1.25, useHTF=false/true depending on trendiness.
Aggressive scalping (more signals):
enterZ=1.2–1.4, exitZ=0.6–0.8, lenPrem=20–30, smoothLen=2–3, useSigma=false, useHTF=false.
Practical tips
Don’t trade the line in isolation. Use it to time trades into your levels: VWAP bands, Monday high/low, prior POC/VAH/VAL, order blocks, etc.
Perp-led reversals often snap—be ready to scale out quickly back to mid-bands.
Venue matters. Keep spot & perp from the same exchange family to avoid cross-venue quirks.
Alerts: enable after you’ve tuned thresholds for your timeframe so you only get high-quality pings.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.