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.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.