OPEN-SOURCE SCRIPT
Quantile Drift Engine [forexobroker]

Quantile Drift Engine uses the rolling 25th and 75th percentiles of close as a robust analogue to mean and variance. The midpoint between Q25 and Q75 is the "interquartile median," which drifts directionally and is far less sensitive to spikes than a moving average. The drift, normalised by ATR, provides the regime gate; close cross of the midpoint provides the entry.
🔶 ALGORITHM
1. q25 = ta.percentile_linear_interpolation(close, N, 25); q75 = same at 75.
2. mid = (q25 + q75) / 2; drift = mid - mid[lag].
3. Trending regime when |drift| > k * ATR.
4. Buy entry: trending up AND close crosses mid up.
5. Sell entry: trending down AND close crosses mid down.
🔶 SIGNAL LOGIC
- Buy: trending up AND close crosses mid up AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: trending down AND close crosses mid down.
- Position-lock state machine.
🔶 INPUTS
- Quantile Window (default 40)
- Drift Lag (default 5 bars)
- Drift Threshold x ATR (default 0.10)
- Cooldown Bars (default 4)
- Visual: dashboard, glow, quantile bands, buy / sell colors
🔶 ALERTS
QDE Buy, QDE Sell, QDE Any Signal, QDE Drift Up, QDE Drift Down, QDE Mid Cross Up, QDE Mid Cross Dn, QDE Outside IQR, QDE Webhook JSON.
🔶 LIMITATIONS
- Percentile estimators need >= ~10 samples to be meaningful; short windows produce step-like quantiles.
- Linear interpolation between samples introduces minor smoothing; raw ranking would be slightly more responsive.
- Drift lag of 5 bars dampens noise but causes slight delay during sharp directional moves.
- IQR midpoint is robust but ignores tail behaviour; for tail-driven instruments pair with a separate volatility filter.
🔶 ALGORITHM
1. q25 = ta.percentile_linear_interpolation(close, N, 25); q75 = same at 75.
2. mid = (q25 + q75) / 2; drift = mid - mid[lag].
3. Trending regime when |drift| > k * ATR.
4. Buy entry: trending up AND close crosses mid up.
5. Sell entry: trending down AND close crosses mid down.
🔶 SIGNAL LOGIC
- Buy: trending up AND close crosses mid up AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: trending down AND close crosses mid down.
- Position-lock state machine.
🔶 INPUTS
- Quantile Window (default 40)
- Drift Lag (default 5 bars)
- Drift Threshold x ATR (default 0.10)
- Cooldown Bars (default 4)
- Visual: dashboard, glow, quantile bands, buy / sell colors
🔶 ALERTS
QDE Buy, QDE Sell, QDE Any Signal, QDE Drift Up, QDE Drift Down, QDE Mid Cross Up, QDE Mid Cross Dn, QDE Outside IQR, QDE Webhook JSON.
🔶 LIMITATIONS
- Percentile estimators need >= ~10 samples to be meaningful; short windows produce step-like quantiles.
- Linear interpolation between samples introduces minor smoothing; raw ranking would be slightly more responsive.
- Drift lag of 5 bars dampens noise but causes slight delay during sharp directional moves.
- IQR midpoint is robust but ignores tail behaviour; for tail-driven instruments pair with a separate volatility filter.
สคริปต์แบบโอเพนซอร์ส
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์แบบโอเพนซอร์ส
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน