OPEN-SOURCE SCRIPT
已更新

Math by Thomas Order Blocks

2 779
🔥 Description:
🚀 Math by Thomas Order Blocks is a precision tool for Smart Money Concept (SMC) and price action traders, designed to automatically detect Bullish and Bearish Order Blocks (OBs). It highlights key institutional trading zones where large orders are placed, helping you identify potential reversal and continuation areas.

⚙️ Key Features:
✅ Automatic Order Block Detection:

Detects Bearish OBs when price sharply reverses after a significant bullish move.

Identifies Bullish OBs following a sharp reversal from a bearish push.

✅ Dynamic Sensitivity & Volume Filter:

Sensitivity Control: Customize OB detection precision.

Minimum Volume Filter: Ensures OBs form only on significant volume spikes.

✅ Flexible OB Mitigation:

Choose between "Close" or "Wick" mitigation for OB invalidation.

Mitigated OBs are automatically removed from the chart.

✅ Adaptive Swing & Price Change Detection:

Adjusts OB detection logic based on timeframe for flexibility.

Uses adaptive rate of change (ROC) calculations to spot momentum shifts.

✅ Visual Customization:

OBs are displayed as shaded boxes with configurable background and border colors.

Bullish OBs = Green (support zones).

Bearish OBs = Red (resistance zones).

✅ Alerts for OB Touch:

Get real-time alerts when price touches a Bullish or Bearish OB.

Helps you catch potential reversal points without constant chart monitoring.

📊 How It Works:
Bullish OB Logic:

Detected when price crosses over a positive momentum threshold (ROC) with high volume.

Plots a green OB box from the low of the swing candle.

Bearish OB Logic:

Identified when price crosses under a negative momentum threshold with high volume.

Plots a red OB box from the high of the swing candle.

Mitigation Rules:

OBs are removed once invalidated by price action based on your chosen mitigation type (Close or Wick).

📈 Usage Tips:
Use Bullish OBs as potential support areas for buy entries.

Treat Bearish OBs as resistance zones for sell setups.

Combine with Fair Value Gaps, volume profile, and RSI for confluence.

Adjust sensitivity and volume filters to fine-tune OB detection.

✅ Chart Example:
The script displays:

Bullish OBs in green, marking potential support zones.

Bearish OBs in red, indicating resistance zones.

Real-time alerts when price touches OBs.

🔥 Why Use This Indicator?
Designed for intraday and swing traders aiming to identify institutional trading zones.

Helps you spot reversal and continuation setups with precision.

Ideal for Smart Money Concept (SMC), price action, and order flow traders.
發行說明
Update Description

Math by Thomas OB Detection

  1. Order Blocks (OBs) are now primarily detected using a combination of price action (bullish or bearish candle structure) and volume spikes above a dynamic average threshold.
  2. Bullish OBs are identified on candles closing below open with high volume; bearish OBs on candles closing above open with high volume.
  3. Enhanced detection logic improves the relevance and strength of identified OB zones.
  4. Optional midpoint line inside each OB helps visualize precise zone levels.
  5. Visual customization options include colors, opacity, and extension length.
  6. Efficient OB management with automatic cleanup and max stored OB limits.


How to Use the OB Detection Script

1. OB Detection Logic
Bullish OB: Candle closes below open with volume higher than the average * multiplier (default 1.618).

Bearish OB: Candle closes above open with volume higher than the average * multiplier.

  1. OBs are drawn as boxes spanning the candle’s high and low.
  2. Optionally, a dashed midpoint line is drawn inside the OB for more precise zone visualization.


2. Choosing Between Full Candle or Midpoint Line
  1. The full candle OB covers the entire high-low range of the candle and highlights the full zone of interest.
  2. The midpoint line inside the OB provides a precise reference level within the OB.
  3. The midpoint line can be toggled on/off using the "Show OB Midpoint Line" input checkbox.


3. Visual Customization
  1. Adjust OB colors for bullish and bearish zones.
  2. Set opacity to control box transparency.
  3. Extend boxes forward by a fixed number of bars to visualize OB zones into the future.

發行說明
🔁 1. Smarter Memory Management
✅ Before:
Always pushed both a box and line, even if showMiddleLine was off (leading to na line values stored in arrays).

Used array.shift() to delete the oldest OB, which is relatively costly in performance for large arrays.

✅ Now:
Only stores a line if it’s actually drawn (showMiddleLine is true).

Uses array.size() checks and simple deletion — avoiding any unnecessary memory use.

No na values stored in arrays.

🧼 2. Cleaner and Safer OB Cleanup
✅ Before:
Repeated code for OB deletion in both bullish and bearish cases.

Touched flags (longTouched, shortTouched) were manually maintained inside two loops.

✅ Now:
OB cleanup is abstracted into one reusable f_clean() function.

Touched status is returned cleanly from the function — avoiding shared state and improving code clarity.

Added safety to skip loop if arrays are empty (preventing runtime errors).

🔧 3. Modular and Maintainable Structure
✅ Before:
All logic was inline — harder to debug or extend.

Logic duplication between bullish and bearish paths.

✅ Now:
Creation and cleanup are handled in separate, testable functions (f_createOB(), f_addOB(), f_clean()).

Makes future improvements (like OB merging, styling, alerting) much easier to implement and reuse.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。