OPEN-SOURCE SCRIPT

Smart Money Concept ML [PickMyTrade]

7 208
Price breaks a swing level. Do you take the break, or wait for a retest?
Smart Money Concept ML brings that question onto the chart: structure and liquidity mapped together, a retest estimate recorded at each swing break, and a running check of how those estimates compare with what actually happened.

Snapshot
――――――――――――――――――――――――――――――――――――――

🔷 WHAT IT MEASURES

🔸 Break of Structure (BOS) in the established direction and Change of Character (CHoCH) against it, using confirmed swing points
🔸 Order blocks, optional fair value gaps, equal highs and lows, and the protected and opposing extremes of the current range
🔸 Order blocks, optional fair value gaps, equal highs and lows, and the protected and opposing extremes of the current range. Optional internal structure shows shorter swings; premium/discount shading shows the two halves of the dealing range
🔸 Retest odds — the estimated chance of price touching the broken swing level within the selected number of bars. A touch counts as a retest; it does not require a bounce or a successful trade
🔸 Liquidity odds — the estimated chance of the nearest untaken pool above price being traded through before the nearest pool below, and vice versa
――――――――――――――――――――――――――――――――――――――

🔷 THE LEARNING ENGINE

🔸 Retest estimates begin with a random-walk calculation using distance from the broken level, recent price-change volatility, and the retest window. The mathematical basis is the reflection principle
🔸 Liquidity estimates begin with the standard gambler’s-ruin first-touch calculation: where price sits between two boundaries
🔸 Bayesian logistic calibration adjusts these starting estimates as outcomes resolve on the chart. Retest calibration learns an intercept and slope; liquidity calibration learns a slope while preserving complementary upper and lower odds
🔸 This calibration is the learned component behind “ML.” Structure detection, zones, and signal rules are explicitly defined in the code
🔸 Each calibration fit uses its latest 500 resolved observations at most, with a prior that pulls it toward the starting formula when evidence is limited. The table reads LEARNING until 30 break observations have been scored as retested or not retested; fitting already takes place during that period. Displayed scoring totals can exceed 500
🔸 Each recorded estimate is scored before its own outcome is used to update the model
🔸 A retest observation resolves on its first later touch or when its window expires. Liquidity calibration samples qualifying setups at swing breaks; setups that cross both pools on one bar or remain unresolved after 1,000 bars are excluded
――――――――――――――――――――――――――――――――――――――

🔷 CHECKING THE EVIDENCE

🔸 Calibration compares the average recorded estimate with the observed event rate and shows the sample count. Tooltips add probability-error comparisons against the unadjusted formula and the chart’s running base rate
🔸 The Edge Test compares three groups: BOS versus CHoCH, breaks with versus without a fair value gap in the leg, and breaks preceded versus not preceded by a liquidity sweep
🔸 Follow-through means a close one risk unit beyond the break close before a close through the protected swing. Unresolved observations expire after 150 bars and are excluded
🔸 A two-proportion test, adjusted for the three comparisons, checks whether an observed difference exceeds its statistical threshold. This describes the loaded sample; it does not establish a lasting trading advantage
――――――――――――――――――――――――――――――――――――――

🔷 SIGNALS AND DISPLAY

🔸 Break Close records a hypothetical entry on a qualifying confirmed swing break. Level Retest waits within the selected window for a later bar to touch the level and close back beyond it in the break direction; a close through the protected swing cancels the setup. Adaptive waits only when the retest estimate meets its threshold
🔸 Stops sit beyond the protected swing, with an ATR buffer. Two targets are expressed as multiples of initial risk, with an optional move of the stop to entry after TP1
🔸 One signal is tracked at a time. Same-direction signals are skipped; an opposing signal closes the existing position at the bar’s close
🔸 The hypothetical Record scores half the position at TP1 and the remainder at TP2 or another exit. If TP1 is never reached, the full position is scored at the exit. It reports average R, adds an approximate 95% interval from 10 closed signals, and labels fewer than 30 as too few to judge
🔸 Blue marks bullish structure and orange marks bearish structure. Display toggles control the zones and labels; Zen Mode hides labels and the table
🔸 Alerts cover structure breaks, liquidity sweeps, and signal events. Select “Any alert() function call” for the combined entry and exit stream, available as Text or JSON
🔸 Eight separate alert conditions cover BUY, SELL, signal closure, bullish and bearish CHoCH, bullish and bearish BOS, and liquidity sweeps. The combined Text/JSON signal stream is described below
――――――――――――――――――――――――――――――――――――――

