OPEN-SOURCE SCRIPT

Kernel Regression Envelope with SMI Oscillator

This script combines kernel regression, envelope calculations, and the Stochastic Momentum Index (SMI) to generate trading signals. It uses a Nadaraya-Watson estimator with a Rational Quadratic kernel to model price trends, constructs an envelope around the estimated trend using Average True Range (ATR), and utilizes the SMI to identify potential overbought/oversold conditions for entry and exit points.

Strategy Logic:

Kernel Regression:

The script employs the Nadaraya-Watson estimator, a non-parametric regression technique, to estimate the underlying trend of the price.
It utilizes the Rational Quadratic kernel function, which allows for flexible weighting of past data points based on their distance in time.
The h parameter controls the lookback window (number of bars used for estimation), alpha determines the relative weighting of time frames, and x_0 sets the starting bar for regression.

Envelope Calculation:

An envelope is created around the estimated trend (yhat_close) to define potential support and resistance levels.
The envelope's boundaries are calculated using a multiple of the ATR, which measures market volatility.
nearFactor and farFactor control the width of the envelope, creating near and far boundaries.

Smoothing:

The script includes an option to smooth the SMA output using various moving average types (SMA, EMA, SMMA, WMA, VWMA).
This smoothing helps to filter out noise and provide a clearer trend signal.

Stochastic Momentum Index (SMI):

The SMI is used as a momentum oscillator to identify potential overbought and oversold conditions.
It measures the distance of the current close relative to the midpoint of the high-low range over a specified period.
Crossovers between the SMI and its EMA signal potential trend reversals.

Entry and Exit Conditions:

Long Entry: A long position is entered when the smoothing line is below the lower far boundary of the envelope, the SMI crosses above its EMA, and the SMI is below -50 (indicating oversold conditions).
Short Entry: A short position is entered when the smoothing line is above the upper far boundary of the envelope, the SMI crosses below its EMA, and the SMI is above 50 (indicating overbought conditions).
Long Exit: A long position is closed when the price crosses above the upper far boundary.
Short Exit: A short position is closed when the price crosses below the lower far boundary.
Stop Loss: A stop loss is set at a user-defined number of ticks below the entry price for long positions and above the entry price for short positions.

Customization:

The script offers extensive customization options, including:

Kernel parameters (lookback window, relative weighting, starting bar)
Envelope parameters (ATR length, near/far factors)
Smoothing method and length
SMI parameters (lengths for %K, %D, and EMA)
Timeframe for SMI calculation
Colors for plots and fills
Stop loss level


Disclaimer:
This script is for educational purposes and should not be considered financial advice. Backtesting and thorough analysis are recommended before using this strategy in live trading. The effectiveness of the strategy may vary depending on market conditions and the chosen parameters.
ATRenvelopeskernelregressionmomentumstrategyMoving AveragesnadarayawatsonOscillatorsSMIVolatility

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明