These Are The Trades We Are Doing / Watching In ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

NEXT WEEK - BIG TECH EARNINGS

Going into this tech heavy earnings cluster, the game plan is to treat the entire market as one coordinated setup driven by /ES compression, not a collection of independent trades. Right now, /ES is holding a bullish structure but clearly stalling under the 7185–7200 resistance zone, with suppressed volatility and dealer-controlled flow. That tells you the market is waiting for information (META, GOOGL, TSLA) rather than pricing it in early. So early in the week, your edge is not prediction, it’s range execution and patience. You should expect continued two-sided action between roughly 7000–7200 on /ES (mirroring ~7000–7200 on SPX), which means fading extremes is higher probability: selling strength into the upper range and buying dips into value, while avoiding breakout chasing because momentum and participation are clearly weak across timeframes.
As earnings begin (TSLA first, then META/GOOGL), shift from range mindset to reaction mindset. TSLA will likely set the tone for volatility, not direction, so watch whether /ES reacts impulsively or absorbs the move. If TSLA sells off and /ES holds above ~7070, that’s a sign of underlying market strength (dip buying); if TSLA sells off and /ES loses that level, that’s your first signal of broader risk-off. Then META and GOOGL become the real directional catalysts: if both report strong numbers and, more importantly, guide well, you should expect /ES to break and hold above 7200, triggering a broad risk-on move where trend names (AMD) continue, large caps (META/GOOGL) expand, and high-beta names (TSLA, CVNA) squeeze. In that environment, you stop fading and instead buy pullbacks and momentum confirmation.
On the flip side, if META/GOOGL disappoint or the market interprets their results negatively (especially around AI spend and margins), the most important tell will be acceptance below ~7070 on /ES. That would likely trigger a fast rotation lower toward 7000 to 6950, and your playbook shifts to selling rallies instead of buying dips. In that scenario, expect weakness to cascade across your list: META and GOOGL pull back from highs, TSLA loses its squeeze structure, and names like CVNA unwind aggressively. The key is not trying to predict which outcome happens, but recognizing that the market is currently coiled, and once it breaks out of this range, the move should be clean and directional.
So the plan is simple but disciplined: early week = range trade and protect capital, midweek into earnings = reduce exposure and wait, post-earnings = attack the breakout or breakdown with size. Let /ES dictate everything, if it breaks and holds above resistance, you lean long across strong names; if it loses support, you lean short or defensive. Until then, assume every move is a trap, because right now, structurally, it probably is.
 
Last edited by a moderator:
thinkorswim_o0ht0For0o.png
thinkorswim_nDTDJCn0sH.png
Quick look at BABA:

Price has already broken out of a cup-with-handle. A retest of the breakout/handle zone is likely (early Monday or after the open). If that holds, continuation toward the projected targets is in play.

Above that sits a key confluence zones at the potential inverted H&S neckline and both targets above.

Pattern resistance (neckline)
Fibonacci levels line up with projected levels
Volume profile HVN also line up with projected levels

From here:

Break above neckline opens larger IH&S reversal

Both paths are mapped now it’s up to price…
assuming no surprise Trump tweets nuke the setup
😅
 
View attachment 27412View attachment 27413Quick look at BABA:

Price has already broken out of a cup-with-handle. A retest of the breakout/handle zone is likely (early Monday or after the open). If that holds, continuation toward the projected targets is in play.

Above that sits a key confluence zones at the potential inverted H&S neckline and both targets above.

Pattern resistance (neckline)
Fibonacci levels line up with projected levels
Volume profile HVN also line up with projected levels

From here:

Break above neckline opens larger IH&S reversal

Both paths are mapped now it’s up to price…
assuming no surprise Trump tweets nuke the setup
😅
Really like your price/ date projections.. Are you manually annotating the chart ?

My current 4hr. Chart. Monday could definitely be a defining moment...

BABA_4Hr.png
 
Thank you atcsam

I wish there was a way to just plug a few numbers into a study and have it generate full technical analysis with directional projections and estimated dates. :LOL: That would save me a lot of time. I usually won’t spend this much time charting unless I think it has the potential to be a high-value trade. Anyhow, if you ever figure out how to do that with the ancient temple ThinkScript :poop:, please let me know.

As for the analysis, this is just the most likely path I see if the pattern follows through. The existing price structure gives enough information to build directional projections, so my thought is: if there is enough structure to project direction and price targets, why not also add estimated dates to help with option selection?

I do think there is enough room in the channel for at least 75% of the projected move, giving MM plenty of room to do his thing on the way up. That said, I would actually like to see a healthy retest of the breakout area, somewhere around $130 or so, before the larger move continues. That would help confirm the breakout and give participants more confidence that the move is real.

There is still the neckline above to deal with, along with other resistance zones, so we’ll see what price does on Monday. As I’m sure you know, patterns can fail and will fail. Current market sentiment is still a little nervous, so anything can happen.

By the way, i wish more people would share their findings on good setups. Doesn't need to be a technical charting analysis, just a ticker and what's going on would be great.
 
Last edited:
Thank you atcsam

I wish there was a way to just plug a few numbers into a study and have it generate full technical analysis with directional projections and estimated dates. :LOL: That would save me a lot of time. I usually won’t spend this much time charting unless I think it has the potential to be a high-value trade. Anyhow, if you ever figure out how to do that with the ancient temple ThinkScript :poop:, please let me know.

As for the analysis, this is just the most likely path I see if the pattern follows through. The existing price structure gives enough information to build directional projections, so my thought is: if there is enough structure to project direction and price targets, why not also add estimated dates to help with option selection?

I do think there is enough room in the channel for at least 75% of the projected move, giving MM plenty of room to do his thing on the way up. That said, I would actually like to see a healthy retest of the breakout area, somewhere around $130 or so, before the larger move continues. That would help confirm the breakout and give participants more confidence that the move is real.

There is still the neckline above to deal with, along with other resistance zones, so we’ll see what price does on Monday. As I’m sure you know, patterns can fail and will fail. Current market sentiment is still a little nervous, so anything can happen.

