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.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
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
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
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
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。