tradingview.com/chart/JYsjnmFD/
Template Name:XGBoost Approx
Core Idea: This strategy attempts to mimic the output of an XGBoost model (a powerful machine learning algorithm) by combining several common technical indicators with the Rate of Change (ROC) , MACD, RSI and EMA across multiple timeframes. It uses a weighted sum of normalized indicators to generate a "composite indicator," and trades based on this indicator crossing predefined thresholds. The multi-timeframe ROC acts as a trend filter.
Key Features and How They Work:
Multi-Timeframe Analysis (MTF): This is the heart of the strategy. It looks at the price action on three different timeframes:
Trading Timeframe (tradingTF): The timeframe you're actually placing trades on (e.g., 1-minute, 5-minute, 1-hour, etc.). You set this directly in the strategy's settings. This is the most important timeframe.
Lower Timeframe (selectedLTF): A timeframe lower than your trading timeframe. Used to catch early signs of trend changes. The script automatically selects an appropriate lower timeframe based on your trading timeframe. This is primarily used for a more sensitive ROC filter.
Current Timeframe (tradingTF): The strategy uses the current (trading) timeframe, to include it in the ROC filter.
Higher Timeframe (selectedHTF): A timeframe higher than your trading timeframe. Used to confirm the overall trend direction. The script automatically selects this, too. This is the "big picture" timeframe.
The script uses request.security to get data from these other timeframes. The lookahead=barmerge.lookahead_on part is important; it prevents the strategy from "peeking" into the future, which would make backtesting results unrealistic.
Indicators Used:
SMA (Simple Moving Average): Smooths out price data. The strategy calculates a normalized SMA, which essentially measures how far the current SMA is from its own average, in terms of standard deviations.
RSI (Relative Strength Index): An oscillator that measures the speed and change of price movements. Normalized similarly to the SMA.
MACD (Moving Average Convergence Divergence): A trend-following momentum indicator. The strategy uses the difference between the MACD line and its signal line, normalized.
ROC (Rate of Change): Measures the percentage change in price over a given period (defined by rocLength). This is the key indicator in this strategy, and it's used on all three timeframes.
Volume: The strategy considers the change in volume, also normalized. This can help identify strong moves (high volume confirming a price move).
Normalization: Each indicator is normalized. This is done by subtracting the indicator's average and dividing by its standard deviation. Normalization puts all the indicators on a similar scale (roughly between -3 and +3, most of the time), making it easier to combine them with weights.
Weights: The strategy uses weights (e.g., weightSMA, weightRSI, etc.) to determine how much influence each indicator has on the final "composite indicator." These weights are crucial for the strategy's performance. You can adjust them in the strategy's settings.
Composite Indicator: This is the weighted sum of all the normalized indicators. It's the strategy's main signal generator.
Thresholds: The buyThreshold and sellThreshold determine when the strategy enters a trade. When the composite indicator crosses above the buyThreshold, it's a potential buy signal. When it crosses below the sellThreshold, it's a potential sell signal.
Multi-Timeframe ROC Filter: The strategy uses a crucial filter based on the ROC on all selected timeframes. For a long trade, the ROC must be positive on all three timeframes (ltf_roc_long, ctf_roc_long, htf_roc_long must all be true). For a short trade, the ROC must be negative on all three timeframes. This is a strong trend filter.
Timeframe Filter Selection The script intelligently chooses filter timeframes (selectedLTF, selectedHTF) based on the tradingTF you select. This is done by the switch_filter_timeframes function:
Trading Timeframe (tradingTF) Lower Timeframe Filter (selectedLTF) Higher Timeframe Filter (selectedHTF)
1 minute 60 minutes (filterTF1) 60 minutes (filterTF1)
5 minute 240 minutes (filterTF2) 240 minutes (filterTF2)
15 minute 240 minutes (filterTF2) 240 minutes (filterTF2)
30 minute, 60 minute 1 Day (filterTF3) 1 Day (filterTF3)
240 minute (4 hour) 1 Week (filterTF4) 1 Week (filterTF4)
1 Day 1 Month (filterTF5) 1 Month (filterTF5)
1 Week 1 Month (filterTF5) 1 Month (filterTF5)
How to Use and Optimize the Strategy (Useful Hints):
Backtesting: Always start by backtesting on historical data. TradingView's Strategy Tester is your best friend here. Pay close attention to:
Net Profit: The most obvious metric.
Max Drawdown: The largest peak-to-trough decline during the backtest. This tells you how much you could potentially lose.
Profit Factor: Gross profit divided by gross loss. A value above 1 is desirable.
Win Rate: The percentage of winning trades.
Sharpe Ratio: Risk-adjusted return. A Sharpe Ratio above 1 is generally considered good.
**Sortino Ratio:**Similar to Sharpe but it only takes the standard deviation of the downside risk.
Timeframe Selection: Experiment with different tradingTF values. The strategy's performance will vary greatly depending on the timeframe. Consider the asset you're trading (e.g., volatile crypto vs. a stable stock index). The preconfigured filters are a good starting point.
Weight Optimization: This is where the real "tuning" happens. The default weights are just a starting point. Here's a systematic approach:
Start with the ROC Weights: Since this is a ROC-focused strategy, try adjusting weightROC_LTF, weightROC_CTF, and weightROC_HTF first. See if increasing or decreasing their influence improves results.
Adjust Other Weights: Then, experiment with weightSMA, weightRSI, weightMACD, and weightVolume. Try setting some weights to zero to see if simplifying the strategy helps.
Use TradingView's Optimization Feature: The Strategy Tester has an optimization feature (the little gear icon). You can tell it to test a range of values for each weight and see which combination performs best. Be very careful with optimization. It's easy to overfit to past data, which means the strategy will perform poorly in live trading.
Walk-Forward Optimization: A more robust form of optimization. Instead of optimizing on the entire dataset, you optimize on a smaller "in-sample" period, then test on a subsequent "out-of-sample" period. This helps prevent overfitting. TradingView doesn't have built-in walk-forward optimization, but you can do it manually.
Threshold Adjustment: Experiment with different buyThreshold and sellThreshold values. Making them more extreme (further from zero) will result in fewer trades, but potentially higher-quality signals.
Filter Control (useLTFFilter, useCTFFilter, useHTFFilter): These booleans allow you to enable or disable the ROC filters for each timeframe. You can use this to simplify the strategy or test the importance of each filter. For example, you could try disabling the lower timeframe filter (useLTFFilter = false) to see if it makes the strategy more robust.
Asset Selection: This strategy may perform better on some assets than others. Try it on different markets (stocks, forex, crypto, etc.) and different types of assets within those markets.
Risk Management:
pyramiding = 0: This prevents the strategy from adding to existing positions. This is generally a good idea for beginners.
default_qty_type = strategy.percent_of_equity and default_qty_value = 100: This means the strategy will risk 100% of your equity on each trade. This is extremely risky! Change this to a much smaller percentage, like 1 or 2. You should never risk your entire account on a single trade.
Save Trading
Always use a demo account first.
Use a small percentage of equity.
Use a stop-loss and take-profit orders.
Example Optimization Workflow:
Set tradingTF: Choose a timeframe, e.g., 15 (15 minutes).
Initial Backtest: Run a backtest with the default settings. Note the results.
Optimize ROC Weights: Use TradingView's optimization feature to test different values for weightROC_LTF, weightROC_CTF, and weightROC_HTF. Keep the other weights at their defaults for now.
Optimize Other Weights: Once you have a good set of ROC weights, optimize the other weights one at a time. For example, optimize weightSMA, then weightRSI, etc.
Adjust Thresholds: Experiment with different buyThreshold and sellThreshold values.
Out-of-Sample Testing: Take the best settings from your optimization and test them on a different period of historical data (data that wasn't used for optimization). This is crucial to check for overfitting.
Filter Testing: Systematically enable/disable the time frame filters (useLTFFilter, useCTFFilter, useHTFFilter) to see how each impacts performance.
Template Name:XGBoost Approx
Core Idea: This strategy attempts to mimic the output of an XGBoost model (a powerful machine learning algorithm) by combining several common technical indicators with the Rate of Change (ROC) , MACD, RSI and EMA across multiple timeframes. It uses a weighted sum of normalized indicators to generate a "composite indicator," and trades based on this indicator crossing predefined thresholds. The multi-timeframe ROC acts as a trend filter.
Key Features and How They Work:
Multi-Timeframe Analysis (MTF): This is the heart of the strategy. It looks at the price action on three different timeframes:
Trading Timeframe (tradingTF): The timeframe you're actually placing trades on (e.g., 1-minute, 5-minute, 1-hour, etc.). You set this directly in the strategy's settings. This is the most important timeframe.
Lower Timeframe (selectedLTF): A timeframe lower than your trading timeframe. Used to catch early signs of trend changes. The script automatically selects an appropriate lower timeframe based on your trading timeframe. This is primarily used for a more sensitive ROC filter.
Current Timeframe (tradingTF): The strategy uses the current (trading) timeframe, to include it in the ROC filter.
Higher Timeframe (selectedHTF): A timeframe higher than your trading timeframe. Used to confirm the overall trend direction. The script automatically selects this, too. This is the "big picture" timeframe.
The script uses request.security to get data from these other timeframes. The lookahead=barmerge.lookahead_on part is important; it prevents the strategy from "peeking" into the future, which would make backtesting results unrealistic.
Indicators Used:
SMA (Simple Moving Average): Smooths out price data. The strategy calculates a normalized SMA, which essentially measures how far the current SMA is from its own average, in terms of standard deviations.
RSI (Relative Strength Index): An oscillator that measures the speed and change of price movements. Normalized similarly to the SMA.
MACD (Moving Average Convergence Divergence): A trend-following momentum indicator. The strategy uses the difference between the MACD line and its signal line, normalized.
ROC (Rate of Change): Measures the percentage change in price over a given period (defined by rocLength). This is the key indicator in this strategy, and it's used on all three timeframes.
Volume: The strategy considers the change in volume, also normalized. This can help identify strong moves (high volume confirming a price move).
Normalization: Each indicator is normalized. This is done by subtracting the indicator's average and dividing by its standard deviation. Normalization puts all the indicators on a similar scale (roughly between -3 and +3, most of the time), making it easier to combine them with weights.
Weights: The strategy uses weights (e.g., weightSMA, weightRSI, etc.) to determine how much influence each indicator has on the final "composite indicator." These weights are crucial for the strategy's performance. You can adjust them in the strategy's settings.
Composite Indicator: This is the weighted sum of all the normalized indicators. It's the strategy's main signal generator.
Thresholds: The buyThreshold and sellThreshold determine when the strategy enters a trade. When the composite indicator crosses above the buyThreshold, it's a potential buy signal. When it crosses below the sellThreshold, it's a potential sell signal.
Multi-Timeframe ROC Filter: The strategy uses a crucial filter based on the ROC on all selected timeframes. For a long trade, the ROC must be positive on all three timeframes (ltf_roc_long, ctf_roc_long, htf_roc_long must all be true). For a short trade, the ROC must be negative on all three timeframes. This is a strong trend filter.
Timeframe Filter Selection The script intelligently chooses filter timeframes (selectedLTF, selectedHTF) based on the tradingTF you select. This is done by the switch_filter_timeframes function:
Trading Timeframe (tradingTF) Lower Timeframe Filter (selectedLTF) Higher Timeframe Filter (selectedHTF)
1 minute 60 minutes (filterTF1) 60 minutes (filterTF1)
5 minute 240 minutes (filterTF2) 240 minutes (filterTF2)
15 minute 240 minutes (filterTF2) 240 minutes (filterTF2)
30 minute, 60 minute 1 Day (filterTF3) 1 Day (filterTF3)
240 minute (4 hour) 1 Week (filterTF4) 1 Week (filterTF4)
1 Day 1 Month (filterTF5) 1 Month (filterTF5)
1 Week 1 Month (filterTF5) 1 Month (filterTF5)
How to Use and Optimize the Strategy (Useful Hints):
Backtesting: Always start by backtesting on historical data. TradingView's Strategy Tester is your best friend here. Pay close attention to:
Net Profit: The most obvious metric.
Max Drawdown: The largest peak-to-trough decline during the backtest. This tells you how much you could potentially lose.
Profit Factor: Gross profit divided by gross loss. A value above 1 is desirable.
Win Rate: The percentage of winning trades.
Sharpe Ratio: Risk-adjusted return. A Sharpe Ratio above 1 is generally considered good.
**Sortino Ratio:**Similar to Sharpe but it only takes the standard deviation of the downside risk.
Timeframe Selection: Experiment with different tradingTF values. The strategy's performance will vary greatly depending on the timeframe. Consider the asset you're trading (e.g., volatile crypto vs. a stable stock index). The preconfigured filters are a good starting point.
Weight Optimization: This is where the real "tuning" happens. The default weights are just a starting point. Here's a systematic approach:
Start with the ROC Weights: Since this is a ROC-focused strategy, try adjusting weightROC_LTF, weightROC_CTF, and weightROC_HTF first. See if increasing or decreasing their influence improves results.
Adjust Other Weights: Then, experiment with weightSMA, weightRSI, weightMACD, and weightVolume. Try setting some weights to zero to see if simplifying the strategy helps.
Use TradingView's Optimization Feature: The Strategy Tester has an optimization feature (the little gear icon). You can tell it to test a range of values for each weight and see which combination performs best. Be very careful with optimization. It's easy to overfit to past data, which means the strategy will perform poorly in live trading.
Walk-Forward Optimization: A more robust form of optimization. Instead of optimizing on the entire dataset, you optimize on a smaller "in-sample" period, then test on a subsequent "out-of-sample" period. This helps prevent overfitting. TradingView doesn't have built-in walk-forward optimization, but you can do it manually.
Threshold Adjustment: Experiment with different buyThreshold and sellThreshold values. Making them more extreme (further from zero) will result in fewer trades, but potentially higher-quality signals.
Filter Control (useLTFFilter, useCTFFilter, useHTFFilter): These booleans allow you to enable or disable the ROC filters for each timeframe. You can use this to simplify the strategy or test the importance of each filter. For example, you could try disabling the lower timeframe filter (useLTFFilter = false) to see if it makes the strategy more robust.
Asset Selection: This strategy may perform better on some assets than others. Try it on different markets (stocks, forex, crypto, etc.) and different types of assets within those markets.
Risk Management:
pyramiding = 0: This prevents the strategy from adding to existing positions. This is generally a good idea for beginners.
default_qty_type = strategy.percent_of_equity and default_qty_value = 100: This means the strategy will risk 100% of your equity on each trade. This is extremely risky! Change this to a much smaller percentage, like 1 or 2. You should never risk your entire account on a single trade.
Save Trading
Always use a demo account first.
Use a small percentage of equity.
Use a stop-loss and take-profit orders.
Example Optimization Workflow:
Set tradingTF: Choose a timeframe, e.g., 15 (15 minutes).
Initial Backtest: Run a backtest with the default settings. Note the results.
Optimize ROC Weights: Use TradingView's optimization feature to test different values for weightROC_LTF, weightROC_CTF, and weightROC_HTF. Keep the other weights at their defaults for now.
Optimize Other Weights: Once you have a good set of ROC weights, optimize the other weights one at a time. For example, optimize weightSMA, then weightRSI, etc.
Adjust Thresholds: Experiment with different buyThreshold and sellThreshold values.
Out-of-Sample Testing: Take the best settings from your optimization and test them on a different period of historical data (data that wasn't used for optimization). This is crucial to check for overfitting.
Filter Testing: Systematically enable/disable the time frame filters (useLTFFilter, useCTFFilter, useHTFFilter) to see how each impacts performance.
Related publications
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.
Related publications
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.