By the way, i wish more people would share their findings on good setups. Doesn't need to be a technical charting analysis, just a ticker and what's going on would be great.
The core idea is to focus only on strong, institutionally driven uptrends (Stage 2) and avoid random scanning or early breakout chasing. Each day begins by filtering for stocks already trading above key moving averages, specifically the 20 EMA and 50 EMA, because this confirms that price is in a sustained uptrend rather than a weak or transitioning phase. From there, the focus shifts to strength, selecting stocks that are outperforming the broader market (SPY/QQQ) and showing strong recent performance (weekly/monthly gains), which indicates institutional participation.

Once strong candidates are identified, the next step is to look for tight consolidation patterns after a move, not extended breakouts. The ideal setup is a stock that has already trended higher, then begins forming a narrow range with shrinking candles and decreasing volatility, this signals supply absorption. Volume should contract during this consolidation phase, showing that sellers are drying up, followed by a noticeable increase in volume as price begins to push higher again. This transition from contraction to expansion is the key signal.

Entries are not taken randomly at highs, instead, the trade is executed either on a clean breakout of the tight range (with volume confirmation) or on a controlled pullback to the 20 EMA, provided price respects that level and does not break structure. The stop loss is placed just below the consolidation range or below the 20 EMA, depending on entry type. If the structure fails or the EMA is lost with momentum, the trade is invalid and exited immediately.

The goal is to align trend + structure + volume, entering only when all three confirm. This avoids low-probability setups and keeps focus on high-quality, momentum-driven stocks that institutions are actively accumulating.

here is a scanner for that:
Code:
# =========================
# STAGE 2 TREND + COMPRESSION SCAN
# =========================

# --- MOVING AVERAGES ---
def ema20 = ExpAverage(close, 20);
def ema50 = ExpAverage(close, 50);

# --- TREND (Stage 2) ---
def trendUp =
    close > ema20 and
    close > ema50 and
    ema20 > ema50;

# --- STRENGTH (Relative Performance) ---
def strength =
    close / close[20] > 1.05;

# --- VOLUME (Institutional Interest) ---
def volFilter =
    volume > Average(volume, 50);

# --- COMPRESSION (Tight Range) ---
def range =
    Highest(high, 10) - Lowest(low, 10);

def compression =
    range / close < 0.05;

# =========================
# FINAL SCAN CONDITION
# =========================
plot scan =
    trendUp and
    strength and
    volFilter and
    compression;

and here is a more powerful piece - a Watchlist Column:
Code:
# =========================
# WATCHLIST: TREND + SETUP STATE
# =========================

# --- MOVING AVERAGES ---
def ema20 = ExpAverage(close, 20);
def ema50 = ExpAverage(close, 50);

# --- TREND ---
def trendUp =
    close > ema20 and
    close > ema50 and
    ema20 > ema50;

def trendDown =
    close < ema20 and
    close < ema50 and
    ema20 < ema50;

# --- COMPRESSION ---
def range =
    Highest(high, 10) - Lowest(low, 10);

def compression =
    range / close < 0.05;

# --- BREAKOUT ---
def breakout =
    close >= Highest(high, 10);

# --- EARLY BUILD (tight + trend) ---
def building =
    trendUp and compression;

# --- READY (tight + slight expansion starting) ---
def ready =
    building and close > close[1];

# =========================
# LABEL OUTPUT
# =========================

AddLabel(yes,
    if breakout then "🔥 BREAKOUT"
    else if ready then "⚡ READY"
    else if building then "🟡 BUILDING"
    else if trendUp then "🟢 TREND"
    else if trendDown then "🔴 DOWN"
    else "—",
    
    if breakout then Color.CYAN
    else if ready then Color.YELLOW
    else if building then Color.ORANGE
    else if trendUp then Color.GREEN
    else if trendDown then Color.RED
    else Color.GRAY
);
 
If your trades are centered on stocks with high institutional liquidity, read on.

If you trade low float, meme, IPO, high volality type stocks with no institutional backing; you are already experienced trading stock like $BABA and don't need to read the following.

The Anatomy Of A Meme-ified Blue Chip
August 28, 2024: The Great Decoupling. To avoid US delisting risks, institutions began swapping their US ADRs for Hong Kong ordinary shares. This caused $BABA's US institutional ownership to crater to 13.47%

So who does that 10 million volume belong to? The 85% is made up of retail traders.
You are looking at the retail trading swarm in all its glory. A million little traders driving a big stock.

So what is the problem?
Institutional Bots are the math behind our technical indicators. We know they will trigger Long when the price crosses above the 200-day SMA or when the RSI climbs out of oversold territory at a key structural level. Swing and day trading were born from this—the ability to front-run the institutional algorithms.
But stocks without an institutional floor do not respect these indicators.

The Psychology of the BABA Swarm: Bag-Holders vs. High-Hopers
A perusal of the trading rooms (Subreddits, Stocktwits, and Discord groups) reveals a market divided.
» The Defiant Bag-Holders:​
They preach HODL at every dip. In actuality, they are looking for an exit. We saw this on Thursday—as soon as the price broke up $140, the HODLers became sellers, desperate to just break even. This created a massive supply overhead that suppressed the rally.​
» The High-Hopers:​
This group believes the confluence of the May 14th Trump-Xi Summit and the May 21st Earnings is prophetic. A guaranteed catalyst to drive the price to $190.​

The Prediction Probability Collapse
A week ago, prediction markets like Polymarket and Kalshi were pricing an 89% probability that the Beijing summit would occur on schedule. As of tonight, that number has cratered to 70.5%.
The catalyst for this 18-point drop was a hawkish pivot from the US State Department:
Tonight's headline:​
22:30 News Bot: The US State Department has reportedly ordered a global warning over alleged AI IP theft involving DeepSeek and other Chinese firms.​

There are those that trade BABA and make serious money. There are tens of thousands of retail traders that believe this stock will make them rich and nothing in this write-up says that they are wrong.

This write-up was soley for the purpose, of pointing out to newer traders; that it is a different kind of stock.
 
Last edited:
If your trades are centered on stocks with high institutional liquidity, read on.

If you trade low float, meme, IPO, high volality type stocks with no institutional backing; you are already experienced trading stock like $BABA and don't need to read the following.

The Anatomy Of A Meme-ified Blue Chip
August 28, 2024: The Great Decoupling. To avoid US delisting risks, institutions began swapping their US ADRs for Hong Kong ordinary shares. This caused $BABA's US institutional ownership to crater to 13.47%

