OPEN-SOURCE SCRIPT
Anticipate future systems

Overall Logic of This Indicator
This is an automatic Order Block (OB) plotting indicator based on "structure break + extreme small-bodied candle". It identifies two types of zones: Demand Zone (Bull OB): Blue semi-transparent box (bullish entry zone)
Supply Zone (Bear OB): Red semi-transparent box (bearish entry zone)
Core Idea:
When price breaks the high/low of the candle 2 bars ago, the script scans backward to find the most extreme small-bodied candle (within a filtered range), uses that single candle’s high/low as the Order Block boundaries, draws a box extending infinitely to the right, and keeps it until price mitigates (breaks) it.Detailed Logic Breakdown (in code execution order)Input Settings show_ob: Show Order Blocks (on/off)
ob_showlast: Maximum number of latest unmitigated OBs to display (default 5)
ob_filter: Small-body filter “Atr” → uses ta.atr(200)
“Cumulative Mean Range” → uses cumulative average of (high - low)
Both are multiplied by 2 to define the “small body” threshold.
Trigger Conditions (Structure Break Detection) pinescript
if ta.crossover(close, high[2]) // Close breaks above the high of 2 bars ago
→ Create **Demand Zone (Bull OB)** → call `ob_coord(false, bar_index[2], ...)`
if ta.crossunder(close, low[2]) // Close breaks below the low of 2 bars ago
→ Create **Supply Zone (Bear OB)** → call `ob_coord(true, bar_index[2], ...)`
This actually detects a 3-candle structure break (current candle breaking the extreme of the candle 2 bars prior).
Order Block Coordinate Calculation (Core of ob_coord function)
Example for Demand Zone (use_max = false): Scans backward from the trigger bar (bar_index[2])
Only considers small-bodied candles: (high - low) < threshold * 2
Among those, finds the lowest low → records it as min
Takes the high of that exact same candle as max
Final Order Block = that single candle’s [high, low], timestamp = time of that candle
For Supply Zone (use_max = true): opposite logic — finds the highest high among small-bodied candles and uses that candle’s low as the lower boundary.→ Result: Every Order Block is always a single small-bodied candle (never a merged zone), but it is the most extreme one within the scanned range.
Order Block Lifecycle Management After creation, stores data in 4 arrays: ob_top, ob_btm, ob_left, ob_type (1 = Demand, -1 = Supply)
Real-time mitigation check (every bar): Demand zone (type == 1): if close < ob_btm → immediately delete
Supply zone (type == -1): if close > ob_top → immediately delete
Only unmitigated blocks remain.
Drawing Logic (executed only on the last bar) Uses pre-created box objects (up to ob_showlast boxes)
For the latest N unmitigated blocks: Left side = time of the extreme candle
Top/Bottom = high/low of that candle
Extends infinitely right (extend.right)
Colors: blue for demand, red for supply.
One-Sentence Summary“When price breaks the extreme of the candle 2 bars ago → scan backward for candles smaller than 2× threshold → pick the most extreme single candle as the Order Block → draw box extending right → delete as soon as price closes through it.”This is a classic Institutional Order Block approach: it treats the “last small-bodied candle before a strong move” as the smart-money entry zone, triggers on structure breaks, automatically removes invalidated zones, and keeps only the most recent 5 valid ones. Clean, efficient, and highly practical for trading.
该指标的总体逻辑
这是一个基于“结构突破+极小实体K线”的自动订单块(OB)绘图指标。它识别两种类型的区域:需求区(看涨 OB):蓝色半透明框(看涨入场区)
供给区(看跌 OB):红色半透明框(看跌入场区)
核心思想:
当价格突破两根K线前的最高价/最低价时,脚本会向前扫描,找到最极端的小型K线(在过滤范围内),使用该K线的最高价/最低价作为订单块边界,绘制一个向右无限延伸的框,并保持该框,直到价格突破(缓解)该框。详细逻辑分解(按代码执行顺序)输入设置 show_ob:显示订单块(开/关)
ob_showlast:要显示的最新未缓解订单块的最大数量(默认为5)
ob_filter:小型K线过滤器 “Atr” → 使用 ta.atr(200)
“累计均值范围” → 使用(最高价 - 最低价)的累计平均值
两者均乘以2定义“小实体”阈值。
触发条件(结构突破检测)pinescript
如果 ta.crossover(close, high[2]) // 收盘价突破前两根K线的最高价
→ 创建**需求区(牛市突破)** → 调用 `ob_coord(false, bar_index[2], ...)`
如果 ta.crossunder(close, low[2]) // 收盘价跌破前两根K线的最低价
→ 创建**供给区(熊市突破)** → 调用 `ob_coord(true, bar_index[2], ...)`
这实际上检测的是三根K线的结构突破(当前K线突破前两根K线的最高价)。
订单块坐标计算(ob_coord 函数的核心)
需求区示例(use_max = false):从触发柱(bar_index[2])向后扫描
仅考虑小实体K线:(high - low) < threshold * 2
在这些小实体K线中,找到最低价 → 将其记录为 min
将该K线的最高价作为 max
最终订单块 = 该K线的 [high, low],时间戳 = 该K线的时间
供给区示例(use_max = true):逻辑相反——找到小实体K线中的最高价,并使用该K线的最低价作为下限。→ 结果:每个订单块始终由一根小实体K线组成(绝非合并区域),但它是扫描范围内最极端的K线。
订单块生命周期管理:创建后,数据存储在 4 个数组中:ob_top、ob_btm、ob_left 和 ob_type(1 = 需求,-1 = 供给)。
实时缓解检查(每根K线):需求区(type == 1):如果收盘价 < ob_btm → 立即删除。
供给区(type == -1):如果收盘价 > ob_top → 立即删除。
仅保留未缓解的订单块。
绘制逻辑(仅在最后一根K线执行):使用预先创建的方框对象(最多 ob_showlast 个方框)。
对于最近的 N 个未缓解的订单块:左侧 = 极端K线的时间。
顶部/底部 = 该K线的最高价/最低价。
向右无限延伸(extend.right)。
颜色:蓝色代表需求,红色代表供给。
一句话总结:“当价格突破两根K线前的极值时 → 向前扫描小于两倍阈值的K线 → 选择最极端的单根K线作为订单块 → 向右绘制延伸的框 → 一旦价格收盘穿过该框,立即删除。”这是一种经典的机构订单块策略:它将“强势行情前的最后一根小实体K线”视为精明资金的入场区域,在结构突破时触发,自动移除无效区域,并仅保留最近的5个有效区域。简洁、高效且极具交易实用性。
This is an automatic Order Block (OB) plotting indicator based on "structure break + extreme small-bodied candle". It identifies two types of zones: Demand Zone (Bull OB): Blue semi-transparent box (bullish entry zone)
Supply Zone (Bear OB): Red semi-transparent box (bearish entry zone)
Core Idea:
When price breaks the high/low of the candle 2 bars ago, the script scans backward to find the most extreme small-bodied candle (within a filtered range), uses that single candle’s high/low as the Order Block boundaries, draws a box extending infinitely to the right, and keeps it until price mitigates (breaks) it.Detailed Logic Breakdown (in code execution order)Input Settings show_ob: Show Order Blocks (on/off)
ob_showlast: Maximum number of latest unmitigated OBs to display (default 5)
ob_filter: Small-body filter “Atr” → uses ta.atr(200)
“Cumulative Mean Range” → uses cumulative average of (high - low)
Both are multiplied by 2 to define the “small body” threshold.
Trigger Conditions (Structure Break Detection) pinescript
if ta.crossover(close, high[2]) // Close breaks above the high of 2 bars ago
→ Create **Demand Zone (Bull OB)** → call `ob_coord(false, bar_index[2], ...)`
if ta.crossunder(close, low[2]) // Close breaks below the low of 2 bars ago
→ Create **Supply Zone (Bear OB)** → call `ob_coord(true, bar_index[2], ...)`
This actually detects a 3-candle structure break (current candle breaking the extreme of the candle 2 bars prior).
Order Block Coordinate Calculation (Core of ob_coord function)
Example for Demand Zone (use_max = false): Scans backward from the trigger bar (bar_index[2])
Only considers small-bodied candles: (high - low) < threshold * 2
Among those, finds the lowest low → records it as min
Takes the high of that exact same candle as max
Final Order Block = that single candle’s [high, low], timestamp = time of that candle
For Supply Zone (use_max = true): opposite logic — finds the highest high among small-bodied candles and uses that candle’s low as the lower boundary.→ Result: Every Order Block is always a single small-bodied candle (never a merged zone), but it is the most extreme one within the scanned range.
Order Block Lifecycle Management After creation, stores data in 4 arrays: ob_top, ob_btm, ob_left, ob_type (1 = Demand, -1 = Supply)
Real-time mitigation check (every bar): Demand zone (type == 1): if close < ob_btm → immediately delete
Supply zone (type == -1): if close > ob_top → immediately delete
Only unmitigated blocks remain.
Drawing Logic (executed only on the last bar) Uses pre-created box objects (up to ob_showlast boxes)
For the latest N unmitigated blocks: Left side = time of the extreme candle
Top/Bottom = high/low of that candle
Extends infinitely right (extend.right)
Colors: blue for demand, red for supply.
One-Sentence Summary“When price breaks the extreme of the candle 2 bars ago → scan backward for candles smaller than 2× threshold → pick the most extreme single candle as the Order Block → draw box extending right → delete as soon as price closes through it.”This is a classic Institutional Order Block approach: it treats the “last small-bodied candle before a strong move” as the smart-money entry zone, triggers on structure breaks, automatically removes invalidated zones, and keeps only the most recent 5 valid ones. Clean, efficient, and highly practical for trading.
该指标的总体逻辑
这是一个基于“结构突破+极小实体K线”的自动订单块(OB)绘图指标。它识别两种类型的区域:需求区(看涨 OB):蓝色半透明框(看涨入场区)
供给区(看跌 OB):红色半透明框(看跌入场区)
核心思想:
当价格突破两根K线前的最高价/最低价时,脚本会向前扫描,找到最极端的小型K线(在过滤范围内),使用该K线的最高价/最低价作为订单块边界,绘制一个向右无限延伸的框,并保持该框,直到价格突破(缓解)该框。详细逻辑分解(按代码执行顺序)输入设置 show_ob:显示订单块(开/关)
ob_showlast:要显示的最新未缓解订单块的最大数量(默认为5)
ob_filter:小型K线过滤器 “Atr” → 使用 ta.atr(200)
“累计均值范围” → 使用(最高价 - 最低价)的累计平均值
两者均乘以2定义“小实体”阈值。
触发条件(结构突破检测)pinescript
如果 ta.crossover(close, high[2]) // 收盘价突破前两根K线的最高价
→ 创建**需求区(牛市突破)** → 调用 `ob_coord(false, bar_index[2], ...)`
如果 ta.crossunder(close, low[2]) // 收盘价跌破前两根K线的最低价
→ 创建**供给区(熊市突破)** → 调用 `ob_coord(true, bar_index[2], ...)`
这实际上检测的是三根K线的结构突破(当前K线突破前两根K线的最高价)。
订单块坐标计算(ob_coord 函数的核心)
需求区示例(use_max = false):从触发柱(bar_index[2])向后扫描
仅考虑小实体K线:(high - low) < threshold * 2
在这些小实体K线中,找到最低价 → 将其记录为 min
将该K线的最高价作为 max
最终订单块 = 该K线的 [high, low],时间戳 = 该K线的时间
供给区示例(use_max = true):逻辑相反——找到小实体K线中的最高价,并使用该K线的最低价作为下限。→ 结果:每个订单块始终由一根小实体K线组成(绝非合并区域),但它是扫描范围内最极端的K线。
订单块生命周期管理:创建后,数据存储在 4 个数组中:ob_top、ob_btm、ob_left 和 ob_type(1 = 需求,-1 = 供给)。
实时缓解检查(每根K线):需求区(type == 1):如果收盘价 < ob_btm → 立即删除。
供给区(type == -1):如果收盘价 > ob_top → 立即删除。
仅保留未缓解的订单块。
绘制逻辑(仅在最后一根K线执行):使用预先创建的方框对象(最多 ob_showlast 个方框)。
对于最近的 N 个未缓解的订单块:左侧 = 极端K线的时间。
顶部/底部 = 该K线的最高价/最低价。
向右无限延伸(extend.right)。
颜色:蓝色代表需求,红色代表供给。
一句话总结:“当价格突破两根K线前的极值时 → 向前扫描小于两倍阈值的K线 → 选择最极端的单根K线作为订单块 → 向右绘制延伸的框 → 一旦价格收盘穿过该框,立即删除。”这是一种经典的机构订单块策略:它将“强势行情前的最后一根小实体K线”视为精明资金的入场区域,在结构突破时触发,自动移除无效区域,并仅保留最近的5个有效区域。简洁、高效且极具交易实用性。
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
📈 专注市场动态与技术分析
📲 自建神经网络量化系统
🌏 AASFANS (抖音微信同号,添加备注来意,拒闲聊)
X:@AASFANS
📲 自建神经网络量化系统
🌏 AASFANS (抖音微信同号,添加备注来意,拒闲聊)
X:@AASFANS
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
📈 专注市场动态与技术分析
📲 自建神经网络量化系统
🌏 AASFANS (抖音微信同号,添加备注来意,拒闲聊)
X:@AASFANS
📲 自建神经网络量化系统
🌏 AASFANS (抖音微信同号,添加备注来意,拒闲聊)
X:@AASFANS
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.