OPEN-SOURCE SCRIPT
Order Block Strategy

Order Block Strategy
🎯 Overview
This strategy automates the detection of Order Blocks (Institutional Supply & Demand Zones) using swing pivot highs and lows. It provides clear visual zone plotting and executes trades when price mitigates these zones, protecting your capital via adaptive risk management tools.Unlike static strategies, this system includes dual risk management logic (ATR-based and Percentage-based), allowing you to trade safely across highly volatile crypto assets, forex pairs, or traditional equities.
🛠️ Key Features
🚦 How the Logic Works
1. Zone Identification (Order Blocks)
The script constantly monitors swing high and low points over a customizable lookback period.
2. Trade Entry Conditions
3. Execution & Risk Engine
Upon entry validation, the strategy maps out an exact risk envelope:
⚙️ Configuration & Inputs Explained
⚠️ Disclaimer
Past performance does not guarantee future results. This script is designed as an automated trading framework and should be thoroughly backtested on your preferred assets and timeframes before deployment with live capital.
🎯 Overview
This strategy automates the detection of Order Blocks (Institutional Supply & Demand Zones) using swing pivot highs and lows. It provides clear visual zone plotting and executes trades when price mitigates these zones, protecting your capital via adaptive risk management tools.Unlike static strategies, this system includes dual risk management logic (ATR-based and Percentage-based), allowing you to trade safely across highly volatile crypto assets, forex pairs, or traditional equities.
🛠️ Key Features
- Automated Order Block Detection: Uses lookback swing pivots to isolate institutional footprint zones.
- Real-time On-Chart Boxes: Dynamically draws and fills bullish (green) and bearish (red) order blocks.
- Dual-Mode Stop Loss Engine: Toggle instantly between structural volatility tracking (ATR) or portfolio-based tracking (Percentage).
- Automated Trade Execution: Auto-calculates mathematically precise entries, stop losses, and take profit targets with fixed Risk-to-Reward (R:R) ratios.
- HUD Performance Dashboard: An integrated on-screen data table displaying your current active configuration for effortless tracking.
🚦 How the Logic Works
1. Zone Identification (Order Blocks)
The script constantly monitors swing high and low points over a customizable lookback period.
- Bullish OB: Plotted when a key swing low forms, identifying the last down-close candle high/low range before an upward impulse.
- Bearish OB: Plotted when a key swing high forms, identifying the last up-close candle high/low range before a downward impulse.
2. Trade Entry Conditions
- Long Entry: Triggered when the current price drops into a valid Bullish Order Block zone, closes above its floor, and confirms momentum with a bullish close (close > open).
- Short Entry: Triggered when the current price rallies into a valid Bearish Order Block zone, closes below its ceiling, and confirms momentum with a bearish close (close < open).
3. Execution & Risk Engine
Upon entry validation, the strategy maps out an exact risk envelope:
- ATR Mode: Multiplies the Average True Range (ta.atr) by your multiplier to clear market noise.
- Percentage Mode: Sets a strict fixed-percentage risk buffer below or above your execution price.
- Take Profit: Automatically set using your custom Risk-to-Reward (R:R) ratio multiplier.
⚙️ Configuration & Inputs Explained
- Lookback Period: Change this to adjust pivot detection sensitivity. Higher values locate macro structural blocks; lower values locate micro intra-day blocks.
- ATR Length / Multiplier: Controls volatility filtering. The default 7.5x multiplier acts as a swing-trading buffer to prevent false-breakout stops.
- Risk:Reward Ratio: Dictates target sizing. A value of 1.5 means your profit target is exactly 1.5x larger than your capital risk.
- Stop Loss Mode: Dropdown to select your preferred risk methodology (ATR vs Percentage).
⚠️ Disclaimer
Past performance does not guarantee future results. This script is designed as an automated trading framework and should be thoroughly backtested on your preferred assets and timeframes before deployment with live capital.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.