So who does that 10 million volume belong to? The 85% is made up of retail traders.
You are looking at the retail trading swarm in all its glory. A million little traders driving a big stock.

So what is the problem?
Institutional Bots are the math behind our technical indicators. We know they will trigger Long when the price crosses above the 200-day SMA or when the RSI climbs out of oversold territory at a key structural level. Swing and day trading were born from this—the ability to front-run the institutional algorithms.
But stocks without an institutional floor do not respect these indicators.

The Psychology of the BABA Swarm: Bag-Holders vs. High-Hopers
A perusal of the trading rooms (Subreddits, Stocktwits, and Discord groups) reveals a market divided.
» The Defiant Bag-Holders:​
They preach HODL at every dip. In actuality, they are looking for an exit. We saw this on Thursday—as soon as the price broke up $140, the HODLers became sellers, desperate to just break even. This created a massive supply overhead that suppressed the rally.​
» The High-Hopers:​
This group believes the confluence of the May 14th Trump-Xi Summit and the May 21st Earnings is prophetic. A guaranteed catalyst to drive the price to $190.​

The Prediction Probability Collapse
A week ago, prediction markets like Polymarket and Kalshi were pricing an 89% probability that the Beijing summit would occur on schedule. As of tonight, that number has cratered to 70.5%.
The catalyst for this 18-point drop was a hawkish pivot from the US State Department:
Tonight's headline:​
22:30 News Bot: The US State Department has reportedly ordered a global warning over alleged AI IP theft involving DeepSeek and other Chinese firms.​

There are those that trade BABA and make serious money. There are tens of thousands of retail traders that believe this stock will make them rich and nothing in this write-up says that they are wrong.

This write-up was soley for the purpose, of pointing out to newer traders; that it is a different kind of stock.
Perfect example of why Homework matters. I generally stay away from Chinese stocks — I knew they took a hit, but I never dug into the structural reasons behind it. Your note makes the whole decoupling move make a lot more sense. TA has its place, just not the full picture.
 
GNRC – Structural Setup Worth Watching

Trying to revive the thread — at first I thought this place might turn into a WallStreetBets frenzy, but it’s been more of a lame duck lately. My attempt at posting something with actual structure to get ideas flowing again.


Seeing potential in high‑quality names temporarily suppressed by macro pressure — mainly rate drag on growth/industrials. GNRC fits that profile: strong fundamentals, solid cash flow, long‑term growth intact, but trading well below its intrinsic range. The 12‑month PO sits around 275–285, so current levels look more like discounted compression than momentum.

GNRC is an interesting watch candidate here. Trend line is intact but fragile, and it’s below the 200MA. Forward growth is strong, recent numbers are soft, and analyst opinions are split (CFRA/LSEG lean long‑term positive; Schwab’s D usually shows up when a name is already beaten down). Industrials are improving, but rates remain a headwind.

Redrew the structure for clarity: • Dotted orange = 3‑point long‑term trend line (middle touch slightly below but structurally valid). • Yellow = 2‑point short‑term support. Both intersect directly at the 38.2% Fib (~175) — exactly where price is sitting.

If 175 breaks, next levels are: • 23.6% = 1460% = 100 (full retracement)

Not calling a move — just mapping realistic downside structure instead of assuming the trend line holds. Interesting decision zone with mixed signals.

Curious how others are mapping this — any alternate reads on this one?

Disclaimer:
Not holding a position — just analyzing the structure and considering a future entry. Have traded GNRC in the past.

Weekly

KDxMFaY.png


Weekly TTM LRC55

muapIz9.png

Stock Insight - Analyst snapshot

tnPhKnv.png
 
Last edited:
GNRC is a graveyard for intraday traders
High % of institutional interest >84% combined will low float ~50m means that level breaks rarely drift lazily—they either result in an immediate aggressive expansion (absorption breakout) or a violent mean-reversion trap (liquidity sweep). The house holds the cards; day traders are destined to be on the wrong side.

But this could be goldmine for short-term swing traders.

When you zoom out to the daily and 30-minute charts provided, the exact mechanics of why day traders get chopped up—and why swing traders can capture asymmetric risk/reward—become visually clear.

The Setup: Daily Floor Hold vs. 30m Volume Surge
Look at the structural alignment across these timeframes:
GJ3eNwT.png

Daily Chart (Left): Testing Structural Macro Support
Price has retraced hard from the June highs near $296 down to test the major horizontal shelf around $183.60–$187.55.​
Notice how this level directly aligns with the March/April breakout structure.​
In market structure terms, this is a prior resistance level flipping into macro support.​
On Friday (August 28, 2026), price closed at $185.64 (down 6.84% on the day) after printing a low of $183.60. It is sitting right inside the structural demand vault.​

30-Minute Chart (Right): Institutional Accumulation Surge
While the daily looks like a waterfall sell-off, the 30min chart tells a completely different story: The Volume Accumulation Panel is blowing out on the right side.​
Look at the 5-bar / 20-bar volume bars on the bottom right panel: 5-bar volume expanded to 175,560 with current total volume surging past 307,746.​
The Interpretation: As price washed out into the $183.60–$187.55 macro floor, large passive/systematic algorithms stepped in to absorb supply heavily. This isn't retail panic-buying; it's block-desk execution sitting at structural support.​

The Range Play: $187.55 Macro Floor to $215.73 Ceiling
GNRC is acting like a classic high-beta range-bound stock. The volatility parameters are clearly defined by the price pivots on the daily chart:
$226.00 ── Overhead Breakout Level (Upper Supply)

$215.73 ── Primary Range Resistance Target (+16% upside from base)

$205.16 ── Mid-Range Pivot / Acceleration Point

$195.60 ── First Local Resistance / Re-entry Pivot

► $187.55 ── MACRO BUY ZONE / ABSORPTION FLOOR (Current Price: $185.64)

$180.00 ── Invalidation Zone (Hard Stop-Loss Floor)

Why the Short Swing Trader Has the Advantage
1. Low Risk / Asymmetric Upside

