OPEN-SOURCE SCRIPT
Ineficient market

The setup
The 1-2-3 pattern (price-structure reversal, in the Joe Ross / Zeiierman lineage) marks three alternating pivots: an extreme, a pullback, and a second extreme that fails to exceed the first — a Higher-Low for longs, a Lower-High for shorts. Entry fires on confirmation of the 3rd pivot (no waiting for a breakout, which cuts lag). On top of that sits a volatility gate: signals only trigger when relative volatility is compressed (ATR% ≤ its own moving average). Trades resolve on a small fixed TP, a wide SL, and a time-stop.
The inefficiency
This isn't about "predicting direction" — direction is free and doesn't pay. The edge is a short-term overreaction at structure pivots: after price prints a failed extreme, it tends to give back a small, fast fraction of the move. In compressed volatility that give-back is more reliable and less noisy. The edge is statistical and regime-conditional — not a silver bullet.
Why the exit looks "wrong" (and why that's the whole point)
The counterintuitive part: small TP + wide SL + no trailing, no break-even, no touching the trade. We tested active management extensively (move to BE, trailing, tight stops at the "normal MAE") and every version destroys the edge — because 1–3% adverse excursion is normal even on winners, and any tight stop sits exactly where noise wanders. Holding through that swing is what captures the reversion. It's fire-and-forget by design, not by laziness.
How we found it (the differentiator)
This wasn't reverse-engineered from a pretty chart. It survived:
- Random-matched placebo — the same exit engine fired on random bars vs. the real signal, proving the edge lives in the signal, not the short TP.
- Path-dependent backtesting — simulating the exact order of intra-trade events, not aggregate stats (which mislead).
- Conditional MAE analysis — measuring how win probability decays as a trade digs, which set the wide SL and killed the temptation of tight stops.
Inputs: prd (pivot lookback) · ATR ratio max (volatility gate) · TP % · SL % · time-stop · direction (long/short).
Disclaimer: For research/education, not financial advice. Past performance does not guarantee future results. The edge is conditional on regime and costs — test with your own commission/slippage before any live use.
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.