Isolated Scroll Container

1. Multitimeframe Order Block Finder Strategy Description

On every candle, the indicator reads a chosen timeframe and waits for a run of consecutive same-colour candles (5 by default). When the run is complete it drops a grey Order Block box on the candle that sat just before the move, splits it with a dashed midline and two half-boxes showing where that candle closed inside its range, keeps the box alive until price eats into it, and can list every live box in a side table and draw a smoothed "OB trend" line.

1.1 Indicator Concept

The indicator answers four simple questions: "Where did a strong one-directional push start? Who had the last word on the candle that launched it? Has price already come back and used that zone up? And, overall, which way are these zones pulling the market?" The zone it hunts for is called an Order Block (OB) — the area where big players are believed to have left unfilled orders before moving the price.

  • An OB is the base of a sustained push. When price prints several candles in a row in the same direction (5 by default), the candle sitting shortly before that run is treated as the place the push was launched from. After a run of up candles the box is called a Bullish OB (a demand zone, expected to sit below price). After a run of down candles it is a Bearish OB (a supply zone, expected to sit above price). The belief: price tends to come back to such a zone and react.
  • Strength comes from the length of the run. More consecutive candles = a more convincing push, but fewer zones. An optional "enhanced" mode replaces "every candle has the right colour" with "a smoothed average of the closes keeps rising / falling", and an optional minimum-move filter throws away pushes that were too small.
  • Any timeframe, drawn on any chart. The OB can be computed on a timeframe different from the one you look at (for example 1-hour zones on a 15-minute chart). Higher-timeframe zones are bigger and are usually treated as more important.
  • Reading the OB candle: who closed it? Inside each box, two half-boxes show where the OB candle closed within its own high–low range. A close near the high = buyers had the last word (long green-aqua bar); a close near the low = sellers had it (long red bar). Despite the "volume" wording in the code, no real volume is used — it is purely the close position in the range.
  • A zone dies when price uses it up ("mitigation"). By default a box is deleted as soon as price reaches its midpoint. Only unused zones stay on the chart, so the screen shows "zones still waiting for price".
  • The OB trend line. Every time a new OB appears, a running level is pulled halfway toward the current price; a low-pass filter then smooths that stepped level into a trend line, coloured by its direction.

In short: it is an automatic supply & demand zone finder based on candle-colour runs, with zone bookkeeping (alive / used up), a mini "buyer vs seller" read of the OB candle, and a slow trend gauge. It is a pattern-based detector, not a volume tool.

1.2 Indicator Features

  • Display:
    • The OB box: a grey box (85% transparent) covering the high-to-low range of the OB candle. Bullish and bearish OBs look identical — you tell them apart by where they sit relative to price. The box has a fixed width (100 bars by default) starting at the OB candle; it does not stretch to the present, so an old, still-valid zone appears as a short box far to the left.
    • The midline: a white dashed line across the box at exactly half of its range (mid price).
    • Two half-boxes (buy / sell split): the lower half of the OB range holds a green-aqua bar whose length is "buy %" of the box width; the upper half holds a red bar whose length is "sell %". They always add up to 100% of the width. Both colours are 50% transparent by default.
    • The OB table (optional, off by default): a column on the right-hand margin of the chart (about 50–100 bars after the last candle) that repeats every live OB at its price level, with the OB's date and time written inside. Each copy is red if the current close is below the zone's upper edge, otherwise green-aqua. A thin grey frame spans the whole price history behind it.
    • The OB trend line (optional, off by default): a smooth line drawn lime while it is rising and red while it is falling, with a soft gradient fill (70% transparent) between the line and a short average.
  • Alerts: 9 ready-made alertcondition() entries, three events × three versions (bullish / bearish / any):
    • OB Created — a new box has just been drawn.
    • OB Retested — the first time a box is "touched" (see the technical notes: with the code as written, this only happens on a candle that swallows the whole OB range).
    • OB Mitigated — a box was used up and deleted.

