Linear Regression with MA filter

229
Linear Regression With MA Filter (LRMF)

INTRODUCTION

My first indicator the LRMF(Linear Regression With MA Filter) is a trend-following indicator that compares a linear regression line with a moving average. The regression line reacts from its nature quickly to the current direction of price. The moving average acts as a slower indicator. The relationship between the two gives a clear trend state and signals.

HOW IT WORKS

Linear regression line
On every bar, a least-squares line is fitted through the last N values of the selected source. The indicator plots the end point of that line. Because it uses the end point and not the average of the window, it carries the slope of recent price action and lags much less than a simple moving average of the same length.

Moving average
A selectable moving average of the chosen source acts as the slower baseline.
Options:
SMA
RMA
WMA
VWMA
TEMA
DEMA
HMA
ALMA
EMA (Default)

Trend state and signals
- Regression line above the MA: bullish state, the line turns green
- Regression line below the MA: bearish state, the line turns red
- Crossover of the regression line over the MA: Long triangle below the bar
- Crossunder of the regression line under the MA: Short triangle above the bar

The color shows the current state. The triangles mark the single bar where the state changes.

SETTINGS

Linear Regression Settings
- Source: price source for the regression (default: close)
- Length: number of bars used in the fit (default: 45). Shorter is faster and noisier, longer is
smoother and slower.

MA Settings
- Source: price source for the moving average (default: close)
- Length: MA period (default: 35)
- MA type: SMA, RMA, WMA, VWMA, TEMA, DEMA, HMA, ALMA, EMA (default: EMA)

The MA type changes how quickly the baseline reacts. Fast types like HMA, TEMA and DEMA bring the baseline closer to the regression line, which gives more and earlier crossovers. Slower types like SMA and RMA give fewer, more filtered signals.

HOW TO USE

- Use the line color as a trend filter, and the triangles as entry or exit events.
- Increase the regression length or use a slower MA type to reduce whipsaws.
- Lower both values or use a faster MA type for a more responsive setup.
- Combine with a volatility or trend-strength filter if you trade ranging markets.

RISKS

- Like any trendfollowing tool, SLR can whipsaw in sideways markets.
- The regression end point can overshoot at sharp reversals.
- Signals on the live bar can change until the bar closes. Treat a signal as confirmed only at bar
close.
- Defaults are a starting point, not an optimized set. Test settings on your own ticker and
timeframe.

DISCLAIMER

This script is for educational and informational purposes only and is not financial advice. Past performance does not guarantee future results. Always do your own research and manage your risk.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.