Nadaraya-Watson Envelope EA: Comprehensive User Guide, Backtest Results, and Optimized Set Files

Nadaraya-Watson Envelope EA: Comprehensive User Guide, Backtest Results, and Optimized Set Files

21 November 2024, 15:24
Biswarup Banerjee
0
2 370

Complete User Documentation — MT4 & MT5

1. OVERVIEW

The Nadaraya Watson Envelope Strategy Multicurrency EA automates trading across multiple pairs from a single chart using the Nadaraya Watson non-parametric kernel regression method. Instead of just scanning for signals, this EA places and manages trades based on configurable entry/exit strategies, trend filters, and risk controls — including ATR-based trailing stops and grid recovery. It solves the problem of manually monitoring multiple currency pairs for envelope-based reversals or breakouts, letting the EA handle execution and position management.

Who Should Use It: Retail forex traders who want a fully automated, multi-pair system based on the Nadaraya Watson envelope, especially those who prefer to fine-tune entry logic and risk management without coding.

Main Benefit: Deploy a single EA on one chart to trade up to 28 currency pairs simultaneously, with customizable entry/exit strategies and built-in safeguards like breakeven, trailing stop, and max loss limits.


2. INPUT PARAMETERS & SETTINGS

This product shares a common set of general input settings with all Multi-Currency Scanner Dashboard products in this series. The following sections are covered in the common guide: General Settings (pairs list, dashboard colors, panel size), Timeframe Signal Settings (individual TF scan per symbol), Timeframe Confluence Settings (multi-TF confluence scan), and Alert Settings (popup, push notification, email). For full details refer to the Common Multi-Currency Scanner Dashboard Settings Guide. The sections below cover only the product-specific inputs unique to this product.

General Settings

These settings control how the EA displays virtual stop-loss/take-profit lines, manages group-level risk, includes swap costs in profit calculations, and records trade history for backtesting analysis.

Setting Name Type Default Value Description Example
Chart lines for virtual SL/TP (never drawn during optimization) bool false When enabled, the EA draws horizontal lines on the chart showing where your hidden stop-loss and take-profit levels sit. Handy for visual confirmation during live trading, but the EA skips drawing them during optimization runs to keep things fast. true — enable during live trading to see your virtual SL/TP levels on the chart.
Group Stoploss Amount double 0 Sets a maximum total loss in account currency for all open trades combined. Once the cumulative loss hits this threshold, the EA closes all positions. Useful for capping drawdown across a basket of pairs. 50 — close all trades if total loss across the group reaches $50.
Include Swap charges in Profit bool true When true, the EA factors overnight swap fees into the profit calculation for breakeven and trailing stop decisions. Set to false if you want to ignore swap costs and only consider pure price movement. false — useful for short-term scalping where swaps are negligible.
Enable history for backtests or optimization bool false When enabled, the EA records trade history and performance metrics during backtests or optimization runs. Leave it off for faster testing, but turn it on when you need detailed results for analysis. true — enable during optimization to capture trade logs for later review.

Atr Trailingstop Settings

These settings configure an adaptive trailing stop based on the Average True Range indicator, allowing the stop distance to adjust automatically to market volatility.

Setting Name Type Default Value Description Example
Use ATR Trailing Stop bool false Enables a trailing stop that moves with price based on ATR values. Unlike a fixed pip trail, this adapts to changing volatility — wider stops in volatile markets, tighter in calm ones. Disable to use the standard breakeven or fixed trailing stop. true — enable for volatile pairs like GBP/JPY where fixed stops get hit too often.
ATR Timeframe ENUM PERIOD_CURRENT Selects the timeframe used to calculate the ATR value for the trailing stop. Using a higher timeframe like H4 gives a smoother, more stable ATR, while M15 reacts faster to short-term volatility changes. PERIOD_H1 — use hourly ATR for a balance between responsiveness and stability.
ATR Period int 14 The number of bars used to calculate the ATR value. A shorter period like 7 makes the trailing stop more sensitive to recent volatility spikes, while 21 smooths out noise. Default 14 works for most swing trading styles. 10 — tighten the ATR calculation for faster reaction to volatility changes.
Activation (ATR multiplier) double 2.0 The profit threshold (in ATR units) that must be reached before the trailing stop kicks in. A value of 2.0 means the trade needs 2x the current ATR in profit before trailing begins. Prevents premature trailing on small moves. 3.0 — require more profit before activating the trail, useful for trend-following strategies.
Trail distance (ATR multiplier) double 1.0 Sets how far the trailing stop sits behind the current price, measured in ATR units. A value of 1.0 places the stop 1 ATR away from price. Tighter values risk early exit, wider values give more breathing room. 1.5 — give the trade more room to breathe in choppy markets.
Trail increment (ATR multiplier) double 0.5 Controls how much the stop moves each time price advances in your favor, measured in ATR units. A value of 0.5 means the stop moves up by 0.5 ATR for every 1 ATR of favorable price movement. Higher values lock in profit faster. 1.0 — lock in profit more aggressively as price moves in your favor.