1.3 How to Use the Indicator

  • Treat every box as a "waiting zone". A grey box below price is a demand zone to watch for long entries; a box above price is a supply zone to watch for shorts. The box is still on the chart only because price has not consumed it yet.
  • Trade the return, not the creation. The box appears right after the run, when price is already far away. The classic plan is to wait for price to come back to the zone and look for a reaction there (a rejection candle, a lower-timeframe shift, etc.). The indicator does not give an entry signal by itself.
  • Use the midline as the "half-way" level. By default the zone is deleted when price touches the midline, so the midline is also the line past which the zone is considered used. A reaction that begins at or before the midline is the cleaner case.
  • Read the buy / sell split as a tie-breaker. Example: a bullish OB whose lower green bar is long (close near the high of the OB candle) shows the base candle itself closed strong; a short green bar says the base candle closed weak. It is a quick quality hint, not a volume measurement.
  • Pick the timeframe on purpose. Leave Timeframe empty to use the chart's own timeframe. Set a higher one (e.g. 60 on a 15-minute chart) to see the bigger zones while you trade the smaller chart. Avoid a timeframe lower than the chart.
  • Tune Lookback for quantity vs. quality. 3 gives many small zones; 5 (default) is a balanced start; 8+ gives rare but stronger zones. Turn on Minimum Percent move (e.g. 0.3) to ignore pushes that were too small to matter.
  • Open the OB table when the chart gets crowded. Scroll the chart a little to the right to see it: it lists every live zone with its date, so you can find the nearest zone above and below the current price without hunting on the chart.
  • Use the OB trend line as a slow bias, not a signal. A lime line says "recent OBs were created above the previous trend level", red the opposite. It reacts slowly by design, and its very first stretch on the chart is distorted (see the notes).
  • Use the alerts to stay informed. "OB Created" tells you a new zone exists; "OB Mitigated" tells you a zone you were watching is gone.

1.4 How the Indicator Works

