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. اقرأ المزيد في شروط الاستخدام.