OPEN-SOURCE SCRIPT
Diupdate

Order Block Zones (Multi, Retest Highlight & Invalidation)

973
A easy OB identificator with the conditon that it should be followed with at-least three strong/weak candles. Highlighted when re-tested (search for entry) and unvalidated once the "opposite" candle closes above/under the zone. Zones valid for 5 days then deleted.

V0.1
Catatan Rilis
Explanation of the Indicator

1. What the indicator does

This script automatically:
1. Detects “order blocks” based on impulsive price moves:
• Bullish OB = potential demand zone.
• Bearish OB = potential supply zone.
2. Draws zones as boxes that extend forward on the chart.
3. Highlights retests of these zones:
• First time price returns to a zone → it’s “validated” and visually strengthened.
• You can optionally show only validated zones.
4. Invalidates and removes zones if:
• Price closes through the zone in the opposite direction, or
• (Optionally) the zone is older than X days.
5. Triggers alerts at retest (once per zone), so you can be notified when price re-enters a zone.

2. Inputs & Settings

Section: Order Blocks
• Impulse bars (impulseBarsReq)
Number of consecutive strong candles in one direction required to define an impulse.
Example: 3 means “3 strong bullish/bearish candles in a row”.
• Base lookback (lookbackBase)
How many bars back from the end of the impulse we look for a candle in the opposite direction that becomes the base candle forming the order block.
• Bullish OB: we look for a bearish candle in that lookback range.
• Bearish OB: we look for a bullish candle in that lookback range.
• Min body/range (minBodyFactor)
Strength filter. The script checks for each impulse candle:
• body / range >= minBodyFactor
• Body = abs(close - open)
• Range = high - low
Example: 0.5 means body must be at least 50% of the entire candle range.


🕒 Section: Zone Lifetime & Display
• Limit by days (useTimeExpiry)
• ON → zones can expire by age.
• OFF → zones live until invalidated by price.
• Days valid (if used) (zoneValidityDays)
Number of days a zone is allowed to exist if the time limit is enabled. After that, the zone is deleted.
• Show Bullish OB (showBullOB)
• ON → draws bullish demand zones.
• OFF → hides them entirely.
• Show Bearish OB (showBearOB)
• ON → draws bearish supply zones.
• OFF → hides them entirely.
• Show only retested (showOnlyValidated)
• OFF → you see all newly created zones, plus retested ones (retested ones have stronger color).
• ON → only zones that have had a first retest are visibly highlighted. “Fresh” zones are drawn, but visually faded/hidden until retested.

🔔 Section: Alerts
• Enable alerts at retest (enableAlerts)
• Controls both:
• alertcondition(...) signals (for manual condition selection).
• The alert() calls (for “Any alert() function call”).

When a zone is retested for the first time:
• Bullish OB → bullRetestSignal is set to true
• Bearish OB → bearRetestSignal is set to true
• If alerts are enabled:
• A text alert is fired via alert()
• alertcondition becomes true for that bar

3. How detection works (step-by-step)

A. Impulse detection
On each bar, the script checks:
• For a bullish impulse:
1. Look back Impulse bars candles.
2. Each one must be a strong bullish candle by your Min body/range condition.
3. The current bar starts a new impulse (i.e. the previous bar did not meet the same impulse condition).
• For a bearish impulse:
Same logic, but with strong bearish candles.

If either condition is satisfied, we have the “edge” of an impulsive move.

B. Finding the base candle (order block origin)
Once an impulse is confirmed:
• Bullish OB:
• Search within Base lookback bars behind the impulse end.
• Find the first bearish candle (opposite direction).
• That candle becomes the base candle forming the OB.
• Bearish OB:
• Search within Base lookback bars behind.
• Find the first bullish candle.
• That candle becomes the base for the bearish OB.

If no suitable opposite candle is found → no zone is created.

C. Drawing the zone box
For each base candle:
• Bullish OB
• Top of the zone = open[baseIndex]
• Bottom of the zone = low[baseIndex]
• A green box is drawn from that bar to the current bar.
• Bearish OB
• Top of the zone = high[baseIndex]
• Bottom of the zone = open[baseIndex]
• A red box is drawn from that bar to the current bar.

Duplicate protection:
Before creating a new zone, we compare top/bottom with existing zones. If both levels are within a small tolerance (sameZoneTolerance), it’s treated as duplicate and is not added.

4. Retest, validation & visuals

On every new bar, for each existing zone:

