PROTECTED SOURCE SCRIPT
Updated

ICT订单块交易【实时不滞后】

32
Used to identify "Order Blocks" (OB), based on Break of Structure (BOS) and Retest mechanisms. It detects candles in the opposite direction after swing highs/lows to form potential supply/demand zones, confirming and plotting valid OBs only upon price retest. The indicator emphasizes "real" OBs: requiring a strong impulse (> ATR * multiplier) and retest verification.

- **Core Functions**: Detect BOS (Break of Structure); find opposite candles after prior impulses; verify strength and retest; draw OB boxes and labels.
- **Applicable Scenarios**: Suitable for ICT strategies, supply-demand trading, or reversal identification. Helps filter false breakouts and shows only high-probability zones.
- **Display Mode**: Overlaid on the main chart, displaying OBs as boxes, supporting up to 500 boxes.
- **Limitations**: Retest period fixed at 15 bars; based on simple candlesticks (no volume filter); no automatic cleanup of old OBs (manual management required).

The indicator has no built-in alerts but can be extended. ATR is used dynamically to validate strength.

## Input Parameters

Input parameters are concise, divided into core settings and display group. Below explains each parameter’s default value, type, and function.

### Core Settings
- **Structure Lookback** (int, default: 10, min: 3): Lookback period for structure detection (length for ta.highest/lowest). Higher values detect stronger structures.
- **Minimum Impulse Strength (ATR ×)** (float, default: 1.5, min: 0.5): Minimum impulse strength ((high-low) > ATR * this value). Ensures significant movement before OB.
- **Bars to watch for Retest** (int, default: 15, min: 1): Number of bars to monitor for retest. OB is confirmed only if price retests the OB zone within N bars after a breakout.

### Display Settings
- **Show Bullish OBs** (bool, default: true): Show bullish OBs (demand zone, rebounds after retest).
- **Show Bearish OBs** (bool, default: true): Show bearish OBs (supply zone, reverses after retest).

Colors are fixed: green (bullish, 80% transparency), red (bearish, 80% transparency).

## Calculations and Display

### Break of Structure (BOS) Detection
- **ATR Calculation**: ta.atr(14) used for strength verification.
- **Swing High/Low**: ta.highest(high, lookback) / ta.lowest(low, lookback) to identify structure. ...

## Calculation and Display

### Structure Breakout (BOS) Detection
- **ATR Calculation**: `ta.atr(14)` used for strength verification.
- **Swing High/Low**: `ta.highest(high, lookback)` / `ta.lowest(low, lookback)` identify structure.
- **BOS Trigger**:
- **bullBOS**: close > hh[1] (breaks previous high).
- **bearBOS**: close < ll[1] (breaks previous low).

### Order Block Identification
- **getLastOppositeCandle(isBullish)**:
- Search for the most recent "opposite" candle within the lookback period (bullBOS: bearish candle close < open; bearBOS: bullish candle close > open).
- Returns the index (idx); if none, then na.
- **OB Logic** (only when showBullish/Bearish=true):
- **Bullish OB (bullBOS)**:
- Find previous bearish candle (idx), check momentum: (high-low) > ATR * atrMult.
- Calculate obLow = low[idx], obHigh = high[idx].
- Backtest check: within 15 candles low[j] inside [obLow, obHigh] → inRetest = true.
- If confirmed: draw green box (from bar_index - idx to current, obLow to obHigh); label "🟩 Bullish OB (Valid)" (top-left, green, 80% transparency, white text).
- Push into bullOBs array.
- **Bearish OB (bearBOS)**: symmetric, red box, label "🟥 Bearish OB (Valid)" (bottom-left).
- **Array Management**: var box[] bullOBs/bearOBs store all OBs; no automatic cleanup (expandable).

### Display Elements
- **Boxes**: dynamically from idx to current candle, visually showing OB area.
- **Labels**: displayed when confirmed, positioned based on obHigh/obLow.
- No lines/fills; pure boxes + labels.

## Alert Functionality
The indicator has no built-in alerts but can be extended via TradingView alerts, for example:
- **New OB**: bullBOS and inRetest or bearBOS and inRetest.
- **Backtest**: price enters OB range.

It is recommended to add `alertcondition()` for custom alerts. ...

It is recommended to add a custom alertcondition(), such as 'Bullish OB Confirmed'.