Inputs & their role

  • tf ("Timeframe", timeframe picker, default empty = the chart's timeframe): the timeframe on which candles are read to detect OBs. Example: on an M15 chart, empty → M15 candles; "60" → H1 candles, so a run of 5 candles means 5 consecutive hourly candles. Its own tooltip is blank in the code; the explanation of this input is actually attached to "Lookback".
  • prd ("Lookback", integer, default 5, min 0, same row as Timeframe): the length of the candle run. With 5, five consecutive candles of the same colour are needed. Before/after: 3 → zones appear after only 3 candles (more, weaker); 8 → needs 8 candles (fewer, stronger). It also decides which candle becomes the OB: always the candle prd + 1 bars back (see Flow 3). Keep it at 1 or more.
  • sen ("Enhanced Candle Sensitivity", tick box, default off): off = every one of the last prd candles must close in the right direction (close above open for bullish). On = instead, a smoothed average of the closes (RMA, length 5) must keep rising (bullish) or falling (bearish) for prd bars, so a single candle of the "wrong" colour no longer cancels the run. Example: five candles up, up, down, up, up fail the default rule, but can still pass in enhanced mode if the smoothed line kept climbing.
  • perc ("Minimum Percent move", decimal, default 0.0, step 0.1): the smallest % distance between the OB candle's close and the last closed candle's close. Example: OB candle close 2646, last close 2658 → move = 12 ÷ 2646 = 0.45%. With 0.0 it passes; with 0.3 it passes; with 0.5 it is rejected. At 0.0 the filter is effectively off.
  • mit ("Mitigated on mid", tick box, default on): on = the box is deleted when price reaches the midpoint; off = the code uses a more sensitive edge test (see the technical notes — it deletes the box earlier than "on", not later as the tooltip suggests). Example: bullish OB 2644–2652, midpoint 2648. A candle with a low of 2649.5 does nothing with "on", but with "off" a low of 2651 is already enough to delete it.
  • extendLength ("Extend Boxes", integer, default 100, no limits): the width of each OB box, in bars of the chart timeframe, counted from the OB candle. Example: on M15, 100 bars = 25 hours. It only changes how wide the box is drawn; the zone stays alive until price mitigates it, however old.
  • showActive ("Show OB table", tick box, default off): turns the right-margin table of live OBs on or off. Display only — logic and alerts are unaffected.
  • TableLeft ("Table Left", integer 0–30, default 5) and TableRight ("Right", integer 10–50, default 10): where the table starts and ends, in steps of 10 bars to the right of the current candle. Defaults → from 50 to 100 bars ahead. Example: Left 5 / Right 10 = a 50-bar-wide column; Left 0 / Right 20 = starts at the last candle and is 200 bars wide. Only matters if the table is on.
  • UpCol / DnCol / Col (three colour swatches on one row, no titles): UpCol default green-aqua (#00ffbb, 50% transparent) paints the buy bars and the "green" table copies; DnCol default red (#ff1100, 50%) paints the sell bars and the "red" table copies; Col default grey (85% transparent) paints the OB box itself. Colours only.
  • showTrend ("Show OB Trend", tick box, default off), TUpCol (default lime), TDnCol (default red): switch the trend line and its fill on, and choose the colour for rising / falling. Off = nothing of the trend is drawn (the calculation still runs).
  • rp ("Passband Ripple (dB)", decimal, default 10.0, min 0.1, step 0.1, group "Trend") and fc ("Cutoff Frequency (0 to 0.5)", decimal, default 0.005, min 0.001, max 0.5, step 0.001, group "Trend"): the two knobs of the smoothing filter. fc is the speed: 0.005 is roughly "one cycle per 200 bars", so smaller = slower and smoother, larger = faster. rp shapes the filter (see the notes for a surprise about its direction). Only the trend line is affected.

Hard-coded constants (NOT inputs)

  • Smoothing length 5: the average used in enhanced mode is ta.rma(close, 5). Fixed.
  • Candle offsets: the OB candle is read at prd + 1, the reference close at [1], and the data is requested with lookahead_on.
  • Time search: the code scans up to 5000 chart bars back (for i = 0 to 4999) to find when the OB candle happened.
  • Trend settings: a 10-bar EMA (ta.ema(Trend, 10)) for the fill, 70% transparency for the fill, and a starting value of 0.0 for the trend level.
  • Drawing details: white dashed midline, date format yyyy-MM-dd HH:mm in the chart's timezone, text colour = chart text colour.
  • Limits: max_boxes_count = 500, max_bars_back = 5000; the line limit is not set, so TradingView's default of 50 lines applies (matters for the midlines).

Main logic blocks

⏱️ Flow 0 — Order of work on every candle

  • Unlike snapshot indicators, this one works on every candle of the chart, from the oldest to the newest, and remembers things between candles in lists (arrays — numbered lists of values) that live as long as the chart.
  • On each candle the order is: ① fetch data from the chosen timeframe → ② find when the OB candle happened and compute the buy/sell split → ③ check existing boxes (retest / mitigation) → ④ create a new box if a run just completed → ⑤ redraw the table (if on) → ⑥ update the trend line → ⑦ evaluate the alerts.
  • Because ③ comes before ④, a brand-new box is first checked on the next candle.

📥 Flow 1 — Fetching the candles of the chosen timeframe

  • Two requests are sent to the chosen timeframe (request.security — "ask another timeframe for numbers"). Request A returns five numbers: c1 = close of the last closed candle, cback / hback / lback = close / high / low of the candle prd + 1 back, and v = volume. Request B returns two true/false flags: green and red (the run test, Flow 2).
  • Concrete example (XAUUSD M15, empty timeframe, prd = 5): the OB candle is 6 bars back with open 2648, high 2652, low 2644, close 2646; the last closed candle closed at 2658. So hback = 2652, lback = 2644, cback = 2646, c1 = 2658.

🕯️ Flow 2 — Is there a run? (green / red)

  • Default mode (sen off): green = each of the last prd candles has close > open. red = each has close < open. The count includes the current candle.
  • Enhanced mode (sen on): green = the 5-candle RMA of closes is rising over prd bars; red = it is falling.
  • Concrete example: the last 5 candles close at 2649, 2652, 2655, 2658, 2661 and each closes above its open → green = true, red = false. The two flags can never be true at the same time.

🎯 Flow 3 — Filtering and the "once per run" trigger

  • Size filter: minMove = |cback − c1| ÷ cback × 100 ≥ perc. In the example: |2646 − 2658| ÷ 2646 × 100 = 0.45%, so with perc = 0 (or anything up to 0.45) it passes.
  • Signals: BullOB = green AND minMove, BearOB = red AND minMove.
  • Once per run: a box is created only when the signal is true now and was false on the previous candle. So a run of 12 up candles creates one Bullish OB (at the moment the 5th candle completes), not 8.
  • Which candle becomes the OB: the candle prd + 1 bars back. The run itself is made of the newest prd candles (offsets 0 to prd−1), so one candle (offset prd) sits in between and is never tested. Example (prd 5): run = offsets 0–4, in-between = offset 5, OB candle = offset 6. Because the box fires on the first candle where the run is complete, the in-between candle is, at that moment, a non-bullish candle — the last candle before the push. The OB candle's own colour is never checked.
  • If the size filter is what blocks the box, it can still appear later, in the middle of the run, as soon as the move passes the threshold; in that case the OB candle is whatever candle is prd + 1 back at that later moment.

📦 Flow 4 — Locating the OB candle in time and drawing the box

  • The numbers from Flow 1 carry prices but no time. A helper scans the chart bars from the newest backwards (up to 5000) and looks for the first bar whose high is exactly equal to hback (HBack), and the same for lback (LBack). It returns that bar's time. If nothing matches, it falls back to the current bar's time.
  • Bullish OB starts at HBack, Bearish OB starts at LBack. The box spans lback to hback, and its right edge is the start time + extendLength chart bars.
  • Three drawings per OB: the grey box, a white dashed midline at (lback + hback) ÷ 2, and the two half-boxes of Flow 5. All are stored in lists (newest first) so they can be found again later.
  • Concrete example: OB range 2644–2652 → midline 2648; start = the time of the OB candle; width 100 bars of M15 = 25 hours.
  • Every new OB also moves the trend level (Flow 8).

⚖️ Flow 5 — The buy / sell split inside the box

  • buyVol = how high the OB candle closed inside its range: (close − low) ÷ (high − low) × 100. sellVol = (high − close) ÷ (high − low) × 100. The volume figure cancels out (it only adds rounding), so this is not volume.
  • Lower half of the box (from low to midline): a green-aqua bar, length = box width × buyVol ÷ 100. Upper half (midline to high): a red bar, length = box width × sellVol ÷ 100.
  • Concrete example: close 2646, low 2644, high 2652 → buy = 2 ÷ 8 = 25%, sell = 6 ÷ 8 = 75%. On a 100-bar box: a 25-bar aqua bar in the lower half and a 75-bar red bar in the upper half → this OB candle closed weakly, near its low.
  • If the candle has no range (high = low) or no volume, the division fails and the result is "no value"; the box may then not draw correctly.

🧹 Flow 6 — Keeping boxes alive: retest and mitigation

  • On every chart candle the code walks through all stored boxes (oldest first), bullish list then bearish list, and tests the current chart candle's high and low against each box.
  • Mitigation test. Bullish box, mit on: low ≤ midline. Bearish box, mit on: high ≥ midline. With mit off, the code compares against the box edges instead (see the notes). When true, the box, its midline and both half-boxes are deleted and removed from the lists, and "mitigated" is flagged for that candle.
  • Retest test. touched = high ≥ bot AND low ≤ top with top / bot read from the box. If true and the box was not retested before, it is flagged "retested" once; the box remembers it so it never fires twice.
  • Concrete example (bullish OB 2644–2652, midline 2648, mit on): a candle with low 2649.5 → nothing. A candle with low 2647.5 → mitigated, deleted. A candle with high 2653 and low 2643 → retested and mitigated on the same candle.

🗂️ Flow 7 — The OB table (only when "Show OB table" is on)

  • On every candle the previous copies are deleted and rebuilt. First a transparent frame from the lowest low to the highest high of the entire chart history, spanning TableLeft to TableRight bars after the current candle.
  • Then, for each live bullish OB and then each bearish OB, a copy of the box is drawn in that column at the same price levels, with the OB's start date/time as its text. Colour: red if close < the box's get_bottom() value, otherwise green-aqua.
  • Example: a live zone 2644–2652 created on 2026-10-06 13:45 appears in the column with that text. If the close is 2640 (price below the zone) it is red; at 2660 it is green-aqua.

📈 Flow 8 — The OB trend line

  • The stepped level. A running number starts at 0.0. Each time an OB is created (bullish or bearish — direction does not matter) the new level = the average of the current candle's (open + high + low + close) ÷ 4 and the previous level. Between OBs, the level stays flat.
  • Concrete example: previous level 2600, new OB when the candle's OHLC average is 2660 → new level = (2660 + 2600) ÷ 2 = 2630.
  • The first levels are distorted: the first OB gives 2660 ÷ 2 = 1330, the next (OHLC average 2665) gives (2665 + 1330) ÷ 2 = 1997.5, and so on, closing the gap by half each time. It takes about 8–10 OBs before the level is near price, so the beginning of the chart can show a line far below price.
  • The colour: lime when the level just rose (price was above the previous level at the last OB), red when it fell; while flat it keeps the previous colour. Start colour: grey.
  • The smoothing: the stepped level goes through a second-order low-pass filter (a formula that blends the newest value with the two previous outputs). fc sets how slow it is, rp how it is damped. The result is the plotted "OB Trend Filter" line.
  • The fill: a gradient between the filtered line and a 10-bar EMA of the stepped level (drawn by an invisible helper line), in the trend colour at 70% transparency. If showTrend is off, the line is hidden and so is the fill.

🔔 Flow 9 — Alerts

  • Each candle produces six flags: created (bull / bear), retested (bull / bear), mitigated (bull / bear), plus "any" versions of each. The 9 alertcondition() entries just expose them. They work whether or not the table or trend line is shown.

Outputs & their role in trading

  • The OB box + midline: a map of unused supply/demand zones with a "half-way" level.
  • The buy / sell bars: a quick quality hint on how the OB candle closed.
  • The OB table: a tidy list of live zones with their dates when the chart gets busy.
  • The OB trend line: a slow directional bias, coloured lime / red.
  • The alerts: notifications for new zones, "retests" and used-up zones.
💡 Important technical notes:
  • Swapped box corners — it changes what "retest" and "mitigated on full fill" mean. The OB box is created with the low in the "top" position and the high in the "bottom" position (box.new(left, lback, right, hback)). The later checks read them back with get_top() / get_bottom() and treat them as top and bottom. As written, ① "retested" requires high ≥ OB high and low ≤ OB low — only a candle that swallows the whole OB range counts, and such a candle always also mitigates the box (even in the default mode), so retest and mitigation fire on the same candle; ② with "Mitigated on mid" off, a bullish box is deleted once low ≤ OB high (the first touch of its upper edge) and a bearish box once high ≥ OB low — this is earlier than the midline, not a "full fill" as the tooltip says. It is worth confirming visually on your own chart.
  • Look-ahead and repainting on higher timeframes. Data is requested with lookahead_on. The price numbers are shifted by one candle (safe), but the green / red run test is not shifted, so on historical bars of a higher timeframe it already "knows" the finished candle of the higher timeframe, whereas on the live bar it only knows what has printed so far. Zones can therefore appear earlier in history than they would have in real time. Leaving the timeframe empty (chart timeframe), or going higher, is the safer use; a timeframe lower than the chart is not reliable. On the live candle the run flags can flip until the candle closes.
  • Pattern, not volume. The "buy / sell" split is only the close position inside the OB candle's range. It says nothing about real traded volume.
  • Time anchoring uses exact price equality. The box start is "the most recent chart bar whose high (or low) equals the OB candle's high (or low)". If a newer bar printed the exact same price, the box starts on that newer bar instead; if none is found within 5000 bars, it starts on the current bar. On a higher timeframe, the start is the bar that made the extreme, not the opening of the higher-timeframe candle. The scan also runs on every candle (2 × up to 5000 steps), which makes the script heavy on long charts.
  • The trend line starts from zero. The stepped level begins at 0.0, so the first OBs pull it up from far below price, and the filter inherits that. Judging by the formula, rp acts as a damping factor: the default 10 dB gives a heavily damped, slow curve, a higher value is smoother still, and values near 0.1 respond faster with a little overshoot — the opposite of the tooltip wording ("higher = more fluctuations").
  • Zones never expire by time. Only price can delete an OB, so on a long chart the number of live zones can grow. Each OB uses 3 boxes (plus 1 line), and with the table on, one more box per OB. The 500-box limit and the default 50-line limit can be reached on long histories: the oldest midlines disappear first, and past the box limit TradingView deletes the oldest boxes.
  • Name trap in the code: the object called bv is the bullish group, while its field bv holds the buy-volume bars; sv is the bearish group and its field sv the sell-volume bars. Only readability is affected.
Zoom/Pan Layered Image
Background Overlay
− +

The indicator above just became a TRADING BOT — 1 AI click

📊Original indicator
→
🤖AI 1-click convert
→
⚙️Bot trading 24/7