Imbalance Zone Script Summary
Creato il: 9 gennaio 2025
Creato il: 9 gennaio 2025
Assessing the code
The user has uploaded the code snippet for a Pine Script drawing imbalanced zones. No explicit questions are present, but it suggests an implicit request for explanation or enhancements.
Pondering possibilities
The user’s code snippet might indicate a need for clarification. It’s worth asking if an explanation or specific guidance is sought, or if further clarification is needed for progress.
Breaking down the code
I’ve examined the Pine Script code and found no errors or questions. It effectively manages daily, weekly, or volume imbalances, potentially requiring a thorough explanation of its mechanics.
Pulling together
I'm organizing a detailed summary that explains the script’s purpose, identifies its features like creating imbalance zones for various timeframes, and tackles potential issues such as referencing box.delete(box)
.
Thought about imbalance zone indicator pendant 15 secondes
Below is an overview of how this script is structured and what it does. If you have follow-up questions or need modifications, just let me know!
This script (written in Pine Script, version 6) plots various types of “imbalances” (often called “fair value gaps”) on a TradingView chart. It also has the option to highlight daily/weekly price imbalances and a “volume imbalance” based on multi-timeframe data.
In short, the script:
tf
), drawing boxes and dotted mid-lines for each imbalance.tfVi
).You can enable or disable each part using the inputs at the top of the script.
TimeFrame (tf
)
Penetration Ratio (penetrationRatio
)
Reduce boxes (reduce
)
true
, the script will “shrink” a box (the imbalance zone) when price partially fills or penetrates it.Extend boxes (extendBoxes
)
true
, newly created boxes and lines will continue extending into the future until price invalidates them or the max bar age is reached.Down/Up Box Colors & mid-line colors
Daily/Weekly Imbalance toggles
Volume Imbalance
tfVi
) can be chosen separately from the primary price imbalance timeframe.Max IPA Age (maxBarHistory
)
Data Request
[h1, h3, l1, l3] = request.security(syminfo.tickerid, tf, [high[1], high[3], low[1], low[3]], ...)
[1]
) and three bars ago ([3]
) on the specified timeframe tf
.lookahead=barmerge.lookahead_on
allows the script to capture data without repaints, though it can behave differently depending on your preference.Logic
h3 < l1
then it’s considered a “down imbalance” (price jumped down, leaving a gap).l3 > h1
then it’s considered an “up imbalance” (price jumped up, leaving a gap).Creating Boxes & Mid-lines
box.new(...)
) that spans from bar_index - 2
to bar_index + 20
, and also creates a dotted mid-line showing the midpoint of the gap.imbalancedDownBoxes
, imbalancedUpBoxes
, etc.) so they can be managed later.The manageBoxes()
function takes care of pruning or adjusting existing imbalance boxes:
Age Out
maxBarHistory
, it’s deleted.Reduction
reduce = true
, the script shrinks the box by adjusting its top or bottom boundary.Invalidation
penetrationRatio
times the box’s height, the box is considered “filled” and is removed.This keeps the chart from accumulating old imbalance boxes indefinitely.
Check if daily timeframe
if showDailyImbalance and timeframe.isdaily
Creates boxes for daily candle bodies
[o, c, t, tc] = request.security(syminfo.tickerid, '1D', [open, close, time, time_close], ...)
open
and close
is considered an imbalance zone (in the sense of a candle body).dailyImbalanceHistory
limit.Same idea, but for weekly data:
if showWeeklyImbalance and timeframe.isweekly
[wo, wc, wt, wtc] = request.security(syminfo.tickerid, '1W', ...)
A box is drawn for each weekly candle body, with a user-defined color and history limit.
Data Request
[o1, c1, o2, c2, viTime] = request.security(...)
tfVi
), a bar or two bars ago.Volume Gap Detection
o1, c1
) and the newer candle (o2, c2
).box
that extends 20 bars into the future (though here it’s using time in milliseconds: time + 20 * 60 * 1000
for a 20-minute extension).Pruning Volume Imbalance Boxes
Adding to Your Chart
Customizing
Performance Note
request.security()
calls and draws multiple boxes, it can be somewhat heavy on resources if you enable everything or use a large maxBarHistory
. Reduce the history or disable unneeded features to lighten it.Potential Edge Cases
barmerge.lookahead_off
if you’re trying to avoid repainting.This script identifies and manages multiple types of imbalances (regular “price” FVGs, candle-body “imbalances” for daily/weekly, and volume-based imbalances). Boxes are dynamically extended, reduced, or removed based on price action and user settings.
If you have specific questions (e.g., debugging issues, repainting concerns, or ideas for further customization), feel free to ask!