## Usage Tips
- **Optimization**: lookback=10 balances sensitivity; atrMult=1.5 filters weak impulses; retestBars=15 is suitable for intraday.
- **Customization**: turn off showBullish/Bearish to hide types; add volume filtering to the fork for better accuracy.
- **Explanation**:
- **BOS + Backtesting**: ensure OB is 'real' (not a false breakout); only draw after backtesting to avoid noise.
- **Strength**: (high-low)>ATR*1.5 indicates strong impulses, making OB more reliable.
- **Application**: Bullish OB = buy zone (support); Bearish OB = sell zone (resistance).
- **Limitations**: fixed backtesting period may miss late retracements; no volume/time filtering; few OBs in low-volatility markets.
- **Extensions**: add OB counts or Fibonacci extensions.

ICT订单块交易指标,用于识别“订单块”(Order Blocks, OB),基于结构突破(Break of Structure, BOS)与回测(Retest)机制。它通过检测摆动高/低点后的相反方向烛台,形成潜在供给/需求区域,仅在价格回测时确认并绘制有效OB。指标强调“真实”OB:需强冲动(> ATR * 乘数)与回测验证。

- **核心功能**:检测BOS(结构突破);查找前冲动相反烛台;验证强度与回测;绘制OB盒子与标签。
- **适用场景**:适合ICT策略、供给需求交易或反转识别。帮助过滤假突破,仅显示高概率区域。
- **显示模式**:叠加在主图上,使用盒子(boxes)显示OB,支持最大500个盒子。
- **限制**:回测期固定15柱;基于简单烛台(无成交量过滤);无自动清理旧OB(手动管理)。

指标无内置警报,但可扩展。数据使用ATR动态验证强度。

## 输入参数

输入参数简洁,分为核心设置与显示组。以下说明每个参数的默认值、类型和作用。

### 核心设置
- **Structure Lookback** (int, 默认: 10, 最小: 3):结构检测回溯期(ta.highest/lowest的长度)。较高值检测更强结构。
- **Minimum Impulse Strength (ATR ×)** (float, 默认: 1.5, 最小: 0.5):最小冲动强度((high-low) > ATR * 此值)。确保OB前有显著移动。
- **Bars to watch for Retest** (int, 默认: 15, 最小: 1):回测监控柱数。突破后N柱内价格回测OB区域才确认。

### 显示设置
- **Show Bullish OBs** (bool, 默认: true):显示看涨OB(需求区,回测后反弹)。
- **Show Bearish OBs** (bool, 默认: true):显示看跌OB(供给区,回测后反转)。

颜色固定:绿(看涨,80%透明)、红(看跌,80%透明)。

## 计算与显示

### 结构突破(BOS)检测
- **ATR计算**:ta.atr(14) 用于强度验证。
- **摆动高/低**:ta.highest(high, lookback) / ta.lowest(low, lookback) 识别结构。
- **BOS触发**:
- **bullBOS**:close > hh[1](上破前高)。
- **bearBOS**:close < ll[1](下破前低)。

### 订单块识别
- **getLastOppositeCandle(isBullish)**:
- 查找最近lookback柱内“相反”烛台(bullBOS: 熊烛 close < open;bearBOS: 牛烛 close > open)。
- 返回索引(idx);若无则na。
- **OB逻辑**(仅当showBullish/Bearish=true):
- **看涨OB (bullBOS)**:
- 查找前熊烛(idx),检查冲动:(high-low) > ATR * atrMult。
- 计算obLow=low[idx],obHigh=high[idx]。
- 回测检查:15柱内low[j] 在 [obLow, obHigh] 内 → inRetest=true。
- 若确认:绘制绿盒(bar_index-idx 到当前,obLow到obHigh);标签“🟩 Bullish OB (Valid)”(左上,绿,80%透明,白文本)。
- 推入bullOBs数组。
- **看跌OB (bearBOS)**:对称,红盒,标签“🟥 Bearish OB (Valid)”(左下)。
- **数组管理**:var box[] bullOBs/bearOBs 存储所有OB;无自动清理(可扩展)。

### 显示元素
- **盒子**:动态从idx到当前柱,延伸显示OB区域。
- **标签**:确认时显示,位置基于obHigh/obLow。
- 无线条/填充;纯盒子+标签。

## 警报功能
指标无内置警报,但可通过TradingView警报扩展,例如:
- **新OB**:bullBOS and inRetest 或 bearBOS and inRetest。
- **回测**:价格进入OB范围。

