OPEN-SOURCE SCRIPT
S4_IBS_Mean_Rev_3candleExit

Overview:
This is a rules-based, mean reversion strategy designed to trade pullbacks using the Internal Bar Strength (IBS) indicator. The system looks for oversold conditions based on IBS, then enters long trades, holding for a maximum of 3 bars or until the trade becomes profitable.
The strategy includes:
✅ Strict entry rules based on IBS
✅ Hardcoded exit conditions for risk management
✅ A clean visual table summarizing key performance metrics
How It Works:
1. Internal Bar Strength (IBS) Setup:
The IBS is calculated using the previous bar’s price range:
IBS = (Previous Close - Previous Low) / (Previous High - Previous Low)
IBS values closer to 0 indicate price is near the bottom of the previous range, suggesting oversold conditions.
2. Entry Conditions:
IBS must be ≤ 0.25, signaling an oversold setup.
Trade entries are only allowed within a user-defined backtest window (default: 2024).
Only one trade at a time is permitted (long-only strategy).
3. Exit Conditions:
If the price closes higher than the entry price, the trade exits with a profit.
If the trade has been open for 3 bars without showing profit, the trade is forcefully exited.
All trades are closed automatically at the end of the backtest window if still open.
Additional Features:
📊 A real-time performance metrics table is displayed on the chart, showing:
- Total trades
- % of profitable trades
- Total P&L
- Profit Factor
- Max Drawdown
- Best/Worst trade performance
📈 Visual markers indicate trade entries (green triangle) and exits (red triangle) for easy chart interpretation.
Who Is This For?
This strategy is designed for:
✅ Traders exploring systematic mean reversion approaches
✅ Those who prefer strict, rules-based setups with no subjective decision-making
✅ Traders who want built-in performance tracking directly on the chart
Note: This strategy is provided for educational and research purposes. It is a backtested model and past performance does not guarantee future results. Users should paper trade and validate performance before considering real capital.
This is a rules-based, mean reversion strategy designed to trade pullbacks using the Internal Bar Strength (IBS) indicator. The system looks for oversold conditions based on IBS, then enters long trades, holding for a maximum of 3 bars or until the trade becomes profitable.
The strategy includes:
✅ Strict entry rules based on IBS
✅ Hardcoded exit conditions for risk management
✅ A clean visual table summarizing key performance metrics
How It Works:
1. Internal Bar Strength (IBS) Setup:
The IBS is calculated using the previous bar’s price range:
IBS = (Previous Close - Previous Low) / (Previous High - Previous Low)
IBS values closer to 0 indicate price is near the bottom of the previous range, suggesting oversold conditions.
2. Entry Conditions:
IBS must be ≤ 0.25, signaling an oversold setup.
Trade entries are only allowed within a user-defined backtest window (default: 2024).
Only one trade at a time is permitted (long-only strategy).
3. Exit Conditions:
If the price closes higher than the entry price, the trade exits with a profit.
If the trade has been open for 3 bars without showing profit, the trade is forcefully exited.
All trades are closed automatically at the end of the backtest window if still open.
Additional Features:
📊 A real-time performance metrics table is displayed on the chart, showing:
- Total trades
- % of profitable trades
- Total P&L
- Profit Factor
- Max Drawdown
- Best/Worst trade performance
📈 Visual markers indicate trade entries (green triangle) and exits (red triangle) for easy chart interpretation.
Who Is This For?
This strategy is designed for:
✅ Traders exploring systematic mean reversion approaches
✅ Those who prefer strict, rules-based setups with no subjective decision-making
✅ Traders who want built-in performance tracking directly on the chart
Note: This strategy is provided for educational and research purposes. It is a backtested model and past performance does not guarantee future results. Users should paper trade and validate performance before considering real capital.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。