Bullish OB
• Retest condition:
low <= top and high >= bot and zone has not yet been retested.
→ This means the bar’s range touches or overlaps the zone.
When this happens:
• bullRetests is set to true for that zone.
• bullRetestSignal is set true for that bar.
• If enableAlerts is ON → alert() is called and alertcondition is true.
• Visual change:
• Before retest: softer green.
• After retest: stronger green (more visible).
• If Show only retested is ON:
• Fresh zones are “hidden” (fully transparent).
• Validated zones are shown with strong color.
• Invalidation:
• If there is a bearish body close below the bottom of the zone, the zone is deleted.
• If Limit by days is ON, and zone is older than Days valid, it is deleted.

Bearish OB
Symmetric logic:
• Retest when high >= bot2 and low <= top2 and not yet retested.
• Bearish retest → bearRetestSignal = true + stronger red.
• Invalidation on bullish body close above the top of the zone.
• Expiry by age same as bullish.

5. Alerts in TradingView – how to use them

You can use the script in two ways for alerts:

A. Using named alertconditions
1. Click “Add alert…”.
2. In Condition:
• Select the indicator:
Order Block Zones (Clean Core Version)
• Then select:
• Bullish OB Retest or
• Bearish OB Retest
3. Set “Once per bar close” (recommended).
4. Save.

This will trigger alerts when the script sets bullRetestSignal / bearRetestSignal.

B. Using “Any alert() function call”
1. Add alert.
2. Under Condition, choose:
• Order Block Zones (Clean Core Version) → Any alert() function call
3. Then every time a retest happens, the script’s internal alert() calls will send the message:
• "Bullish OB re-test on $ ([tf])"
• "Bearish OB re-test on ([tf])"
Catatan Rilis
Explanation of the Indicator

A clean and powerful Order Block indicator designed for traders who want precision without complexity.
It automatically detects bullish and bearish order blocks, highlights retests, removes invalid levels, and keeps your chart focused only on the zones that matter. Built for speed, accuracy, and real-time trading decisions

1. What the indicator does

This script automatically:
1. Detects “order blocks” based on impulsive price moves:
• Bullish OB = potential demand zone.
• Bearish OB = potential supply zone.
2. Draws zones as boxes that extend forward on the chart.
3. Highlights retests of these zones:
• First time price returns to a zone → it’s “validated” and visually strengthened.
• You can optionally show only validated zones.
4. Invalidates and removes zones if:
• Price closes through the zone in the opposite direction, or
• (Optionally) the zone is older than X days.
5. Triggers alerts at retest (once per zone), so you can be notified when price re-enters a zone.



2. Inputs & Settings

🧩 Section: Order Blocks
• Impulse bars (impulseBarsReq)
Number of consecutive strong candles in one direction required to define an impulse.
Example: 3 means “3 strong bullish/bearish candles in a row”.
• Base lookback (lookbackBase)
How many bars back from the end of the impulse we look for a candle in the opposite direction that becomes the base candle forming the order block.
• Bullish OB: we look for a bearish candle in that lookback range.
• Bearish OB: we look for a bullish candle in that lookback range.
• Min body/range (minBodyFactor)
Strength filter. The script checks for each impulse candle:
• body / range >= minBodyFactor
• Body = abs(close - open)
• Range = high - low
Example: 0.5 means body must be at least 50% of the entire candle range.



🕒 Section: Zone Lifetime & Display
• Limit by days (useTimeExpiry)
• ON → zones can expire by age.
• OFF → zones live until invalidated by price.
• Days valid (if used) (zoneValidityDays)
Number of days a zone is allowed to exist if the time limit is enabled. After that, the zone is deleted.
• Show Bullish OB (showBullOB)
• ON → draws bullish demand zones.
• OFF → hides them entirely.
• Show Bearish OB (showBearOB)
• ON → draws bearish supply zones.
• OFF → hides them entirely.
• Show only retested (showOnlyValidated)
• OFF → you see all newly created zones, plus retested ones (retested ones have stronger color).
• ON → only zones that have had a first retest are visibly highlighted. “Fresh” zones are drawn, but visually faded/hidden until retested.



🔔 Section: Alerts
• Enable alerts at retest (enableAlerts)
• Controls both:
• alertcondition(...) signals (for manual condition selection).
• The alert() calls (for “Any alert() function call”).

When a zone is retested for the first time:
• Bullish OB → bullRetestSignal is set to true
• Bearish OB → bearRetestSignal is set to true
• If alerts are enabled:
• A text alert is fired via alert()
• alertcondition becomes true for that bar



3. How detection works (step-by-step)

