The Dynamic Trend Indicator (DTI) with VWAP Filter is a trend-following indicator.
It aims to identify and follow market trends while minimizing false signals in choppy or ranging markets.
The DTI combines a dynamically adjusted Exponential Moving Average (EMA) with a daily Volume Weighted Average Price (VWAP) confirmation filter and a cooldown mechanism to enhance signal reliability. This indicator is particularly useful for traders on intraday timeframes (e.g., 4-hour charts) who want to align their trades with the broader daily trend while avoiding whipsaws.
Key Features:
Dynamic Trend Line:
The core of the DTI is a trend line calculated using a custom EMA that adjusts its period dynamically based on market conditions.
The period of the EMA is determined by a combination of volatility (measured via ATR) and trend strength (measured via price momentum). In strong trends, the period shortens for faster responsiveness; in weak or ranging markets, it lengthens to reduce noise.
An optional smoothing EMA can be applied to the dynamic trend line to further reduce noise, with a user-defined smoothing length.
Daily VWAP Confirmation Filter:
A daily VWAP is calculated to provide a higher-timeframe trend bias. VWAP represents the average price paid for an asset during the day, weighted by volume, and is often used as a benchmark by institutional traders.
Buy signals are only generated when the price is above the daily VWAP (indicating a bullish daily bias), and sell signals are only generated when the price is below the VWAP (indicating a bearish daily bias).
The VWAP resets at the start of each day, ensuring it reflects the current day’s trading activity.
Cooldown Mechanism:
To prevent rapid signal reversals (whipsaws), the indicator includes a cooldown period between signals. After a buy or sell signal is generated, no new signals can be generated for a user-defined number of bars (default: 5 bars).
This helps filter out noise in choppy markets, ensuring signals are spaced out and more likely to align with significant trend changes.
Visual Elements:
Trend Line: Plotted on the chart, colored green when the price is above (uptrend) and red when below (downtrend). A gray color indicates a neutral trend.
Buy/Sell Signals: Displayed as green triangles below the bar for buy signals and red triangles above the bar for sell signals.
Background Coloring: The chart background is shaded green during uptrends and red during downtrends, providing a quick visual cue of the trend direction.
Daily VWAP Line: Optionally plotted as a purple step line, allowing traders to see the VWAP level and its relationship to the price.
Alerts:
The indicator includes built-in alerts for buy and sell signals, triggered when the price crosses the trend line and satisfies the VWAP filter and cooldown conditions.
Alert messages specify whether the signal is a buy or sell and confirm that the VWAP condition was met (e.g., "DTI Buy Signal: Price crossed above trend line and VWAP").
Input Parameters
Base Length (default: 14): The base period for calculating volatility and trend strength, used to adjust the dynamic EMA period.
Volatility Multiplier (default: 1.5): Adjusts the sensitivity of the dynamic period to market volatility (via ATR).
Trend Threshold (default: 0.5): Controls the sensitivity of the dynamic period to trend strength (via price momentum).
Use Smoothing (default: true): Enables/disables smoothing of the trend line with an additional EMA.
Smoothing Length (default: 3): The period for the smoothing EMA, if enabled.
Cooldown Bars (default: 5): The minimum number of bars between consecutive signals, reducing signal frequency in choppy markets.
Show Daily VWAP (default: true): Toggles the display of the daily VWAP line on the chart.
How It Works
Dynamic Trend Line Calculation:
Volatility is measured using the Average True Range (ATR) over the base length, scaled by the volatility multiplier.
Trend strength is calculated as the absolute price momentum (change in price over the base length) divided by the volatility factor.
The dynamic EMA period is adjusted based on the trend strength: stronger trends result in a shorter period (faster response), while weaker trends result in a longer period (more stability). The period is constrained between 5 and 50 to avoid extreme values.
A custom EMA function is used to handle the dynamic period, as Pine Script’s built-in ta.ema() requires a fixed length. The trend line is optionally smoothed with a secondary EMA.
Signal Generation:
A buy signal is generated when the price crosses above the trend line, the price is above the daily VWAP, and the cooldown period has elapsed.
A sell signal is generated when the price crosses below the trend line, the price is below the daily VWAP, and the cooldown period has elapsed.
The cooldown mechanism ensures that signals are not generated too frequently, reducing false signals in ranging markets.
Daily VWAP Calculation:
The VWAP is calculated by accumulating the price-volume product (close * volume) and total volume for the day, resetting at the start of each new day.
The VWAP is then computed as the cumulative price-volume divided by the cumulative volume, providing a volume-weighted average price for the day.
Usage
Timeframe: Best suited for intraday timeframes (e.g., 1-hour, 4-hour) where the daily VWAP provides a higher-timeframe trend bias. It can also be used on daily charts with adjustments to the cooldown period.
Markets: Works well in trending markets (e.g., forex, crypto, stocks) where the dynamic trend line can capture sustained price movements. The VWAP filter helps align signals with the daily trend, making it effective for assets with clear daily biases.
Trading Strategy:
Buy: Enter a long position when a green triangle (buy signal) appears, indicating the price has crossed above the trend line and is above the daily VWAP.
Sell: Enter a short position (or exit a long) when a red triangle (sell signal) appears, indicating the price has crossed below the trend line and is below the daily VWAP.
Use the trend line and VWAP as dynamic support/resistance levels to set stop-losses or take-profit targets.
Backtesting: Use TradingView’s strategy tester to evaluate the indicator’s performance on your chosen market and timeframe, adjusting parameters like cooldown_bars and volatility_mult to optimize for profitability.
Example
On a 4-hour SOLUSDT chart, the DTI with VWAP Filter might show:
An uptrend with the price above the green trend line and above the daily VWAP, generating buy signals as the price continues to rise.
A downtrend where the price falls below the red trend line and the daily VWAP, generating sell signals that align with the bearish daily bias.
During choppy periods, the cooldown mechanism and VWAP filter reduce false signals, ensuring trades are taken only when the price aligns with the daily trend.
Limitations
Lagging Nature: Like all trend-following indicators, the DTI may lag during sharp price reversals, as the dynamic EMA needs time to adjust.
Ranging Markets: While the VWAP filter and cooldown mechanism reduce whipsaws, the indicator may still generate some false signals in strongly ranging markets. Combining it with a trend strength filter (e.g., ADX) can help.
VWAP Dependency: The effectiveness of the VWAP filter depends on the market’s respect for the daily VWAP as a support/resistance level. In markets with low volume or erratic price action, the VWAP may be less reliable.
Potential Improvements
VWAP Buffer: Add a percentage buffer around the VWAP (e.g., require the price to be 1% above/below) to further reduce noise.
Multi-Timeframe VWAP: Incorporate a weekly VWAP for additional trend confirmation on longer timeframes.
Trend Strength Filter: Add an ADX filter to ensure signals are generated only during strong trends (e.g., ADX > 25).