OPEN-SOURCE SCRIPT
Range Filter Strategy [Real Backtest]

Range Filter Strategy - Real Backtesting
# Overview
Advanced Range Filter strategy designed for realistic backtesting with precise execution timing and comprehensive risk management. Built specifically for cryptocurrency markets with customizable parameters for different assets and timeframes.
Core Algorithm
Range Filter Technology:
- Smooth Average Range calculation using dual EMA filtering
- Dynamic range-based price filtering to identify trend direction
- Anti-noise filtering system to reduce false signals
- Directional momentum tracking with upward/downward counters
Key Features
Real-Time Execution (No Delay)
- Process orders on tick: Immediate execution without waiting for bar close
- Bar magnifier integration for intrabar precision
- Calculate on every tick for maximum responsiveness
- Standard OHLC bypass for enhanced accuracy
Realistic Price Simulation
- HL2 entry pricing (High+Low)/2 for realistic fills
- Configurable spread buffer simulation
- Random slippage generation (0 to max slippage)
- Market liquidity validation before entry
Advanced Signal Filtering
- Volume-based filtering with customizable ratio
- Optional signal confirmation system (1-3 bars)
- Anti-repetition logic to prevent duplicate signals
- Daily trade limit controls
Risk Management
- Fixed Risk:Reward ratios with precise point calculation
- Automatic stop loss and take profit execution
- Position size management
- Maximum daily trades limitation
Alert System
- Real-time alerts synchronized with strategy execution
- Multiple alert types: Setup, Entry, Exit, Status
- Customizable message formatting with price/time inclusion
- TradingView alert panel integration
Default Parameters
Optimized for BTC 5-minute charts:
- Sampling Period: 100
- Range Multiplier: 3.0
- Risk: 50 points
- Reward: 100 points (1:2 R:R)
- Spread Buffer: 2.0 points
- Max Slippage: 1.0 points
Signal Logic
Long Entry Conditions:
- Price above Range Filter line
- Upward momentum confirmed
- Volume requirements met (if enabled)
- Confirmation period completed (if enabled)
- Daily trade limit not exceeded
Short Entry Conditions:
- Price below Range Filter line
- Downward momentum confirmed
- Volume requirements met (if enabled)
- Confirmation period completed (if enabled)
- Daily trade limit not exceeded
Visual Elements
- Range Filter line with directional coloring
- Upper and lower target bands
- Entry signal markers
- Risk/Reward ratio boxes
- Real-time settings dashboard
Customization Options
Market Adaptation:
- Adjust Sampling Period for different timeframes
- Modify Range Multiplier for various volatility levels
- Configure spread/slippage for different brokers
- Set appropriate R:R ratios for trading style
Filtering Controls:
- Enable/disable volume filtering
- Adjust confirmation requirements
- Set daily trade limits
- Customize alert preferences
Performance Features
- Realistic backtesting results aligned with live trading
- Elimination of look-ahead bias
- Proper order execution simulation
- Comprehensive trade statistics
Alert Configuration
Alert Types Available:
- Entry signals with complete trade information
- Setup alerts for early preparation
- Exit notifications for position management
- Filter direction changes for market context
Message Format:
Symbol - Action | Price: XX.XX | Stop: XX.XX | Target: XX.XX | Time: HH:MM
Usage Recommendations
Optimal Settings:
- Bitcoin/Major Crypto: Default parameters
- Forex: Reduce sampling period to 50-70, multiplier to 2.0-2.5
- Stocks: Reduce sampling period to 30-50, multiplier to 1.0-1.8
- Gold: Sampling period 60-80, multiplier 1.5-2.0
TradingView Configuration:
- Recalculate: "On every tick"
- Orders: "Use bar magnifier"
- Data: Real-time feed recommended
Risk Disclaimer
This strategy is designed for educational and analytical purposes. Past performance does not guarantee future results. Always test thoroughly on paper trading before live implementation. Consider market conditions, broker execution, and personal risk tolerance when using any automated trading system.
Best Settings Found for Gold 15-Minute Timeframe
After extensive testing and optimization, these are the most effective settings I've discovered for trading Gold (XAUUSD) on the 15-minute timeframe:
Core Filter Settings:
Sampling Period: 100
Range Multiplier: 3.0
Professional Execution Engine:
Realistic Entry: Enabled (HL2)
Spread Buffer: 2 points
Dynamic Slippage: Enabled with max 1 point
Volume Filter: Enabled at 1.7x ratio
Signal Confirmation: Enabled with 1 bar confirmation
Risk Management:
Stop Loss: 50 points
Take Profit: 100 points (2:1 Risk-Reward)
Max Trades Per Day: 5
These settings provide an excellent balance between signal accuracy and realistic market execution. The volume filter at 1.7x ensures we only trade during periods of sufficient market activity, while the 1-bar confirmation helps filter out false signals. The spread buffer and slippage settings account for real trading costs, making backtest results more realistic and achievable in live trading.
# Overview
Advanced Range Filter strategy designed for realistic backtesting with precise execution timing and comprehensive risk management. Built specifically for cryptocurrency markets with customizable parameters for different assets and timeframes.
Core Algorithm
Range Filter Technology:
- Smooth Average Range calculation using dual EMA filtering
- Dynamic range-based price filtering to identify trend direction
- Anti-noise filtering system to reduce false signals
- Directional momentum tracking with upward/downward counters
Key Features
Real-Time Execution (No Delay)
- Process orders on tick: Immediate execution without waiting for bar close
- Bar magnifier integration for intrabar precision
- Calculate on every tick for maximum responsiveness
- Standard OHLC bypass for enhanced accuracy
Realistic Price Simulation
- HL2 entry pricing (High+Low)/2 for realistic fills
- Configurable spread buffer simulation
- Random slippage generation (0 to max slippage)
- Market liquidity validation before entry
Advanced Signal Filtering
- Volume-based filtering with customizable ratio
- Optional signal confirmation system (1-3 bars)
- Anti-repetition logic to prevent duplicate signals
- Daily trade limit controls
Risk Management
- Fixed Risk:Reward ratios with precise point calculation
- Automatic stop loss and take profit execution
- Position size management
- Maximum daily trades limitation
Alert System
- Real-time alerts synchronized with strategy execution
- Multiple alert types: Setup, Entry, Exit, Status
- Customizable message formatting with price/time inclusion
- TradingView alert panel integration
Default Parameters
Optimized for BTC 5-minute charts:
- Sampling Period: 100
- Range Multiplier: 3.0
- Risk: 50 points
- Reward: 100 points (1:2 R:R)
- Spread Buffer: 2.0 points
- Max Slippage: 1.0 points
Signal Logic
Long Entry Conditions:
- Price above Range Filter line
- Upward momentum confirmed
- Volume requirements met (if enabled)
- Confirmation period completed (if enabled)
- Daily trade limit not exceeded
Short Entry Conditions:
- Price below Range Filter line
- Downward momentum confirmed
- Volume requirements met (if enabled)
- Confirmation period completed (if enabled)
- Daily trade limit not exceeded
Visual Elements
- Range Filter line with directional coloring
- Upper and lower target bands
- Entry signal markers
- Risk/Reward ratio boxes
- Real-time settings dashboard
Customization Options
Market Adaptation:
- Adjust Sampling Period for different timeframes
- Modify Range Multiplier for various volatility levels
- Configure spread/slippage for different brokers
- Set appropriate R:R ratios for trading style
Filtering Controls:
- Enable/disable volume filtering
- Adjust confirmation requirements
- Set daily trade limits
- Customize alert preferences
Performance Features
- Realistic backtesting results aligned with live trading
- Elimination of look-ahead bias
- Proper order execution simulation
- Comprehensive trade statistics
Alert Configuration
Alert Types Available:
- Entry signals with complete trade information
- Setup alerts for early preparation
- Exit notifications for position management
- Filter direction changes for market context
Message Format:
Symbol - Action | Price: XX.XX | Stop: XX.XX | Target: XX.XX | Time: HH:MM
Usage Recommendations
Optimal Settings:
- Bitcoin/Major Crypto: Default parameters
- Forex: Reduce sampling period to 50-70, multiplier to 2.0-2.5
- Stocks: Reduce sampling period to 30-50, multiplier to 1.0-1.8
- Gold: Sampling period 60-80, multiplier 1.5-2.0
TradingView Configuration:
- Recalculate: "On every tick"
- Orders: "Use bar magnifier"
- Data: Real-time feed recommended
Risk Disclaimer
This strategy is designed for educational and analytical purposes. Past performance does not guarantee future results. Always test thoroughly on paper trading before live implementation. Consider market conditions, broker execution, and personal risk tolerance when using any automated trading system.
Best Settings Found for Gold 15-Minute Timeframe
After extensive testing and optimization, these are the most effective settings I've discovered for trading Gold (XAUUSD) on the 15-minute timeframe:
Core Filter Settings:
Sampling Period: 100
Range Multiplier: 3.0
Professional Execution Engine:
Realistic Entry: Enabled (HL2)
Spread Buffer: 2 points
Dynamic Slippage: Enabled with max 1 point
Volume Filter: Enabled at 1.7x ratio
Signal Confirmation: Enabled with 1 bar confirmation
Risk Management:
Stop Loss: 50 points
Take Profit: 100 points (2:1 Risk-Reward)
Max Trades Per Day: 5
These settings provide an excellent balance between signal accuracy and realistic market execution. The volume filter at 1.7x ensures we only trade during periods of sufficient market activity, while the 1-bar confirmation helps filter out false signals. The spread buffer and slippage settings account for real trading costs, making backtest results more realistic and achievable in live trading.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.