Grid Settings

These settings manage a grid recovery feature that aims to bring the entire basket of trades back to breakeven or profit after a series of losing positions.

Setting Name Type Default Value Description Example
Recover profit from all grid trades bool false When enabled, the EA calculates the total profit or loss from all open trades in the grid and attempts to close the entire basket when the net profit reaches a target. Useful for recovering from multiple losing entries in a grid strategy. true — enable for grid-based recovery where you want the whole basket to close at breakeven or profit.

Safeguard Settings

These settings provide protective limits to prevent excessive losses and ensure the EA only trades under favorable conditions, with some options specifically for backtesting validation.

Setting Name Type Default Value Description Example
Max Loss from initial balance [0: disable] double 0.0 Sets a maximum drawdown limit as a percentage of the initial account balance. If the account drops below this threshold, the EA stops opening new trades. Set to 0 to disable this safety net entirely. 15 — stop trading if the account loses 15% from the starting balance.
Minimum Profit Percent [backtesting only] [0: disable] double 0 During backtesting, this setting filters out runs where the total profit doesn't reach the specified percentage. Helps you quickly discard underperforming parameter sets in optimization. Disabled by default. 5 — ignore any backtest result with less than 5% total profit.
Minimum Trades [backtesting only] [0: disable] double 0 In backtesting, this setting rejects any optimization result that didn't execute at least this many trades. Useful for avoiding overfitted results with very few trades that look good by luck. 20 — only consider results with 20 or more trades for statistical significance.
Max inactive days [backtesting only] [0: disable] int 0 During backtesting, this setting flags periods where the EA didn't open any trades for more than the specified number of consecutive days. Helps identify parameter sets that go dormant for too long. 30 — flag any period where the EA is inactive for more than 30 consecutive days.

Nadaraya Settings

These settings define the core parameters of the Nadaraya Watson envelope calculation, including lookback period, bandwidth, multiplier, smoothing, and the entry/exit strategy logic.

Setting Name Type Default Value Description Example
Bars Count int 100 The number of historical bars used to calculate the Nadaraya Watson envelope. A higher count smooths the envelope but makes it less responsive to recent price changes. Lower values react faster but may produce more false signals. 3. HOW IT WORKS

Core Calculation & Logic

The EA runs a continuous scan across every symbol you list in the Symbols input, calculating the Nadaraya Watson Envelope on each one independently. At its heart, the indicator uses a kernel regression — a non-parametric smoothing technique — to estimate a weighted average of recent prices, with the Bandwidth controlling how many bars influence each point. The envelope is then drawn at a distance determined by the Multiplier times a local volatility estimate. What you end up with is a dynamic support/resistance channel that adapts to market noise better than a simple moving average.

The EA checks every tick (or every new bar, depending on your timeframe) whether price has touched or crossed these bands. When it detects a qualifying event — a bounce off the lower band in reversal mode, or a break above it in momentum mode — it fires a signal for that symbol. It then applies your risk rules (lot size, stop-loss, take-profit) and opens a market order. Because the scan is multi-symbol, a single chart can monitor the entire forex watchlist without you juggling multiple windows.

Entry Strategies Explained

ENTRY_STRATEGY1 — Reversal Bounce

