Nadaraya-Watson Envelope for MT4 and MT5

Nadaraya-Watson Envelope for MT4 and MT5

16 December 2025, 22:02
Abir Pathak
0
36

About:

The Nadaraya-Watson Envelope is a sophisticated yet practical technical indicator that helps traders identify overbought and oversold conditions using advanced kernel regression methods.

Key Features

  • ATR-Based Bands: Three upper and three lower bands provide graduated overbought/oversold zones
  • Logarithmic Scale Calculation
  • Center Line - bullish (teal) or bearish (red)

What is the Nadaraya-Watson Envelope?

Think of an envelope as a channel around price action. Traditional envelopes use simple moving averages with fixed percentage bands. The Nadaraya-Watson Envelope takes this concept further by using kernel regression - a smart mathematical approach that weighs recent price data more heavily while still considering historical context.

Why Kernel Regression?

Kernel regression doesn't assume price moves in straight lines or follows specific patterns. Instead, it looks at each price point and asks: "How much should nearby prices influence my estimate here?" Closer prices get more weight, distant prices get less. This creates a smoothly adaptive line that responds to market changes without the lag of traditional moving averages.

The Rational Quadratic Kernel used here is particularly powerful. Imagine combining multiple moving averages of different lengths into one intelligent line. That's essentially what this kernel does, giving you both responsiveness and smoothness in a single calculation.


Understanding the Bands

The indicator displays eight distinct lines on your chart:

Upper Bands (Red/Orange)

  • Upper Far - Extreme overbought zone (thin line)
  • Upper Average - Moderate overbought zone (thin line)
  • Upper Near - Initial overbought zone (thickest line)

Center Line

  • Envelope Line - Changes color based on trend direction: Teal = Rising (bullish) and Red = Falling (bearish)

Lower Bands (Teal/Green)

  • Lower Near - Initial oversold zone (thickest line)
  • Lower Average - Moderate oversold zone (thin line)
  • Lower Far - Extreme oversold zone (thinnest line)

The thickness helps you quickly identify which bands are most important for reversal signals.




How to Use This Indicator

If you are trading during sideways market then use the outer bands as your reversal zones. And you can trade in both directions.

But visually check if center line has mostly stayed bullish or bearish, then that will indicate a trending market. In this case only trade on direction of trend.


Long Setups:

  • Price reaches Lower Near or Lower Average band
  • Look for reversal candlestick patterns
  • Entry on confirmation
  • Stop below Lower Far band
  • Target: Upper bands (if longer term trading) or center line (if quick scalping)

Short Setups:

  • Price reaches Upper Near or Upper Average band
  • Look for reversal candlestick patterns
  • Entry on confirmation
  • Stop above Upper Far band
  • Target: Lower bands (if longer term trading) or center line


Settings Guide for Different Trading Styles

Scalping (M1-M5 timeframes)

  • Lookback Window: 5-8
  • Relative Weighting: 3.0-5.0
  • Start Regression at Bar: 15-20
  • ATR Length: 30-40
  • Near ATR Factor: 1.0-1.5
  • Far ATR Factor: 1.5-2.0

Faster response, tighter bands for quick trades.


Day Trading (M15-H1 timeframes)

  • Lookback Window: 8-12
  • Relative Weighting: 8.0 (default)
  • Start Regression at Bar: 25 (default)
  • ATR Length: 60 (default)
  • Near ATR Factor: 1.5 (default)
  • Far ATR Factor: 2.0 (default)

Balanced settings for intraday moves.


Swing Trading (H4-D1 timeframes)

  • Lookback Window: 12-21
  • Relative Weighting: 10.0-15.0
  • Start Regression at Bar: 30-40
  • ATR Length: 80-120
  • Near ATR Factor: 2.0-2.5
  • Far ATR Factor: 3.0-4.0

Wider bands to accommodate larger swings.


High Probability Setups

Price uses Pivot areas and quarter levels as a strong support/resistance levels. These act like magnets for price and it will start ranging near them.

Then either price will breakout or reverse. We are looking for strong reversals near Pivot areas:


  1. Price starts ranging near pivots or quarters.
  2. A strong volume candle reverses and comes inside from the outer bands (Bearish reversal near red upper bands or bullish reversal near lower bands)
  3. Center line breaks with color change = trend confirmation
  4. Price between Near and Average = caution zone

Try to make the entry as close to pivot area as possible. And make sure that your take profit is more than 1.5 to 2 times the stop loss.


Does This Indicator Repaint?

Short Answer: Yes, the indicator repaints within its lookback window (default: 8 bars). This is expected behavior for kernel regression and not a bug.

Traditional Moving Average (No Repaint)

A traditional moving average at Bar 8 calculates the sum of prices from the last 8 bars and divides by 8. Once calculated, this value never changes because it's based on fixed historical data that never gets revisited.

