OPEN-SOURCE SCRIPT
BB Mean Reversion Long + SL

This strategy exploits statistical price extremes using Bollinger Bands
on a mean reversion logic — when price closes below the lower band,
it's statistically outside 95% of normal price action.
That's the entry. The target is simple : get back to the mean.
━━━ LOGIC ━━━
- Entry → price closes below the lower band (crossunder)
- Take Profit → price returns to the SMA (middle band)
- Stop Loss → fixed % below entry price
━━━ SETTINGS ━━━
- SMA Period (N) → default 20
- Standard Deviations (K) → default 2.0
- Stop Loss % → default 1.5%
- Pyramiding → up to 3 simultaneous entries
━━━ BEST TIMEFRAME ━━━
Tested and works best between 45min and 2h.
Below 30min : too much noise.
Above 2h : price extremes often reflect real trend, not overreaction.
━━━ NOTES ━━━
→ Designed for mean-reverting assets with clear volatility cycles
→ Works particularly well on XAUUSD, indices ETFs
→ Avoid running during major news events (NFP, CPI, Fed)
→ Not recommended to hold positions over the weekend
→ qty is set to fixed lot — adjust to your broker's lot size
Tune N and K to your asset. Default settings are a starting point,
not a final answer. The edge is in the calibration.
on a mean reversion logic — when price closes below the lower band,
it's statistically outside 95% of normal price action.
That's the entry. The target is simple : get back to the mean.
━━━ LOGIC ━━━
- Entry → price closes below the lower band (crossunder)
- Take Profit → price returns to the SMA (middle band)
- Stop Loss → fixed % below entry price
━━━ SETTINGS ━━━
- SMA Period (N) → default 20
- Standard Deviations (K) → default 2.0
- Stop Loss % → default 1.5%
- Pyramiding → up to 3 simultaneous entries
━━━ BEST TIMEFRAME ━━━
Tested and works best between 45min and 2h.
Below 30min : too much noise.
Above 2h : price extremes often reflect real trend, not overreaction.
━━━ NOTES ━━━
→ Designed for mean-reverting assets with clear volatility cycles
→ Works particularly well on XAUUSD, indices ETFs
→ Avoid running during major news events (NFP, CPI, Fed)
→ Not recommended to hold positions over the weekend
→ qty is set to fixed lot — adjust to your broker's lot size
Tune N and K to your asset. Default settings are a starting point,
not a final answer. The edge is in the calibration.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.