BUY Signal: Price touches or crosses below the lower envelope line, then closes back above it. The EA interprets this as a rejection of lower prices and a potential reversal upward.

SELL Signal: Price touches or crosses above the upper envelope line, then closes back below it. This flags a rejection at resistance and a likely move lower.

Best For: Range-bound or mean-reverting markets where price oscillates between well-defined bands. Works well on H1–H4 when volatility is moderate.

ENTRY_STRATEGY2 — Momentum Breakout

BUY Signal: Price closes above the upper envelope line. The EA treats this as a breakout of the channel, expecting the trend to continue upward.

SELL Signal: Price closes below the lower envelope line. This signals a breakdown and a bearish continuation.

Best For: Trending markets with strong directional moves. Avoid using it during low-volatility sessions or when major news is pending — false breakouts are common then.

Step-by-Step Workflow

Step 1: Attach the EA to a single chart. Any timeframe works — the EA scans all symbols you specify, not just the chart symbol. Use a 1H or 4H chart for a good balance of speed and signal quality.

Step 2: Configure your symbol list. In the Symbols input, enter comma-separated pairs like EURUSD,GBPUSD,USDCHF,USDJPY,AUDUSD . The EA will scan each one in sequence.

Step 3: Set your entry strategy. Choose ENTRY_STRATEGY1 if you expect reversals, or ENTRY_STRATEGY2 if you expect breakouts. Start with Strategy 1 on a demo account to see how the envelope behaves on your pairs.

Step 4: Define risk parameters. Set Lot Size to 0.01 for testing. Choose a stop-loss and take-profit mode — Pips is the simplest for beginners. Enter STOPLOSS = 30 and TAKEPROFIT = 60 for a 1:2 risk-reward ratio.

Step 5: Enable or disable repainting. If you want signals that won't disappear on historical bars, set Repainting Smoothing = false. For live trading where you only care about the current bar, leaving it true gives a smoother envelope.

Step 6: Run on a demo account first. Let it trade for at least 50–100 closed trades before going live. Pay attention to how often each strategy triggers — if you see too many signals in quiet markets, increase the Bandwidth or Multiplier.


4. RISK MANAGEMENT FEATURES

The EA includes several built-in risk controls that let you protect your account without needing external scripts or manual oversight.

Feature Description
Hidden Stop-Loss & Take-Profit When HIDDEN_SL_TP = true, the EA places SL/TP levels that are not visible to your broker — useful if you trade with a dealing desk that might widen spreads on visible stops. The levels are still enforced by the EA on every tick. You can optionally show them as chart lines by enabling SHOW_HIDDEN_SL_TP_LINES, but note that these lines are never drawn during optimization to avoid clutter.
Multiple SL/TP Calculation Modes Choose from six modes: Pips (fixed distance), Amount (fixed monetary loss), Percent (percentage of account), Group Amount/Percent (aggregate across all open positions from this EA), or No SL/TP. The group modes are especially useful if you run multiple pairs — they cap total drawdown rather than per-position risk.
Group Stop-Loss & Take-Profit When using GROUP_AMOUNT or GROUP_PERCENT, the EA tracks the combined profit/loss of all positions opened by this instance. If the group loss exceeds your threshold, all positions are closed. This prevents a single bad pair from dragging down your whole portfolio.
Fixed Lot Size with Optional Scaling The Lot Size input lets you set a fixed volume for every trade. For more advanced risk management, you can later integrate a money-management function (not included by default) that scales lot size based on account equity or volatility.

5. IMPORTANT NOTES & WARNINGS

Known Limitations

Issue Explanation
Repainting with Smoothing Enabled When Repainting Smoothing = true, the envelope values can change on historical bars as new price data comes in. This means a signal that appeared on a completed bar might disappear later. For backtesting or strict historical analysis, set this to false.
Multi-Symbol Scanning Overhead Scanning 10+ symbols on every tick can increase CPU usage, especially on older machines or VPS with limited resources. If you notice lag, reduce the symbol list or increase the minimum time between scans by using a higher timeframe chart.
No Built-In News Filter The EA does not automatically pause trading during high-impact news events. If you trade news-sensitive pairs like EURUSD or GBPUSD, consider using an external calendar filter or manually disabling the EA during major releases.
Hidden SL/TP Not Supported by All Brokers Some brokers reject orders with hidden stop-loss levels. If you get errors like "Invalid stops" when HIDDEN_SL_TP = true, switch to false and use visible stops instead.

