PROTECTED SOURCE SCRIPT
Aktualisiert OB with Signals

Overview
The "OB with Signals" indicator is a Pine Script (version 6) tool designed for TradingView to identify Order Blocks (OBs) and generate Buy/Sell signals based on price interactions with OBs. It provides customizable visualization options and robust logic for OB detection, signal generation, and invalidation.
Features
Order Block Detection:
Identifies Bullish Order Blocks (OBs) based on the breakout of the high of the most recent bearish candle within a user-defined lookback period (default: 20 bars).
Identifies Bearish OBs based on the breakout of the low of the most recent bullish candle within the same lookback period.
Prevents overlapping OBs of the same type and filters out fully contained OBs.
Signal Generation:
Generates Buy signals when price interacts with the upper or lower half of a Bullish OB, or recovers from a false breakout above the OB.
Generates Sell signals when price interacts with the upper or lower half of a Bearish OB, or recovers from a false breakout below the OB.
Limits the number of displayed signals (default: 3) to reduce chart clutter.
Allows a minimum bar delay after OB creation before generating signals (default: 0).
Stop Loss (SL) Display:
Optionally displays Stop Loss price on OBs (default: disabled), showing the low for Bullish OBs and the high for Bearish OBs.
Visualization Options:
Toggle display of Bullish OBs, Bearish OBs, and signals (all default: enabled).
Customizable colors for Bullish OBs (default: blue, 90% transparency), Bearish OBs (default: red, 90% transparency), and OB midlines (default: white, 70% transparency).
Customizable signal label colors: current signal uses a prominent text color (default: white), historical signals use a non-prominent text color (default: red).
Adjustable background transparency for current signals (default: 30) to highlight new signals.
Invalidation and Reversal:
Invalidates OBs when price breaks through the opposite boundary (wick-based or close-based, default: wick-based).
Optionally reverses OB type on engulfing candles (default: disabled).
Performance Optimization:
Uses arrays to manage OBs and signals efficiently, removing invalidated OBs and signals to maintain chart clarity.
Notes
The indicator is designed for flexibility, with user-configurable parameters for lookback period, signal limits, and display options.
Stop Loss display is exclusive to OBs, with signal labels showing only "Buy" or "Sell" for simplicity.
Compatible with any market and timeframe on TradingView.
中文
概述
「OB with Signals」是一款基於 Pine Script(版本 6)為 TradingView 設計的指標,用於識別訂單塊(OB)並根據價格與 OB 的互動生成買賣訊號。它提供可自訂的視覺化選項以及穩健的 OB 偵測、訊號生成和失效邏輯。
功能
訂單塊偵測:
基於最近一根熊燭(紅 K)高點的突破,在使用者定義的回溯範圍(預設:20 根 K 棒)內識別看漲訂單塊(OB)。
基於最近一根牛燭(綠 K)低點的突破,在相同回溯範圍內識別看跌 OB。
防止同類型 OB 重疊,並過濾完全包含的 OB。
訊號生成:
當價格與看漲 OB 的上半部或下半部互動,或從 OB 上方的假突破回落時,生成買訊號。
當價格與看跌 OB 的上半部或下半部互動,或從 OB 下方的假突破反彈時,生成賣訊號。
限制顯示的訊號數量(預設:3 個)以減少圖表雜亂。
允許在 OB 生成後設定最小 K 棒延遲(預設:0)後才生成訊號。
止損價(SL)顯示:
可選在 OB 上顯示止損價(預設:關閉),看漲 OB 顯示低點,看跌 OB 顯示高點。
視覺化選項:
可切換顯示看漲 OB、看跌 OB 和訊號(預設:全部啟用)。
可自訂看漲 OB(預設:藍色,90% 透明)、看跌 OB(預設:紅色,90% 透明)和 OB 中線(預設:白色,70% 透明)的顏色。
可自訂訊號標籤顏色:當前訊號使用醒目文字顏色(預設:白色),歷史訊號使用非醒目文字顏色(預設:紅色)。
可調整當前訊號的背景透明度(預設:30)以突出新訊號。
失效與反轉:
當價格突破 OB 的相反邊界(基於影線或收盤價,預設:影線)時,OB 失效。
可選在吞噬 K 棒時反轉 OB 類型(預設:關閉)。
性能優化:
使用陣列高效管理 OB 和訊號,移除失效的 OB 和訊號以保持圖表清晰。
注意事項
指標設計靈活,提供可自訂的參數,包括回溯範圍、訊號數量限制和顯示選項。
止損價顯示僅限於 OB,訊號標籤僅顯示「Buy」或「Sell」以簡化呈現。
適用於 TradingView 上的任何市場和時間框架。
The "OB with Signals" indicator is a Pine Script (version 6) tool designed for TradingView to identify Order Blocks (OBs) and generate Buy/Sell signals based on price interactions with OBs. It provides customizable visualization options and robust logic for OB detection, signal generation, and invalidation.
Features
Order Block Detection:
Identifies Bullish Order Blocks (OBs) based on the breakout of the high of the most recent bearish candle within a user-defined lookback period (default: 20 bars).
Identifies Bearish OBs based on the breakout of the low of the most recent bullish candle within the same lookback period.
Prevents overlapping OBs of the same type and filters out fully contained OBs.
Signal Generation:
Generates Buy signals when price interacts with the upper or lower half of a Bullish OB, or recovers from a false breakout above the OB.
Generates Sell signals when price interacts with the upper or lower half of a Bearish OB, or recovers from a false breakout below the OB.
Limits the number of displayed signals (default: 3) to reduce chart clutter.
Allows a minimum bar delay after OB creation before generating signals (default: 0).
Stop Loss (SL) Display:
Optionally displays Stop Loss price on OBs (default: disabled), showing the low for Bullish OBs and the high for Bearish OBs.
Visualization Options:
Toggle display of Bullish OBs, Bearish OBs, and signals (all default: enabled).
Customizable colors for Bullish OBs (default: blue, 90% transparency), Bearish OBs (default: red, 90% transparency), and OB midlines (default: white, 70% transparency).
Customizable signal label colors: current signal uses a prominent text color (default: white), historical signals use a non-prominent text color (default: red).
Adjustable background transparency for current signals (default: 30) to highlight new signals.
Invalidation and Reversal:
Invalidates OBs when price breaks through the opposite boundary (wick-based or close-based, default: wick-based).
Optionally reverses OB type on engulfing candles (default: disabled).
Performance Optimization:
Uses arrays to manage OBs and signals efficiently, removing invalidated OBs and signals to maintain chart clarity.
Notes
The indicator is designed for flexibility, with user-configurable parameters for lookback period, signal limits, and display options.
Stop Loss display is exclusive to OBs, with signal labels showing only "Buy" or "Sell" for simplicity.
Compatible with any market and timeframe on TradingView.
中文
概述
「OB with Signals」是一款基於 Pine Script(版本 6)為 TradingView 設計的指標,用於識別訂單塊(OB)並根據價格與 OB 的互動生成買賣訊號。它提供可自訂的視覺化選項以及穩健的 OB 偵測、訊號生成和失效邏輯。
功能
訂單塊偵測:
基於最近一根熊燭(紅 K)高點的突破,在使用者定義的回溯範圍(預設:20 根 K 棒)內識別看漲訂單塊(OB)。
基於最近一根牛燭(綠 K)低點的突破,在相同回溯範圍內識別看跌 OB。
防止同類型 OB 重疊,並過濾完全包含的 OB。
訊號生成:
當價格與看漲 OB 的上半部或下半部互動,或從 OB 上方的假突破回落時,生成買訊號。
當價格與看跌 OB 的上半部或下半部互動,或從 OB 下方的假突破反彈時,生成賣訊號。
限制顯示的訊號數量(預設:3 個)以減少圖表雜亂。
允許在 OB 生成後設定最小 K 棒延遲(預設:0)後才生成訊號。
止損價(SL)顯示:
可選在 OB 上顯示止損價(預設:關閉),看漲 OB 顯示低點,看跌 OB 顯示高點。
視覺化選項:
可切換顯示看漲 OB、看跌 OB 和訊號(預設:全部啟用)。
可自訂看漲 OB(預設:藍色,90% 透明)、看跌 OB(預設:紅色,90% 透明)和 OB 中線(預設:白色,70% 透明)的顏色。
可自訂訊號標籤顏色:當前訊號使用醒目文字顏色(預設:白色),歷史訊號使用非醒目文字顏色(預設:紅色)。
可調整當前訊號的背景透明度(預設:30)以突出新訊號。
失效與反轉:
當價格突破 OB 的相反邊界(基於影線或收盤價,預設:影線)時,OB 失效。
可選在吞噬 K 棒時反轉 OB 類型(預設:關閉)。
性能優化:
使用陣列高效管理 OB 和訊號,移除失效的 OB 和訊號以保持圖表清晰。
注意事項
指標設計靈活,提供可自訂的參數,包括回溯範圍、訊號數量限制和顯示選項。
止損價顯示僅限於 OB,訊號標籤僅顯示「Buy」或「Sell」以簡化呈現。
適用於 TradingView 上的任何市場和時間框架。
Versionshinweise
Changes:Fixed drawing error caused by excessive bar count in OB range by using time-based positioning instead of bar index.
Updated OB structure to store start and creation times as timestamps instead of bar indices.
Modified box and line drawing to use timestamps for positioning.
Adjusted label positioning to use time-based coordinates where needed.
Updated signal reference checks to use start timestamp.
Revised OB extension logic to use current timestamp.
Updated bar counting logic for minimum bars after OB to use timestamp-based calculation.
變更內容:
修復因 OB 區間 K 棒數量過多導致的繪圖錯誤,改用基於時間的定位方式取代 K 棒索引。
更新 OB 結構,將起始和創建時間儲存為時間戳而非 K 棒索引。
修改方框和線條繪製,使用時間戳進行定位。
調整標籤定位,在需要處使用基於時間的座標。
更新訊號參考檢查,使用起始時間戳。
修改 OB 延伸邏輯,使用當前時間戳。
更新 OB 生成後最小 K 棒數的計數邏輯,使用基於時間戳的計算。
Versionshinweise
Changes:Fixed the functionality for setting the minimum number of bars to wait after OB creation before evaluating entry signals.
Improved reliability of bar counting for the minimum bars delay feature.
Enhanced OB structure to support accurate tracking of creation time.
Optimized signal generation to ensure correct delay after OB formation.
Maintained consistent time-based positioning for drawing elements.
Updated extension logic for order blocks to align with current time.
Strengthened signal reference checks for robust performance.
變更內容:
修復 OB 生成後需經過指定 K 棒數才開始判斷進場訊號的功能。
提升最小 K 棒延遲功能的計數可靠性。
增強 OB 結構以支援精確的創建時間追蹤。
優化訊號生成邏輯,確保 OB 生成後正確延遲。
保持繪圖元素的基於時間定位一致性。
更新訂單塊延伸邏輯,與當前時間對齊。
強化訊號參考檢查,提升穩健性。
Versionshinweise
Key Focus: This version optimizes signal display logic for enhanced visual clarity and user experience. Core OB detection and invalidation mechanisms remain unchanged, with improvements focused on real-time and historical signal presentation.Key Improvements
Real-time Signal Enhancement: When a signal triggers on the current bar, the SL label changes color (blue for bullish, red for bearish, fully opaque) and appends a directional arrow (▲ for buy / ▼ for sell) after the stop-loss price for intuitive real-time alerts.
Historical Signal Optimization: Historical signals are now displayed as compact triangle shapes (blue upward for buy / red downward for sell), shown only after bar close, precisely aligned to the bar's low/high, with a customizable offset factor (default 10% of bar range) to prevent overlap.
SL Label Improvements: SL labels are offset one bar to the right to avoid obscuring the current bar; opacity is set to 0 (fully opaque) during color changes, with automatic reset of text and color each bar for a clean chart.
Interface Simplification: Removed highlighted/non-highlighted font color settings; all text is now uniformly white for consistency and reduced parameter complexity.
Usage Tips
Test the offset factor (0.05-0.2) across different timeframes (1H, 4H, Daily) to suit market volatility.
Enable showSLOnOB to fully leverage the real-time arrow feature.
更新重點:本版本針對訊號顯示邏輯進行全面優化,提升視覺清晰度和使用者體驗。核心 OB 偵測與失效機制保持不變,僅強化即時與歷史訊號的呈現方式。
主要改進
即時訊號強化:當前 K 棒觸發訊號時,SL 標籤變色(看漲藍色、看跌紅色,不透明)並在止損價格後附加方向箭頭(▲ 買入 / ▼ 賣出),提供直觀即時提示。
歷史訊號優化:歷史 K 棒訊號改為小型三角形圖案(藍色向上買入 / 紅色向下賣出),僅在 K 棒收盤後顯示,位置精確對齊 K 棒低點/高點,並新增可設定偏移比例(預設 10% K 棒範圍),避免重疊。
SL 標籤改進:SL 標籤位置向右偏移一個 K 棒,避免遮擋當前 K 棒;變色時透明度設為 0(完全不透明),每 K 棒重置文字與顏色,確保圖表乾淨。
介面簡化:移除醒目/非醒目字體顏色設定,所有文字統一為白色,提升一致性並減少參數複雜度。
使用建議
建議在不同時間框架(1H、4H、日線)測試偏移比例(0.05-0.2),以適應市場波動。
啟用 showSLOnOB 以充分利用即時箭頭功能。
Versionshinweise
Key Focus: This version focuses on optimizing SL label display content for improved visual prominence in real-time signals. Core logic remains consistent with the previous version, with enhancements to SL label opacity and rendering.Key Improvements
SL Label Opacity Optimization: When a signal triggers on the current bar, SL label background opacity is set to the minimum (0, fully opaque) for a more prominent blue (bullish) / red (bearish) background, ensuring clear visibility of arrow text (▲/▼). Default SL labels have opacity reduced to 20% for better overall readability.
Display Consistency Enhancement: Each bar resets SL label text and color automatically, preventing residual effects and keeping the chart clean and smooth.
更新重點:本版本專注優化 SL 標籤的顯示內容,提升即時訊號的視覺醒目度。核心邏輯與先前版本保持一致,僅強化 SL 標籤的透明度與渲染效果。
主要改進
SL 標籤透明度優化:當前 K 棒觸發訊號時,SL 標籤背景透明度調至最低(0,完全不透明),確保藍色(看漲)/紅色(看跌)背景更突出,箭頭文字(▲/▼)清晰可見。預設 SL 標籤透明度調低至 20%,提升整體可讀性。
顯示一致性強化:每 K 棒重置時,SL 標籤文字與顏色自動恢復原樣,避免殘留效果,圖表更乾淨流暢。
使用建議
建議啟用 showSLOnOB 以充分利用即時 SL 變色與箭頭功能。
在高波動市場(如 BTC/USDT)測試,確認透明度調整後的視覺效果。
Versionshinweise
Key Fixes and Enhancements:Fixed SL Tag Display Issue: Resolved the problem where the SL (Stop Loss) tag was being incorrectly covered or obscured on the chart.
Optimized Label Layering Priority: Specifically ensured that the OB tag (Order Block or similar critical label) on the current candlestick is no longer overlapped by the SL tag. This guarantees you can clearly see the core markings for current market activity.
主要修正與優化:
修正了SL標籤的顯示問題: 解決了SL (Stop Loss) 標籤在圖表上被不當覆蓋或隱藏的問題。
優化標籤圖層優先級: 特別確保**當前K棒(Candlestick)**上的 **OB 標籤(Order Block 或類似重要標籤)**不再被 SL 標籤覆蓋,保證您能清楚看到當前市場活動的核心標註。
Geschütztes Skript
Dieses Script ist als Closed-Source veröffentlicht. Sie können es kostenlos und ohne Einschränkungen verwenden – erfahren Sie hier mehr.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Geschütztes Skript
Dieses Script ist als Closed-Source veröffentlicht. Sie können es kostenlos und ohne Einschränkungen verwenden – erfahren Sie hier mehr.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.