A. Impulse detection
On each bar, the script checks:
• For a bullish impulse:
1. Look back Impulse bars candles.
2. Each one must be a strong bullish candle by your Min body/range condition.
3. The current bar starts a new impulse (i.e. the previous bar did not meet the same impulse condition).
• For a bearish impulse:
Same logic, but with strong bearish candles.

If either condition is satisfied, we have the “edge” of an impulsive move.



B. Finding the base candle (order block origin)
Once an impulse is confirmed:
• Bullish OB:
• Search within Base lookback bars behind the impulse end.
• Find the first bearish candle (opposite direction).
• That candle becomes the base candle forming the OB.
• Bearish OB:
• Search within Base lookback bars behind.
• Find the first bullish candle.
• That candle becomes the base for the bearish OB.

If no suitable opposite candle is found → no zone is created.



C. Drawing the zone box
For each base candle:
• Bullish OB
• Top of the zone = open[baseIndex]
• Bottom of the zone = low[baseIndex]
• A green box is drawn from that bar to the current bar.
• Bearish OB
• Top of the zone = high[baseIndex]
• Bottom of the zone = open[baseIndex]
• A red box is drawn from that bar to the current bar.

Duplicate protection:
Before creating a new zone, we compare top/bottom with existing zones. If both levels are within a small tolerance (sameZoneTolerance), it’s treated as duplicate and is not added.



4. Retest, validation & visuals

On every new bar, for each existing zone:

Bullish OB
• Retest condition:
low <= top and high >= bot and zone has not yet been retested.
→ This means the bar’s range touches or overlaps the zone.
When this happens:
• bullRetests is set to true for that zone.
• bullRetestSignal is set true for that bar.
• If enableAlerts is ON → alert() is called and alertcondition is true.
• Visual change:
• Before retest: softer green.
• After retest: stronger green (more visible).
• If Show only retested is ON:
• Fresh zones are “hidden” (fully transparent).
• Validated zones are shown with strong color.
• Invalidation:
• If there is a bearish body close below the bottom of the zone, the zone is deleted.
• If Limit by days is ON, and zone is older than Days valid, it is deleted.

Bearish OB
Symmetric logic:
• Retest when high >= bot2 and low <= top2 and not yet retested.
• Bearish retest → bearRetestSignal = true + stronger red.
• Invalidation on bullish body close above the top of the zone.
• Expiry by age same as bullish.



5. Alerts in TradingView – how to use them

You can use the script in two ways for alerts:

A. Using named alertconditions
1. Click “Add alert…”.
2. In Condition:
• Select the indicator:
Order Block Zones (Clean Core Version)
• Then select:
• Bullish OB Retest or
• Bearish OB Retest
3. Set “Once per bar close” (recommended).
4. Save.

This will trigger alerts when the script sets bullRetestSignal / bearRetestSignal.

B. Using “Any alert() function call”
1. Add alert.
2. Under Condition, choose:
• Order Block Zones (Clean Core Version) → Any alert() function call
3. Then every time a retest happens, the script’s internal alert() calls will send the message:
• "Bullish OB re-test on $ ([tf])"
• "Bearish OB re-test on ([tf])"
Catatan Rilis
Explanation of the Indicator

A clean and powerful Order Block indicator designed for traders who want precision without complexity.
It automatically detects bullish and bearish order blocks, highlights retests, removes invalid levels, and keeps your chart focused only on the zones that matter. Built for speed, accuracy, and real-time trading decisions

1. What the indicator does

This script automatically:
1. Detects “order blocks” based on impulsive price moves:
• Bullish OB = potential demand zone.
• Bearish OB = potential supply zone.
2. Draws zones as boxes that extend forward on the chart.
3. Highlights retests of these zones:
• First time price returns to a zone → it’s “validated” and visually strengthened.
• You can optionally show only validated zones.
4. Invalidates and removes zones if:
• Price closes through the zone in the opposite direction, or
• (Optionally) the zone is older than X days.
5. Triggers alerts at retest (once per zone), so you can be notified when price re-enters a zone.



2. Inputs & Settings

🧩 Section: Order Blocks
• Impulse bars (impulseBarsReq)
Number of consecutive strong candles in one direction required to define an impulse.
Example: 3 means “3 strong bullish/bearish candles in a row”.
• Base lookback (lookbackBase)
How many bars back from the end of the impulse we look for a candle in the opposite direction that becomes the base candle forming the order block.
• Bullish OB: we look for a bearish candle in that lookback range.
• Bearish OB: we look for a bullish candle in that lookback range.
• Min body/range (minBodyFactor)
Strength filter. The script checks for each impulse candle:
• body / range >= minBodyFactor
• Body = abs(close - open)
• Range = high - low
Example: 0.5 means body must be at least 50% of the entire candle range.