Settings Beginners Should NOT Change

Setting Why to Leave Default
Bars Count The default of 500 bars gives a good balance between responsiveness and stability. Dropping it too low (e.g., 50) makes the envelope jumpy and prone to false signals. Increasing it above 1000 slows calculation without much benefit.
Bandwidth At 8.0, the envelope adapts well to typical forex volatility. Lower values (e.g., 3.0) cause the envelope to hug price too tightly, generating excessive signals. Higher values (e.g., 15.0) make it too loose, missing many reversals.
Multiplier The default of 3.0 sets the envelope width at three times the local volatility estimate. Changing this without understanding the math can lead to envelopes that are either too wide (few signals) or too narrow (many false signals).
Entry Strategy Strategy 1 (reversal) is the safer starting point because it waits for price to reject the band. Strategy 2 (breakout) is more aggressive and prone to whipsaws in choppy markets. Stick with Strategy 1 until you're confident in reading the envelope behavior.

Dashboard Usage Tips

  1. Start with 3–5 pairs: Don't overload the EA with 20 pairs right away. Pick the major ones (EURUSD, GBPUSD, USDJPY, AUDUSD, USDCHF) and watch how the envelope behaves on each before expanding.
  2. Match your strategy to the session: Reversal strategy works better during London and New York overlap when ranges are tighter. Breakout strategy can be used during Asian session if you see clear trends.
  3. Use the chart lines to verify signals: Enable SHOW_HIDDEN_SL_TP_LINES = true during demo testing so you can see where the EA would place stops. This helps you catch any logic errors before going live.
  4. Monitor the EA's journal output: The EA prints signal details to the Experts tab. If you see repeated "no signal" messages for a pair, check that the symbol name is correct and that the market is open.
  5. Don't mix strategies on the same chart: The EA uses one entry strategy per instance. If you want to test both strategies, run two separate charts with different symbol lists.
  6. Backtest with "Every tick" mode: For the most accurate results, use every-tick modeling in the Strategy Tester. Open-price-only mode will miss the intra-bar touches that trigger reversal signals.

Quick Start Guide

Follow these steps to get started in under 5 minutes:

  1. Download and install: Purchase the EA from the MQL5 Market, then download it from the "My Products" tab in MetaTrader. Drag it onto any chart — the chart symbol doesn't matter, as the EA scans your custom list.
  2. Set your symbol list: In the EA's input dialog, find the Symbols field and enter EURUSD,GBPUSD,USDJPY . Make sure there are no spaces after commas.
  3. Choose your entry strategy: Leave Entry Strategy at ENTRY_STRATEGY1 (reversal) for your first test. This is the more forgiving option.
  4. Configure risk: Set Lot Size = 0.01, SLTP_MODE = Pips, STOPLOSS = 30, TAKEPROFIT = 60. This gives you a 1:2 risk-reward ratio with minimal capital exposure.
  5. Disable repainting for testing: Set Repainting Smoothing = false so that signals on historical bars don't change. You can re-enable it later for live trading if you prefer a smoother envelope.
  6. Run on demo for 50 trades: Let the EA trade on a demo account for at least 50 closed trades. Check the trade journal for any errors — common ones include "invalid symbol" or "market closed."
  7. Review and adjust: After 50 trades, look at the win rate and average profit per trade. If you're getting too many small losses, try increasing Bandwidth to 10.0 or switching to ENTRY_STRATEGY2.
  8. Go live with caution: Once you're satisfied with demo performance, attach the EA to a live chart with the same settings. Start with the smallest lot size your broker allows and monitor it daily for the first week.


Installation Guide for MQL Products | Updating Purchased MQL Products on MT4/MT5 | General Troubleshooting Guide | Backtest and Set Files

Check all my products: https://www.mql5.com/en/users/biswait50/seller

Contact me for support: https://www.mql5.com/en/users/biswait50