OPEN-SOURCE SCRIPT
Order Block AI [PickMyTrade]

Most Order Block indicators draw zones and leave you guessing which ones to trade. Order Block AI adds a machine learning engine that learns from every historical order block retest on your chart — comparing current market conditions to past setups and returning a data-driven confidence score before you enter.
The core engine is K-Nearest Neighbors (KNN) with Lorentzian distance. Rather than applying fixed rules, it stores every past order block retest as a feature vector — RSI level, volume strength, and ADX trend reading at the moment of retest. It then records what happened: did price reach the take profit or reverse to the stop? On each new signal, the model finds the K most similar historical episodes and votes on the likely outcome. The confidence % you see on the label is the model's output — not a static threshold, but a score that adapts as new market data resolves.
────────────────────────────────────
3 Layers of Confirmation
Layer 1 · Market Structure
Pivot-based detection of confirmed swing highs and lows:
Layer 2 · Order Block + Liquidity Sweep
A signal requires price to actively retest the OB zone. No retest = no signal.
Layer 3 · KNN Classification
When a retest occurs, the KNN engine retrieves the K most similar historical setups using Lorentzian distance — a log-space metric that handles outliers better than standard Euclidean distance. The confidence score reflects how many of those K analogues resolved in the signal direction. The model updates continuously as past signals resolve, meaning it gets more informed over time without any manual adjustment.
Signal fires only when all 3 align:
CHoCH or Liquidity Sweep → Order Block Retest → KNN Confidence ≥ Threshold
────────────────────────────────────
Non-Repainting
Pivots require full left + right bar confirmation before any signal is issued. The label appears at the confirmed bar — what you see is what was tradeable at the time.
────────────────────────────────────
Settings
Market Structure
Order Blocks
Fair Value Gaps
KNN Engine
Risk Management
Display
────────────────────────────────────
Alerts
────────────────────────────────────
Notes
────────────────────────────────────
Risk Disclosure
Confidence scores reflect the frequency of past patterns in the KNN training history — they do not guarantee future outcomes. Use in combination with your own position sizing and risk management. Not financial advice.
The core engine is K-Nearest Neighbors (KNN) with Lorentzian distance. Rather than applying fixed rules, it stores every past order block retest as a feature vector — RSI level, volume strength, and ADX trend reading at the moment of retest. It then records what happened: did price reach the take profit or reverse to the stop? On each new signal, the model finds the K most similar historical episodes and votes on the likely outcome. The confidence % you see on the label is the model's output — not a static threshold, but a score that adapts as new market data resolves.
────────────────────────────────────
3 Layers of Confirmation
Layer 1 · Market Structure
Pivot-based detection of confirmed swing highs and lows:
- BOS (Break of Structure) — trend continuation
- CHoCH (Change of Character) — first counter-trend break, potential reversal
Layer 2 · Order Block + Liquidity Sweep
- Bullish OB — last bearish candle before a bullish structure break
- Bearish OB — last bullish candle before a bearish structure break
- Liquidity Sweep — wick beyond last swing that closes back inside (stop hunt)
A signal requires price to actively retest the OB zone. No retest = no signal.
Layer 3 · KNN Classification
When a retest occurs, the KNN engine retrieves the K most similar historical setups using Lorentzian distance — a log-space metric that handles outliers better than standard Euclidean distance. The confidence score reflects how many of those K analogues resolved in the signal direction. The model updates continuously as past signals resolve, meaning it gets more informed over time without any manual adjustment.
Signal fires only when all 3 align:
CHoCH or Liquidity Sweep → Order Block Retest → KNN Confidence ≥ Threshold
────────────────────────────────────
Non-Repainting
Pivots require full left + right bar confirmation before any signal is issued. The label appears at the confirmed bar — what you see is what was tradeable at the time.
────────────────────────────────────
Settings
Market Structure
- Pivot Left / Right Bars — confirmation bars for swing detection
Order Blocks
- Show/hide zones, bull and bear colors
Fair Value Gaps
- Show/hide 3-candle imbalance zones (visual context only — does not affect signals)
KNN Engine
- K Neighbors — how many historical analogues vote on the signal (default 5)
- History Length — maximum past signals stored for KNN learning (default 200)
- Min Confidence — minimum fraction of K neighbors that must agree to fire a signal (default 0.60)
- Outcome Bars — bars after a historical signal to evaluate its outcome (default 20)
Risk Management
- ATR Stop Multiplier and R:R Ratio — used by the KNN engine to score whether past signals reached TP or SL
Display
- Zen Mode — hides all visuals except entry signal labels
- Show/hide BOS and CHoCH structure labels
────────────────────────────────────
Alerts
- OB AI Long Signal
- OB AI Short Signal
────────────────────────────────────
Notes
- The KNN engine improves as it accumulates more resolved historical setups — give it time on the first load
- Works on any symbol and timeframe
- Lower the confidence threshold to see more signals; raise it to filter more aggressively
- Fair Value Gap zones are displayed as context — they do not affect signal logic
────────────────────────────────────
Risk Disclosure
Confidence scores reflect the frequency of past patterns in the KNN training history — they do not guarantee future outcomes. Use in combination with your own position sizing and risk management. Not financial advice.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Automate TradingView alerts to brokers no coding needed. Trade futures, forex, or crypto, copy trades across unlimited accounts, & control risk with ease.
For Tradovate: bit.ly/4a1KBrY
For all other supported brokers: bit.ly/4qEbU2G
For Tradovate: bit.ly/4a1KBrY
For all other supported brokers: bit.ly/4qEbU2G
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
Automate TradingView alerts to brokers no coding needed. Trade futures, forex, or crypto, copy trades across unlimited accounts, & control risk with ease.
For Tradovate: bit.ly/4a1KBrY
For all other supported brokers: bit.ly/4qEbU2G
For Tradovate: bit.ly/4a1KBrY
For all other supported brokers: bit.ly/4qEbU2G
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.