Machine Learning: Logistic Regression
Jan 21, 2021

The Machine Learning: Logistic Regression indicator utilizes a classic classification algorithm to categorize market price movements into binary buy or sell states for trend analysis.
Usage
The Usage section describes how the script can be used to identify potential market entries and exits. The indicator retrains its model on every new bar, attempting to classify price action into two categories: Long or Short.
Signals are displayed as "Buy" and "Sell" labels on the chart. Users can also see "Exit" markers (crosses) based on a defined holding period. Because the algorithm relies on iterative weight adjustments, the interpretation of signals can be refined by observing the relationship between the price and the generated loss/prediction curves.
Example applications include:
- Trend Following: Using the classification labels to align with the current momentum.
- Mean Reversion: Observing when price deviates significantly from the scaled loss curve.
- Multi-Timeframe Analysis: Adjusting the "Resolution" setting to see predictions from higher timeframes on a lower timeframe chart.
Note: This indicator features repainting signals as it recalculates based on iterative training data.
Details
The script implements Logistic Regression, which, despite its name, is a classification algorithm rather than a standard regression tool. While linear regression fits a straight line to predict continuous values, Logistic Regression fits a Sigmoid (S-shaped) curve to separate data points into discrete classes.
The core execution involves a logistic_regression function that updates weights ($w$) via gradient descent over a user-defined number of iterations. The model seeks to minimize the log-loss between the prediction and the target data. In this implementation, the algorithm uses price data or temporal data to generate a probability of occurrence for a price move, which is then scaled using a Minimax algorithm to fit the chart's price scale.
Settings
Main Settings
- Price Type: Selects the source data for calculations (e.g., Close, HL2, OHLC4).
- Resolution: Determines the timeframe from which the data is pulled for the model.
- Lookback Window Size: Sets the window for the dot product and summation operations within the algorithm.
- Normalization Lookback: Defines the period used for the Minimax scaling of the output curves.
- Learning Rate: Controls the step size of the gradient descent during weight updates.
- Training Iterations: The number of times the algorithm loops to minimize loss and optimize weights.
Filters and Display
- Filter Signals by: Allows filtering signals based on Volatility (ATR), Volume (RSI of Volume), or both.
- Show Loss & Prediction Curves?: Toggles the visibility of the internal ML calculation lines.
- Optional Calculation?: Swaps the input variables for the logistic function (using time as a base).
- Use Price Data for Signal Generation?: Determines if signals are triggered by price crossing the curves or by curve crossovers.
- Holding Period: Sets the number of bars to wait before displaying an exit signal.
- Lot Size: Used for the internal backtesting statistics displayed in the info box.
- Show Info?: Displays a dashboard with cumulative return, trade count, and win rate.
FAQ
How do I use this indicator for different assets?
Some assets, such as BTCUSD or USDJPY, may require a lower "Normalization Lookback" (around 2–5) and enabling "Use Price Data for Signal Generation" for better alignment.
Why do the signals change after the bar closes?
This indicator uses an iterative machine learning process that recalculates on every bar, which leads to repainting. It is best used for historical analysis or with the understanding that signals may shift during live calculation.
How can I access the Machine Learning: Logistic Regression indicator?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
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.