🔷 ALERTS AND AUTOMATION

🔸 Supports webhook-based automation through TradingView alerts and an external receiver configured for this script’s message format. The indicator generates signals; the receiving service handles order execution
🔸 Choose Text for readable notifications or JSON for structured integration. JSON includes source, event, action, position, side, symbol, timeframe, price, entry, sl, tp1, and tp2
🔸 Signal events include entry, TP1, TP2, stop loss, stop at entry, timeout, and reversal. The action field identifies buy, sell, partial_close, or close. The side field describes the original position direction, including on exits; receivers should use action and position to interpret an exit
🔸 After selecting the symbol, timeframe, and script inputs, set Alert Message Format to JSON and create an alert using “Any alert() function call.” Add your receiver’s webhook URL in the alert settings. TradingView requires two-factor authentication for webhooks
🔸 Messages are emitted on confirmed bar closes. A reported stop or target price is the script’s reference price for the event, not confirmation of an external fill. On a reversal, the close message is sent before the new entry message
🔸 The payload does not include order quantity, account credentials, or a unique event ID. Position sizing, symbol mapping, duplicate handling, and execution rules must be configured in the receiver. Compatibility with a particular execution platform depends on its required payload
🔸 A TP2 event can occur without a separate TP1 message. If multiple exit events occur on one bar, only the final assigned exit message is sent. The receiver must account for this when managing partial exits; the chart’s hypothetical 50% allocation is not an order-size instruction in the payload
🔸 Recreate the alert after changing script code, inputs, symbol, or timeframe: an existing TradingView alert runs its saved configuration. Hiding Buy/Sell signals changes their display; it does not disable the underlying alert logic
――――――――――――――――――――――――――――――――――――――

🔷 INPUTS

Swing Length / Internal Length — bars on each side needed to confirm a pivot. Defaults 10 / 3.
Order Blocks — number retained per side. Default 2.
Fair Value Gap Minimum / Equal-Level Tolerance — defaults 0.30 / 0.15 ATR.
Retest Window — time allowed for a return to the broken level. Default 20 bars.
Entry — Break Close, Level Retest, or Adaptive. Default Break Close.
Adaptive Threshold — estimate required to wait for a retest in Adaptive mode. Default 80%.
Breaks That Signal — CHoCH, BOS, or both. Default both.
Stop Buffer / Maximum Risk — defaults 0.20 / 6.0 ATR; wider setups are skipped.
TP1 / TP2 — defaults 1R / 2R. Stop to entry after TP1 is enabled by default.
Trade Timeout — default 150 bars.
Alert Message Format — Text or JSON. Default Text.
――――――――――――――――――――――――――――――――――――――

🔷 REQUIREMENTS AND LIMITATIONS

🔸 Use standard price bars. Synthetic chart prices can distort the measurements and hypothetical fills
🔸 Pivots become available only after their right-side confirmation bars close. A swing marker identifies an earlier bar; it was not available on that bar
🔸 Breaks, signals, and recorded estimates are committed at bar close. Live liquidity odds and the premium/discount reading can change during the current bar
🔸 Learning starts from the loaded history. Loading a different stretch of data can change calibration, historical estimates, diagnostics, and Adaptive signals
🔸 Random-walk assumptions simplify market behavior. Overlapping observations can also make statistical intervals appear more precise than the evidence warrants
🔸 Retest and liquidity percentages describe specific touch events, not win rates. The signal record is hypothetical, excludes commission and slippage, and is not a Strategy Tester backtest
🔸 When a later bar touches both a stop and a target, the record gives the stop priority. Chart bars cannot reveal every intrabar price sequence
――――――――――――――――――――――――――――――――――――――
Built in Pine Script v6. Open source — Mozilla Public License 2.0.

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.