Kernel Regression (Repaints)

The Nadaraya-Watson Envelope at Bar 8 calculates a weighted average where bars 2 through 8 all influence the result. These weights are not equal. Bars closer to Bar 8 have more influence, while distant bars have less influence.

How Kernel Regression Works (Simple Explanation)

Think of kernel regression like smoothing a drawing. You place a magnifying glass (the kernel) at each bar. This glass has a focus point (x_0 = 25) that determines how weights are distributed. Nearby bars get more influence, while distant bars get less influence (controlled by the lookback window of 8 bars). The smoothed line represents the weighted average of all visible bars through this lens.

When new data arrives, the entire dataset shifts. The magnifying glass recalculates weights for all bars within the lookback window, and values within the last 8 bars adjust to maintain smooth regression.

The last 8 bars (your lookback window) will adjust as new bars form. Bars older than 8 bars remain stable and fixed. The envelope "breathes" around recent price action as the market evolves.


How the Calculations Work

The indicator uses the Rational Quadratic Kernel formula to calculate weights for each bar within the lookback window

Here's the simplified process:

  1. Look Back - The indicator examines a specific number of past bars (Lookback Window)
  2. Assign Weights - Each bar gets a weight based on its distance from the current bar
  3. Calculate - These weights multiply the price values and sum up
  4. Result - You get a smoothed estimation of true price value

The magic happens in step 2. The Rational Quadratic Kernel formula assigns weights that decay gracefully with distance. Recent bars matter most, but older bars still contribute. The Relative Weighting parameter controls how quickly this weight decreases.


ATR-Based Band Placement

The bands aren't placed at fixed distances. They adapt to volatility using a custom ATR (Average True Range) calculation.

Custom ATR Process:

  1. Calculate true range for each bar (in log scale)
  2. Apply exponential smoothing over ATR Length periods
  3. Multiply by Near/Far ATR Factors
  4. Add/subtract from center line to create bands

Higher volatility = wider bands. Lower volatility = tighter bands. This automatic adjustment keeps the indicator relevant in all market conditions.


Band Calculations

Once the center estimation line and ATR are calculated:

The Average bands are simply midpoints between Near and Far, creating graduated zones.


Complete Settings Reference



Main Settings

Lookback Window (Default: 8)

  • Controls how many bars influence the estimation
  • Lower = more responsive, potentially noisier
  • Higher = smoother, potentially slower
  • Range: 5-21 for most applications

Relative Weighting (Default: 8.0)

  • The "alpha" parameter controlling curve smoothness
  • Lower = smoother, more stretched curve
  • Higher = wigglier, tighter fit to price
  • Range: 3.0-15.0 for most use cases

Start Regression at Bar (Default: 25)

  • Which bar to use as the reference point for the kernel calculation
  • Affects how far back historical data influences current estimation
  • Higher = more historical context, potentially laggier
  • Range: 15-40 typically

ATR Length (Default: 60)

  • Lookback for volatility calculation
  • Shorter = bands react faster to volatility changes
  • Longer = smoother band adjustment
  • Range: 30-120 depending on timeframe

Near ATR Factor (Default: 1.5)

  • Multiplier for the inner bands
  • Smaller = tighter bands, more signals
  • Larger = wider bands, fewer signals
  • Range: 1.0-2.5 typically

Far ATR Factor (Default: 2.0)

  • Multiplier for the outer bands
  • Usually 0.5-1.0 larger than Near Factor
  • Defines extreme overbought/oversold zones
  • Range: 1.5-4.0 typically


Debug Settings

Useful for troubleshooting or comparing with other platforms:

  • Show Debug Values: Prints raw calculation values
  • Show Debug Buffers: Prints final buffer values
  • Start Debug Bar: Which bar to start debug output
  • Debug For Bars: How many bars to show debug info


Performance Optimization

Refresh After Ticks (Default: 50)

This critical setting controls calculation frequency. The indicator doesn't need to recalculate on every single tick.

  • Default 50 means: recalculate every 50 price updates
  • Lower = more frequent updates, higher CPU usage
  • Higher = less frequent updates, lower CPU usage
  • Set to 0 for new-bar-only updates (most efficient)

For most traders, the default 50 ticks provides excellent responsiveness with minimal performance impact.


Tips for Best Results

  1. Combine with price action - Use candlestick patterns at band touches for confirmation
  2. Watch the center line color - Stay in tune with the dominant trend direction
  3. Multiple timeframe analysis - Check higher timeframe bands for confluence
  4. Volume confirmation - High volume at band extremes increases reversal probability
  5. Avoid chop - In sideways markets, wait for clear band touches before entry
  6. Adjust for your instrument - Volatile pairs need wider bands, stable pairs need tighter bands
  7. Backtest your settings - Spend time finding what works best for your trading instrument and style