🕒 Section: Zone Lifetime & Display
• Limit by days (useTimeExpiry)
• ON → zones can expire by age.
• OFF → zones live until invalidated by price.
• Days valid (if used) (zoneValidityDays)
Number of days a zone is allowed to exist if the time limit is enabled. After that, the zone is deleted.
• Show Bullish OB (showBullOB)
• ON → draws bullish demand zones.
• OFF → hides them entirely.
• Show Bearish OB (showBearOB)
• ON → draws bearish supply zones.
• OFF → hides them entirely.
• Show only retested (showOnlyValidated)
• OFF → you see all newly created zones, plus retested ones (retested ones have stronger color).
• ON → only zones that have had a first retest are visibly highlighted. “Fresh” zones are drawn, but visually faded/hidden until retested.



🔔 Section: Alerts
• Enable alerts at retest (enableAlerts)
• Controls both:
• alertcondition(...) signals (for manual condition selection).
• The alert() calls (for “Any alert() function call”).

When a zone is retested for the first time:
• Bullish OB → bullRetestSignal is set to true
• Bearish OB → bearRetestSignal is set to true
• If alerts are enabled:
• A text alert is fired via alert()
• alertcondition becomes true for that bar



3. How detection works (step-by-step)

A. Impulse detection
On each bar, the script checks:
• For a bullish impulse:
1. Look back Impulse bars candles.
2. Each one must be a strong bullish candle by your Min body/range condition.
3. The current bar starts a new impulse (i.e. the previous bar did not meet the same impulse condition).
• For a bearish impulse:
Same logic, but with strong bearish candles.

If either condition is satisfied, we have the “edge” of an impulsive move.



B. Finding the base candle (order block origin)
Once an impulse is confirmed:
• Bullish OB:
• Search within Base lookback bars behind the impulse end.
• Find the first bearish candle (opposite direction).
• That candle becomes the base candle forming the OB.
• Bearish OB:
• Search within Base lookback bars behind.
• Find the first bullish candle.
• That candle becomes the base for the bearish OB.

If no suitable opposite candle is found → no zone is created.



C. Drawing the zone box
For each base candle:
• Bullish OB
• Top of the zone = open[baseIndex]
• Bottom of the zone = low[baseIndex]
• A green box is drawn from that bar to the current bar.
• Bearish OB
• Top of the zone = high[baseIndex]
• Bottom of the zone = open[baseIndex]
• A red box is drawn from that bar to the current bar.

Duplicate protection:
Before creating a new zone, we compare top/bottom with existing zones. If both levels are within a small tolerance (sameZoneTolerance), it’s treated as duplicate and is not added.



4. Retest, validation & visuals

On every new bar, for each existing zone:

Bullish OB
• Retest condition:
low <= top and high >= bot and zone has not yet been retested.
→ This means the bar’s range touches or overlaps the zone.
When this happens:
• bullRetests is set to true for that zone.
• bullRetestSignal is set true for that bar.
• If enableAlerts is ON → alert() is called and alertcondition is true.
• Visual change:
• Before retest: softer green.
• After retest: stronger green (more visible).
• If Show only retested is ON:
• Fresh zones are “hidden” (fully transparent).
• Validated zones are shown with strong color.
• Invalidation:
• If there is a bearish body close below the bottom of the zone, the zone is deleted.
• If Limit by days is ON, and zone is older than Days valid, it is deleted.

Bearish OB
Symmetric logic:
• Retest when high >= bot2 and low <= top2 and not yet retested.
• Bearish retest → bearRetestSignal = true + stronger red.
• Invalidation on bullish body close above the top of the zone.
• Expiry by age same as bullish.



5. Alerts in TradingView – how to use them

You can use the script in two ways for alerts:

A. Using named alertconditions
1. Click “Add alert…”.
2. In Condition:
• Select the indicator:
Order Block Zones (Clean Core Version)
• Then select:
• Bullish OB Retest or
• Bearish OB Retest
3. Set “Once per bar close” (recommended).
4. Save.

This will trigger alerts when the script sets bullRetestSignal / bearRetestSignal.

B. Using “Any alert() function call”
1. Add alert.
2. Under Condition, choose:
• Order Block Zones (Clean Core Version) → Any alert() function call
3. Then every time a retest happens, the script’s internal alert() calls will send the message:
• "Bullish OB re-test on $ ([tf])"
• "Bearish OB re-test on ([tf])"

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.