Risk (Stop Placement): A invalidation stop can be placed just under structural support (e.g., a 30m/1hr candle close below $180.00).​
Reward: A mean-reversion move back to mid-range ($205.16) yields ~$20/share (+10.5%), while a complete swing up to upper range resistance ($215.73) yields ~$30/share (+16%).​
Risk-to-Reward Ratio: Better than 1 : 3.5.​

2. Avoiding Intraday Execution Traps
Day traders get crushed on GNRC because intraday market orders suffer slippage in thin ask queues, and algorithms actively sweep stops above/below tight intraday consolidations.

By taking a 2-to-5 day swing position, you give the trade room to breathe through intraday noise. You allow the high-volume absorption on the 30-minute chart time to play out into a sustained multiday recovery push.

Execution Protocol for the Swing Trade
Entry Strategy (Limit Orders Only):​
Scale into a position in the $183.50 – $187.55 zone. Do not use market orders. Let the high-volume sell-side sweep fill your limit bid.​

Invalidation (Hard Risk Control):​
Exit the trade if the Daily candle closes below $180.00. A daily close below structural support invalidates the range-bound narrative.​

Profit Target Scaling:​
Target 1 ($195.60): Lock in 1/3 of the position to bring risk to breakeven.​
Target 2 ($205.16): Sell another 1/3 at the mid-range structural pivot.​
Target 3 ($215.73): Exit the final tranche right below range resistance before the next institutional rebalancing wall.​
 
NOW breaking past the bearish VFVG already tested the double bottom break out from june/july, looking to run past 150

Code:
# Volumatic Fair Value Gaps - thinkScript Adaptation
# Original Pine Script: "Volumatic Fair Value Gaps [BigBeluga]"
# Original copyright (c) BigBeluga
# Licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0
# https://creativecommons.org/licenses/by-nc-sa/4.0/
# Adaptation and modifications: OpenAI, 2026-08-30. Same license.
#
# COMPLETE, STANDALONE UPPER STUDY. LABELS INSTEAD OF A TABLE.
#
# PRESERVED:
# - Original 3-candle bullish/bearish gap conditions.
# - Gap size > 10% of the largest diff in the 1000-bar filter window.
# - Strict far-edge mitigation: below bullish bottom / above bearish top.
# - Up to 10 active zones; oldest is replaced only when all slots are full.
#
# ADAPTATIONS / LIMITS:
# - TOS cannot request lower-timeframe volume arrays on a higher-timeframe chart.
#   Volume is the MIDDLE CANDLE'S TOTAL chart volume, not the Pine intrabar sum.
#   Bullish/bearish volume percentages are deliberately NOT fabricated.
# - Deterministic overlap rule: newest gap replaces older overlapping gaps.
#   This differs from the Pine script's nested array-removal loop.
# - Clouds show zone lifecycles on real bars. Historical footprints remain
#   after mitigation; only active zones count in the labels.
# - No box backdating, no 25-bar future projection, no future-price references.
# - LIVE by default, like the source. A developing candle can create/remove
#   a provisional zone. completedBarsOnly=yes processes the prior closed bar.
# - Slot replacement includes a one-bar visual break to avoid diagonal clouds.
# - This is a gap-location study, NOT buy/sell orders or a win-rate model.

declare upper;

input mitigationSource = {default Close, HighLow};
input bullGaps = yes;
input bearGaps = yes;
input showZones = yes;
input showBorders = yes;
input showLabels = yes;
input showVolumeLabels = yes;
input completedBarsOnly = no;
input filterLookback = 1000;
input minimumRelativeGap = 10.0;
input removeOverlaps = yes;

DefineGlobalColor("BullFVG", CreateColor(26, 194, 216));
DefineGlobalColor("BearFVG", CreateColor(216, 118, 26));

Assert(filterLookback >= 1, "filterLookback must be at least 1.");
Assert(minimumRelativeGap >= 0, "minimumRelativeGap cannot be negative.");

def bn = BarNumber();
def realBar = !IsNaN(close);

# At the 100th percentile, nearest-rank percentile equals the maximum.
# Preserve the original diff branch based on the middle candle's direction.
def diff = if close[1] > open[1]
           then (if low != 0 then (low - high[2]) / low * 100 else Double.NaN)
           else (if high != 0 then (low[2] - high) / high * 100 else Double.NaN);
def largestDiff = Highest(diff, filterLookback);
def relativeGap = if !IsNaN(largestDiff) and largestDiff > 0
                  then diff / largestDiff * 100 else 0;
def filterPass = relativeGap > minimumRelativeGap;

def rawBull = high[2] < low and high[2] < high[1]
              and low[2] < low and filterPass;
def rawBear = low[2] > high and low[2] > low[1]
              and high[2] > high and filterPass;

# All event fields and mitigation prices share the selected processing bar.
def eventReady = realBar and
    (if completedBarsOnly then bn > 102 else bn > 101);
def makeBull = eventReady and bullGaps and
    (if completedBarsOnly then rawBull[1] else rawBull);
def makeBear = eventReady and bearGaps and
    (if completedBarsOnly then rawBear[1] else rawBear);
def newGap = makeBull or makeBear;
def gapSide = if makeBull then 1 else -1;

def newTop = if makeBull
             then (if completedBarsOnly then low[1] else low)
             else (if completedBarsOnly then low[3] else low[2]);
def newBottom = if makeBull
                then (if completedBarsOnly then high[3] else high[2])
                else (if completedBarsOnly then high[1] else high);

def middleVolume = if completedBarsOnly then volume[2] else volume[1];
def newVolumeKnown = !IsNaN(middleVolume);
def newVolume = if newVolumeKnown then middleVolume else 0;

def processClose = if completedBarsOnly then close[1] else close;
def processLow = if completedBarsOnly then low[1] else low;
def processHigh = if completedBarsOnly then high[1] else high;
def bullMitigationPrice = if mitigationSource == mitigationSource.Close
                          then processClose else processLow;
def bearMitigationPrice = if mitigationSource == mitigationSource.Close
                          then processClose else processHigh;