建议添加alertcondition()自定义,如“Bullish OB Confirmed”。

## 使用提示
- **优化**:lookback=10平衡敏感;atrMult=1.5过滤弱冲动;retestBars=15适合日内。
- **自定义**:关闭showBullish/Bearish隐藏类型;fork添加成交量过滤提升准确。
- **解释**:
- **BOS+回测**:确保OB“真实”(非假突破);仅回测后绘制,避免噪音。
- **强度**:(high-low)>ATR*1.5表示强冲动,OB更可靠。
- **应用**:看涨OB=买入区(支撑);看跌OB=卖出区(阻力)。
- **局限**:回测期固定,可能错过晚回测;无成交量/时间过滤;低波动市场少OB。
- **扩展**:添加OB计数或斐波那契扩展。
Release Notes
The "Trend Duration Forecast" indicator is designed to estimate the potential duration of bullish or bearish trends. It detects directional changes using the Hull Moving Average (HMA), tracks the duration of each historical trend, and calculates the average, thereby statistically predicting how long the current trend may continue. This feature allows traders to clearly visualize real-time trend strength and potential trend exhaustion areas.

## Key Features
- **Dynamic Trend Detection**: Uses the Hull Moving Average to identify when prices transition into a new upward or downward trend.
- **Trend Duration Counting**: Counts the number of candlesticks in each completed bullish and bearish phase to understand trend persistence.
- **Forecast Projection**: Automatically projects an estimated trend continuation line based on the average length of recent trends.
- **Real-Time Updates**: Continuously updates the "actual length" label as trends develop.
- **Historical Data Table**: Displays past trend durations of bullish and bearish cycles and their averages.
- **Adaptive Sampling**: Uses a customizable sample size to smooth volatility in forecasts, providing statistically meaningful predictions.
- **Clear Color Differentiation**: Highlights upward trends in green and downward trends in orange for quick visual assessment.

## Usage
- Use the "Trend Detection Sensitivity" setting to control how quickly the indicator reacts to trend changes — lower values increase responsiveness, higher values better smooth out noise.
- Compare the "actual length" of the current trend with the predicted "possible length" to estimate if the trend is nearing exhaustion.
- Observe the historical duration table to understand the average trend duration under the current market structure.
- Use the color-coded HMA line and projection arrows to identify when momentum weakens and prepare for potential trend reversals.
- This indicator is particularly useful for swing trading or trend-following strategies, where the trend duration is critical for effectively managing entry and exit points.


“趋势持续时间预测”指标旨在估算看涨或看跌趋势的可能持续时间。该指标通过赫尔移动平均线(Hull Moving Average, HMA)检测方向变化,追踪每段历史趋势的持续时间并计算平均值,从而从统计学角度预测当前趋势可能延续的时长。这一功能使交易者能极其清晰地可视化实时趋势强度及潜在的趋势衰竭区域。

## 主要特点
- **动态趋势检测**:利用赫尔移动平均线识别价格何时过渡至新的上升趋势或下降趋势。
- **趋势持续时间计数**:统计每段已完成的看涨和看跌阶段的K线数量,以了解趋势的持续性。
- **预测投影**:根据近期趋势的平均长度,自动投射出估算的趋势延续线。
- **实时更新**:随着趋势发展,持续更新“实际长度”标签。
- **历史数据表**:显示看涨和看跌周期的过往趋势持续时间及其平均值。
- **自适应采样**:采用可自定义的样本量,平滑预测中的波动性,提供具有统计学意义的预测结果。
- **颜色区分清晰度**:用绿色突出显示上升趋势,用橙色突出显示下降趋势,便于即时视觉判断。

## 使用方法
- 通过“趋势检测灵敏度”设置,控制指标对趋势变化的反应速度——数值越低,响应速度越快;数值越高,越能平滑噪音干扰。
- 将当前趋势的“实际长度”与“可能长度”预测值进行对比,估算该趋势是否接近衰竭。
- 观察历史持续时间表,了解当前市场结构下趋势的平均持续时间。
- 利用颜色编码的赫尔移动平均线(HMA线)和投影箭头,识别动能强度何时减弱,并为可能的趋势反转做好准备。
- 该指标非常适合波段交易或趋势跟踪策略,在这类策略中,趋势的持续时间对有效管理进场和出场至关重要。

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.