Machine Learning Random Forest Strategy
May 31, 2026

The Machine Learning Random Forest Strategy indicator utilizes ensemble learning techniques to forecast market direction and price magnitude. By combining multiple decision stumps into a shallow Random Forest model, the tool provides a probabilistic outlook on whether the next move is likely to be bullish or bearish, alongside an estimated expected return.
Usage
The indicator can be used to identify high-probability reversal or continuation setups based on machine learning classifications.
- Bullish Signals: Triggered when the bullish probability exceeds the defined threshold (default 60%) and the cooldown period has passed.
- Bearish Signals: Triggered when the bearish probability (1 - Bull Prob) exceeds the threshold.
- Confirmation: Stronger signals occur when the Classifier (direction) and the Regression Forest (magnitude/expected return) align. For example, a high bullish probability coupled with a positive expected return indicates higher conviction.
- Adaptive Threshold: If enabled, the tool automatically raises the required probability threshold during periods of poor performance, filtering out lower-quality signals in difficult market regimes.
Details
This script implements a depth-1 Random Forest using "decision stumps" to stay within the execution limits of Pine Script while maintaining ensemble logic.
- Bootstrap Sampling: Each tree is trained on a random subset of historical data.
- Information Gain: The model performs a threshold search using Gini Impurity to select the most effective splits for its predictions.
- Rolling Window: The model continuously retrains on the most recent N bars (default 60), allowing it to adapt to non-stationary market conditions without lookahead bias.
- Features: The model evaluates three primary inputs: an Anchor Oscillator (RSI, MFI, Stoch, or Z-Score), Trend Correlation (price vs. time), and Normalized Momentum.
Settings
Model & Logic
- Anchor Oscillator/Length: Sets the primary momentum or mean reversion feature and its lookback period.
- Training Window (bars): Determines how much recent history the model uses for the rolling retraining process.
- Number of Trees: Controls the number of decision stumps in the ensemble.
- Signal Probability Threshold: The baseline probability required to trigger a signal.
- Adaptive Threshold: Toggles the self-correcting logic that tightens signal requirements based on recent performance.
Filters & Visuals
- Signal Cooldown: The minimum number of bars required between signals of the same direction to prevent clustering.
- Enable ADX Trend Filter: Filters signals based on a minimum ADX level to prioritize trending environments.
- TP/SL Settings: Adjusts ATR-based target price and stop loss levels for signal visualization.
- Show Backtest Table: Displays a summary of win rate, profit factor, and cumulative PnL on the chart.
FAQ
How do I access the Machine Learning Random Forest Strategy?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
What features does the model use to predict price?
The model evaluates four normalized features: the selected Anchor Oscillator, Trend Correlation, Momentum normalized by ATR, and recent volatility.
Why does the probability threshold change on my chart?
If "Adaptive Threshold" is enabled, the indicator increases the required probability for a signal if recent trades have been unsuccessful, signaled by an orange marker in the statistics table.
Unlock Unlimited Access to the LuxAlgo Library
Upgrade your plan to get all indicators, strategies, charts, and full access to Quant, our AI agent.
Trading & investing are risky and many will lose money in connection with trading and investing activities. All content on this site is not intended to, and should not be, construed as financial advice. Decisions to buy, sell, hold or trade in securities, commodities and other investments involve risk and are best made based on the advice of qualified financial professionals. Past performance does not guarantee future results.
Hypothetical or Simulated performance results have certain limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, including, but not limited to, lack of liquidity. Simulated trading programs in general are designed with the benefit of hindsight, and are based on historical information. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.
Testimonials appearing on this website may not be representative of other clients or customers and is not a guarantee of future performance or success.
As a provider of technical analysis tools and strategies, we do not have access to the personal trading accounts or brokerage statements of our customers. As a result, we have no reason to believe our customers perform better or worse than traders as a whole based on any content, tool, or platform feature we provide.
Charts used on this site are by TradingView in which the majority of our technical indicators are built on. TradingView® is a registered trademark of TradingView, Inc. www.TradingView.com TradingView® has no affiliation with the owner, developer, or provider of the Services described herein.
Market data is provided by CBOE, CME Group, BarChart, Massive, CoinAPI. Select U.S. equities data is provided through Massive. CBOE BZX real-time U.S. equities data is licensed from CBOE and provided through BarChart. Real-time futures data is licensed from CME Group and provided through BarChart. Select cryptocurrency data, including major coins, is provided through CoinAPI. All data is provided “as is” and should be verified independently for trading purposes.
This does not represent our full Disclaimer. Please read our full disclaimer.
© 2026 LuxAlgo Global, LLC.