# Declare slot state before the history-based allocation expressions.
def active1; def top1; def bottom1; def side1;
def born1; def vol1; def volumeKnown1;
def active2; def top2; def bottom2; def side2;
def born2; def vol2; def volumeKnown2;
def active3; def top3; def bottom3; def side3;
def born3; def vol3; def volumeKnown3;
def active4; def top4; def bottom4; def side4;
def born4; def vol4; def volumeKnown4;
def active5; def top5; def bottom5; def side5;
def born5; def vol5; def volumeKnown5;
def active6; def top6; def bottom6; def side6;
def born6; def vol6; def volumeKnown6;
def active7; def top7; def bottom7; def side7;
def born7; def vol7; def volumeKnown7;
def active8; def top8; def bottom8; def side8;
def born8; def vol8; def volumeKnown8;
def active9; def top9; def bottom9; def side9;
def born9; def vol9; def volumeKnown9;
def active10; def top10; def bottom10; def side10;
def born10; def vol10; def volumeKnown10;

# Retire mitigated zones first. On overlap, prefer the newly detected zone.
def keep1 = active1[1] == 1
    and !(realBar and
          ((side1[1] == 1 and bullMitigationPrice < bottom1[1])
           or (side1[1] == -1 and bearMitigationPrice > top1[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom1[1] and newBottom < top1[1]);
def keep2 = active2[1] == 1
    and !(realBar and
          ((side2[1] == 1 and bullMitigationPrice < bottom2[1])
           or (side2[1] == -1 and bearMitigationPrice > top2[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom2[1] and newBottom < top2[1]);
def keep3 = active3[1] == 1
    and !(realBar and
          ((side3[1] == 1 and bullMitigationPrice < bottom3[1])
           or (side3[1] == -1 and bearMitigationPrice > top3[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom3[1] and newBottom < top3[1]);
def keep4 = active4[1] == 1
    and !(realBar and
          ((side4[1] == 1 and bullMitigationPrice < bottom4[1])
           or (side4[1] == -1 and bearMitigationPrice > top4[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom4[1] and newBottom < top4[1]);
def keep5 = active5[1] == 1
    and !(realBar and
          ((side5[1] == 1 and bullMitigationPrice < bottom5[1])
           or (side5[1] == -1 and bearMitigationPrice > top5[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom5[1] and newBottom < top5[1]);
def keep6 = active6[1] == 1
    and !(realBar and
          ((side6[1] == 1 and bullMitigationPrice < bottom6[1])
           or (side6[1] == -1 and bearMitigationPrice > top6[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom6[1] and newBottom < top6[1]);
def keep7 = active7[1] == 1
    and !(realBar and
          ((side7[1] == 1 and bullMitigationPrice < bottom7[1])
           or (side7[1] == -1 and bearMitigationPrice > top7[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom7[1] and newBottom < top7[1]);
def keep8 = active8[1] == 1
    and !(realBar and
          ((side8[1] == 1 and bullMitigationPrice < bottom8[1])
           or (side8[1] == -1 and bearMitigationPrice > top8[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom8[1] and newBottom < top8[1]);
def keep9 = active9[1] == 1
    and !(realBar and
          ((side9[1] == 1 and bullMitigationPrice < bottom9[1])
           or (side9[1] == -1 and bearMitigationPrice > top9[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom9[1] and newBottom < top9[1]);
def keep10 = active10[1] == 1
    and !(realBar and
          ((side10[1] == 1 and bullMitigationPrice < bottom10[1])
           or (side10[1] == -1 and bearMitigationPrice > top10[1])))
    and !(newGap and removeOverlaps
          and newTop > bottom10[1] and newBottom < top10[1]);

def oldestBorn = Min(born1[1], Min(born2[1], Min(born3[1], Min(born4[1], Min(born5[1], Min(born6[1], Min(born7[1], Min(born8[1], Min(born9[1], born10[1])))))))));
def place = if !newGap then 0
    else if !keep1 then 1
    else if !keep2 then 2
    else if !keep3 then 3
    else if !keep4 then 4
    else if !keep5 then 5
    else if !keep6 then 6
    else if !keep7 then 7
    else if !keep8 then 8
    else if !keep9 then 9
    else if !keep10 then 10
    else if born1[1] == oldestBorn then 1
    else if born2[1] == oldestBorn then 2
    else if born3[1] == oldestBorn then 3
    else if born4[1] == oldestBorn then 4
    else if born5[1] == oldestBorn then 5
    else if born6[1] == oldestBorn then 6
    else if born7[1] == oldestBorn then 7
    else if born8[1] == oldestBorn then 8
    else if born9[1] == oldestBorn then 9
    else 10;

# Fixed-size memory: inactive slots are reused before any live zone is evicted.
active1 = CompoundValue(1, if place == 1 then 1 else if keep1 then 1 else 0, 0);
top1 = CompoundValue(1, if place == 1 then newTop else top1[1], 0);
bottom1 = CompoundValue(1, if place == 1 then newBottom else bottom1[1], 0);
side1 = CompoundValue(1, if place == 1 then gapSide else side1[1], 0);
born1 = CompoundValue(1, if place == 1 then bn else born1[1], 0);
vol1 = CompoundValue(1, if place == 1 then newVolume else vol1[1], 0);
volumeKnown1 = CompoundValue(1,
    if place == 1 then newVolumeKnown else volumeKnown1[1], 0);

active2 = CompoundValue(1, if place == 2 then 1 else if keep2 then 1 else 0, 0);
top2 = CompoundValue(1, if place == 2 then newTop else top2[1], 0);
bottom2 = CompoundValue(1, if place == 2 then newBottom else bottom2[1], 0);
side2 = CompoundValue(1, if place == 2 then gapSide else side2[1], 0);
born2 = CompoundValue(1, if place == 2 then bn else born2[1], 0);
vol2 = CompoundValue(1, if place == 2 then newVolume else vol2[1], 0);
volumeKnown2 = CompoundValue(1,
    if place == 2 then newVolumeKnown else volumeKnown2[1], 0);

active3 = CompoundValue(1, if place == 3 then 1 else if keep3 then 1 else 0, 0);
top3 = CompoundValue(1, if place == 3 then newTop else top3[1], 0);
bottom3 = CompoundValue(1, if place == 3 then newBottom else bottom3[1], 0);
side3 = CompoundValue(1, if place == 3 then gapSide else side3[1], 0);
born3 = CompoundValue(1, if place == 3 then bn else born3[1], 0);
vol3 = CompoundValue(1, if place == 3 then newVolume else vol3[1], 0);
volumeKnown3 = CompoundValue(1,
    if place == 3 then newVolumeKnown else volumeKnown3[1], 0);

active4 = CompoundValue(1, if place == 4 then 1 else if keep4 then 1 else 0, 0);
top4 = CompoundValue(1, if place == 4 then newTop else top4[1], 0);
bottom4 = CompoundValue(1, if place == 4 then newBottom else bottom4[1], 0);
side4 = CompoundValue(1, if place == 4 then gapSide else side4[1], 0);
born4 = CompoundValue(1, if place == 4 then bn else born4[1], 0);
vol4 = CompoundValue(1, if place == 4 then newVolume else vol4[1], 0);
volumeKnown4 = CompoundValue(1,
    if place == 4 then newVolumeKnown else volumeKnown4[1], 0);

active5 = CompoundValue(1, if place == 5 then 1 else if keep5 then 1 else 0, 0);
top5 = CompoundValue(1, if place == 5 then newTop else top5[1], 0);
bottom5 = CompoundValue(1, if place == 5 then newBottom else bottom5[1], 0);
side5 = CompoundValue(1, if place == 5 then gapSide else side5[1], 0);
born5 = CompoundValue(1, if place == 5 then bn else born5[1], 0);
vol5 = CompoundValue(1, if place == 5 then newVolume else vol5[1], 0);
volumeKnown5 = CompoundValue(1,
    if place == 5 then newVolumeKnown else volumeKnown5[1], 0);

active6 = CompoundValue(1, if place == 6 then 1 else if keep6 then 1 else 0, 0);
top6 = CompoundValue(1, if place == 6 then newTop else top6[1], 0);
bottom6 = CompoundValue(1, if place == 6 then newBottom else bottom6[1], 0);
side6 = CompoundValue(1, if place == 6 then gapSide else side6[1], 0);
born6 = CompoundValue(1, if place == 6 then bn else born6[1], 0);
vol6 = CompoundValue(1, if place == 6 then newVolume else vol6[1], 0);
volumeKnown6 = CompoundValue(1,
    if place == 6 then newVolumeKnown else volumeKnown6[1], 0);

active7 = CompoundValue(1, if place == 7 then 1 else if keep7 then 1 else 0, 0);
top7 = CompoundValue(1, if place == 7 then newTop else top7[1], 0);
bottom7 = CompoundValue(1, if place == 7 then newBottom else bottom7[1], 0);
side7 = CompoundValue(1, if place == 7 then gapSide else side7[1], 0);
born7 = CompoundValue(1, if place == 7 then bn else born7[1], 0);
vol7 = CompoundValue(1, if place == 7 then newVolume else vol7[1], 0);
volumeKnown7 = CompoundValue(1,
    if place == 7 then newVolumeKnown else volumeKnown7[1], 0);

active8 = CompoundValue(1, if place == 8 then 1 else if keep8 then 1 else 0, 0);
top8 = CompoundValue(1, if place == 8 then newTop else top8[1], 0);
bottom8 = CompoundValue(1, if place == 8 then newBottom else bottom8[1], 0);
side8 = CompoundValue(1, if place == 8 then gapSide else side8[1], 0);
born8 = CompoundValue(1, if place == 8 then bn else born8[1], 0);
vol8 = CompoundValue(1, if place == 8 then newVolume else vol8[1], 0);
volumeKnown8 = CompoundValue(1,
    if place == 8 then newVolumeKnown else volumeKnown8[1], 0);

active9 = CompoundValue(1, if place == 9 then 1 else if keep9 then 1 else 0, 0);
top9 = CompoundValue(1, if place == 9 then newTop else top9[1], 0);
bottom9 = CompoundValue(1, if place == 9 then newBottom else bottom9[1], 0);
side9 = CompoundValue(1, if place == 9 then gapSide else side9[1], 0);
born9 = CompoundValue(1, if place == 9 then bn else born9[1], 0);
vol9 = CompoundValue(1, if place == 9 then newVolume else vol9[1], 0);
volumeKnown9 = CompoundValue(1,
    if place == 9 then newVolumeKnown else volumeKnown9[1], 0);

active10 = CompoundValue(1, if place == 10 then 1 else if keep10 then 1 else 0, 0);
top10 = CompoundValue(1, if place == 10 then newTop else top10[1], 0);
bottom10 = CompoundValue(1, if place == 10 then newBottom else bottom10[1], 0);
side10 = CompoundValue(1, if place == 10 then gapSide else side10[1], 0);
born10 = CompoundValue(1, if place == 10 then bn else born10[1], 0);
vol10 = CompoundValue(1, if place == 10 then newVolume else vol10[1], 0);
volumeKnown10 = CompoundValue(1,
    if place == 10 then newVolumeKnown else volumeKnown10[1], 0);

# Cloud input order supplies the direction color without dynamic color arguments.
# Plot wrappers keep recursive state out of direct AddCloud arguments.
# Boundaries are drawn only on real bars while each zone was active.

def draw1 = showZones and realBar and active1 == 1
              and (active1[1] == 0 or born1 == born1[1]);
plot Zone1A = if draw1
                then (if side1 == 1 then top1 else bottom1)
                else Double.NaN;
plot Zone1B = if draw1
                then (if side1 == 1 then bottom1 else top1)
                else Double.NaN;
Zone1A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone1B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone1A.AssignValueColor(if side1 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone1B.AssignValueColor(if side1 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone1A.SetHiding(!showBorders);
Zone1B.SetHiding(!showBorders);
Zone1A.HideBubble(); Zone1B.HideBubble();
Zone1A.HideTitle(); Zone1B.HideTitle();
AddCloud(Zone1A, Zone1B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw2 = showZones and realBar and active2 == 1
              and (active2[1] == 0 or born2 == born2[1]);
plot Zone2A = if draw2
                then (if side2 == 1 then top2 else bottom2)
                else Double.NaN;
plot Zone2B = if draw2
                then (if side2 == 1 then bottom2 else top2)
                else Double.NaN;
Zone2A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone2B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone2A.AssignValueColor(if side2 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone2B.AssignValueColor(if side2 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone2A.SetHiding(!showBorders);
Zone2B.SetHiding(!showBorders);
Zone2A.HideBubble(); Zone2B.HideBubble();
Zone2A.HideTitle(); Zone2B.HideTitle();
AddCloud(Zone2A, Zone2B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw3 = showZones and realBar and active3 == 1
              and (active3[1] == 0 or born3 == born3[1]);
plot Zone3A = if draw3
                then (if side3 == 1 then top3 else bottom3)
                else Double.NaN;
plot Zone3B = if draw3
                then (if side3 == 1 then bottom3 else top3)
                else Double.NaN;
Zone3A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone3B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone3A.AssignValueColor(if side3 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone3B.AssignValueColor(if side3 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone3A.SetHiding(!showBorders);
Zone3B.SetHiding(!showBorders);
Zone3A.HideBubble(); Zone3B.HideBubble();
Zone3A.HideTitle(); Zone3B.HideTitle();
AddCloud(Zone3A, Zone3B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw4 = showZones and realBar and active4 == 1
              and (active4[1] == 0 or born4 == born4[1]);
plot Zone4A = if draw4
                then (if side4 == 1 then top4 else bottom4)
                else Double.NaN;
plot Zone4B = if draw4
                then (if side4 == 1 then bottom4 else top4)
                else Double.NaN;
Zone4A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone4B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone4A.AssignValueColor(if side4 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone4B.AssignValueColor(if side4 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone4A.SetHiding(!showBorders);
Zone4B.SetHiding(!showBorders);
Zone4A.HideBubble(); Zone4B.HideBubble();
Zone4A.HideTitle(); Zone4B.HideTitle();
AddCloud(Zone4A, Zone4B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw5 = showZones and realBar and active5 == 1
              and (active5[1] == 0 or born5 == born5[1]);
plot Zone5A = if draw5
                then (if side5 == 1 then top5 else bottom5)
                else Double.NaN;
plot Zone5B = if draw5
                then (if side5 == 1 then bottom5 else top5)
                else Double.NaN;
Zone5A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone5B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone5A.AssignValueColor(if side5 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone5B.AssignValueColor(if side5 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone5A.SetHiding(!showBorders);
Zone5B.SetHiding(!showBorders);
Zone5A.HideBubble(); Zone5B.HideBubble();
Zone5A.HideTitle(); Zone5B.HideTitle();
AddCloud(Zone5A, Zone5B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw6 = showZones and realBar and active6 == 1
              and (active6[1] == 0 or born6 == born6[1]);
plot Zone6A = if draw6
                then (if side6 == 1 then top6 else bottom6)
                else Double.NaN;
plot Zone6B = if draw6
                then (if side6 == 1 then bottom6 else top6)
                else Double.NaN;
Zone6A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone6B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone6A.AssignValueColor(if side6 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone6B.AssignValueColor(if side6 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone6A.SetHiding(!showBorders);
Zone6B.SetHiding(!showBorders);
Zone6A.HideBubble(); Zone6B.HideBubble();
Zone6A.HideTitle(); Zone6B.HideTitle();
AddCloud(Zone6A, Zone6B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw7 = showZones and realBar and active7 == 1
              and (active7[1] == 0 or born7 == born7[1]);
plot Zone7A = if draw7
                then (if side7 == 1 then top7 else bottom7)
                else Double.NaN;
plot Zone7B = if draw7
                then (if side7 == 1 then bottom7 else top7)
                else Double.NaN;
Zone7A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone7B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone7A.AssignValueColor(if side7 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone7B.AssignValueColor(if side7 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone7A.SetHiding(!showBorders);
Zone7B.SetHiding(!showBorders);
Zone7A.HideBubble(); Zone7B.HideBubble();
Zone7A.HideTitle(); Zone7B.HideTitle();
AddCloud(Zone7A, Zone7B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw8 = showZones and realBar and active8 == 1
              and (active8[1] == 0 or born8 == born8[1]);
plot Zone8A = if draw8
                then (if side8 == 1 then top8 else bottom8)
                else Double.NaN;
plot Zone8B = if draw8
                then (if side8 == 1 then bottom8 else top8)
                else Double.NaN;
Zone8A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone8B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone8A.AssignValueColor(if side8 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone8B.AssignValueColor(if side8 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone8A.SetHiding(!showBorders);
Zone8B.SetHiding(!showBorders);
Zone8A.HideBubble(); Zone8B.HideBubble();
Zone8A.HideTitle(); Zone8B.HideTitle();
AddCloud(Zone8A, Zone8B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw9 = showZones and realBar and active9 == 1
              and (active9[1] == 0 or born9 == born9[1]);
plot Zone9A = if draw9
                then (if side9 == 1 then top9 else bottom9)
                else Double.NaN;
plot Zone9B = if draw9
                then (if side9 == 1 then bottom9 else top9)
                else Double.NaN;
Zone9A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone9B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone9A.AssignValueColor(if side9 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone9B.AssignValueColor(if side9 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone9A.SetHiding(!showBorders);
Zone9B.SetHiding(!showBorders);
Zone9A.HideBubble(); Zone9B.HideBubble();
Zone9A.HideTitle(); Zone9B.HideTitle();
AddCloud(Zone9A, Zone9B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

def draw10 = showZones and realBar and active10 == 1
              and (active10[1] == 0 or born10 == born10[1]);
plot Zone10A = if draw10
                then (if side10 == 1 then top10 else bottom10)
                else Double.NaN;
plot Zone10B = if draw10
                then (if side10 == 1 then bottom10 else top10)
                else Double.NaN;
Zone10A.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone10B.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Zone10A.AssignValueColor(if side10 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone10B.AssignValueColor(if side10 == 1 then GlobalColor("BullFVG") else GlobalColor("BearFVG"));
Zone10A.SetHiding(!showBorders);
Zone10B.SetHiding(!showBorders);
Zone10A.HideBubble(); Zone10B.HideBubble();
Zone10A.HideTitle(); Zone10B.HideTitle();
AddCloud(Zone10A, Zone10B, GlobalColor("BullFVG"), GlobalColor("BearFVG"));

# LABELS: counts and summed middle-candle volume for ACTIVE zones only.
def bullCount = (if active1 == 1 and side1 == 1 then 1 else 0)
    + (if active2 == 1 and side2 == 1 then 1 else 0)
    + (if active3 == 1 and side3 == 1 then 1 else 0)
    + (if active4 == 1 and side4 == 1 then 1 else 0)
    + (if active5 == 1 and side5 == 1 then 1 else 0)
    + (if active6 == 1 and side6 == 1 then 1 else 0)
    + (if active7 == 1 and side7 == 1 then 1 else 0)
    + (if active8 == 1 and side8 == 1 then 1 else 0)
    + (if active9 == 1 and side9 == 1 then 1 else 0)
    + (if active10 == 1 and side10 == 1 then 1 else 0);
def bullVolume = (if active1 == 1 and side1 == 1 then vol1 else 0)
    + (if active2 == 1 and side2 == 1 then vol2 else 0)
    + (if active3 == 1 and side3 == 1 then vol3 else 0)
    + (if active4 == 1 and side4 == 1 then vol4 else 0)
    + (if active5 == 1 and side5 == 1 then vol5 else 0)
    + (if active6 == 1 and side6 == 1 then vol6 else 0)
    + (if active7 == 1 and side7 == 1 then vol7 else 0)
    + (if active8 == 1 and side8 == 1 then vol8 else 0)
    + (if active9 == 1 and side9 == 1 then vol9 else 0)
    + (if active10 == 1 and side10 == 1 then vol10 else 0);
def bullMissingVolume = (if active1 == 1 and side1 == 1 and !volumeKnown1 then 1 else 0)
    + (if active2 == 1 and side2 == 1 and !volumeKnown2 then 1 else 0)
    + (if active3 == 1 and side3 == 1 and !volumeKnown3 then 1 else 0)
    + (if active4 == 1 and side4 == 1 and !volumeKnown4 then 1 else 0)
    + (if active5 == 1 and side5 == 1 and !volumeKnown5 then 1 else 0)
    + (if active6 == 1 and side6 == 1 and !volumeKnown6 then 1 else 0)
    + (if active7 == 1 and side7 == 1 and !volumeKnown7 then 1 else 0)
    + (if active8 == 1 and side8 == 1 and !volumeKnown8 then 1 else 0)
    + (if active9 == 1 and side9 == 1 and !volumeKnown9 then 1 else 0)
    + (if active10 == 1 and side10 == 1 and !volumeKnown10 then 1 else 0);
def bearCount = (if active1 == 1 and side1 == -1 then 1 else 0)
    + (if active2 == 1 and side2 == -1 then 1 else 0)
    + (if active3 == 1 and side3 == -1 then 1 else 0)
    + (if active4 == 1 and side4 == -1 then 1 else 0)
    + (if active5 == 1 and side5 == -1 then 1 else 0)
    + (if active6 == 1 and side6 == -1 then 1 else 0)
    + (if active7 == 1 and side7 == -1 then 1 else 0)
    + (if active8 == 1 and side8 == -1 then 1 else 0)
    + (if active9 == 1 and side9 == -1 then 1 else 0)
    + (if active10 == 1 and side10 == -1 then 1 else 0);
def bearVolume = (if active1 == 1 and side1 == -1 then vol1 else 0)
    + (if active2 == 1 and side2 == -1 then vol2 else 0)
    + (if active3 == 1 and side3 == -1 then vol3 else 0)
    + (if active4 == 1 and side4 == -1 then vol4 else 0)
    + (if active5 == 1 and side5 == -1 then vol5 else 0)
    + (if active6 == 1 and side6 == -1 then vol6 else 0)
    + (if active7 == 1 and side7 == -1 then vol7 else 0)
    + (if active8 == 1 and side8 == -1 then vol8 else 0)
    + (if active9 == 1 and side9 == -1 then vol9 else 0)
    + (if active10 == 1 and side10 == -1 then vol10 else 0);
def bearMissingVolume = (if active1 == 1 and side1 == -1 and !volumeKnown1 then 1 else 0)
    + (if active2 == 1 and side2 == -1 and !volumeKnown2 then 1 else 0)
    + (if active3 == 1 and side3 == -1 and !volumeKnown3 then 1 else 0)
    + (if active4 == 1 and side4 == -1 and !volumeKnown4 then 1 else 0)
    + (if active5 == 1 and side5 == -1 and !volumeKnown5 then 1 else 0)
    + (if active6 == 1 and side6 == -1 and !volumeKnown6 then 1 else 0)
    + (if active7 == 1 and side7 == -1 and !volumeKnown7 then 1 else 0)
    + (if active8 == 1 and side8 == -1 and !volumeKnown8 then 1 else 0)
    + (if active9 == 1 and side9 == -1 and !volumeKnown9 then 1 else 0)
    + (if active10 == 1 and side10 == -1 and !volumeKnown10 then 1 else 0);

AddLabel(showLabels,
    "BULL FVG: " + bullCount +
    (if !showVolumeLabels then ""
     else if bullMissingVolume > 0 then " | BAR VOL: N/A"
     else if bullVolume >= 1000000000 then " | BAR VOL: " + Round(bullVolume / 1000000000, 2) + "B"
     else if bullVolume >= 1000000 then " | BAR VOL: " + Round(bullVolume / 1000000, 2) + "M"
     else if bullVolume >= 1000 then " | BAR VOL: " + Round(bullVolume / 1000, 1) + "K"
     else " | BAR VOL: " + Round(bullVolume, 0)),
    GlobalColor("BullFVG"));

AddLabel(showLabels,
    "BEAR FVG: " + bearCount +
    (if !showVolumeLabels then ""
     else if bearMissingVolume > 0 then " | BAR VOL: N/A"
     else if bearVolume >= 1000000000 then " | BAR VOL: " + Round(bearVolume / 1000000000, 2) + "B"
     else if bearVolume >= 1000000 then " | BAR VOL: " + Round(bearVolume / 1000000, 2) + "M"
     else if bearVolume >= 1000 then " | BAR VOL: " + Round(bearVolume / 1000, 1) + "K"
     else " | BAR VOL: " + Round(bearVolume, 0)),
    GlobalColor("BearFVG"));

AddLabel(showLabels and IsNaN(largestDiff),
    "FVG FILTER: LOAD MORE CHART HISTORY", Color.GRAY);
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
781 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top