OPEN-SOURCE SCRIPT

Dynamic Timeframe Trend Analyzer

140
Purpose and Core Logic
This indicator automatically adjusts its calculations based on the current chart’s timeframe, allowing traders to analyze trends, momentum, and mean reversion opportunities without manually changing indicator settings for each interval. It detects potential long or short setups by combining several techniques:


Dynamic Timeframe Factor

The script compares the current timeframe to a base (e.g., 5 minutes) and calculates a “factor” to scale certain parameters, such as EMA lengths or ATR settings. This reduces the need to reconfigure indicators when switching timeframes.

Regime Detection


It uses ADX (Average Directional Index) to classify the market as strongly trending, moderately trending, choppy, or in a potential mean-reversion phase.
RSI (Relative Strength Index) is also monitored for extreme levels (e.g., overbought/oversold) to detect potential reversal zones.
Volume is compared to a moving average to confirm or refute volatility conditions.

Trend & Mean Reversion Signals

EMA Alignment (8/21/55) helps identify bullish or bearish phases (strong bull if all EMAs align upward, strong bear if aligned downward).
For mean reversion opportunities, the script checks if ADX is sufficiently low (indicating weak or no trend) while price and RSI are at extreme levels—suggesting a snapback or countertrend move may occur.


Dynamic Stop Loss & Take Profit


Uses ATR (Average True Range) to set initial stop-loss (SL) and take-profit (TP) levels, then adjusts these levels further with “regime multipliers” based on whether the market is in a high-volatility trend or a quieter mean-reversion environment.
This approach aims to place stops and targets in a more adaptive way, reflecting current market conditions rather than a one-size-fits-all approach.

Visual Aids

Color-coded chart backgrounds (e.g., greenish for bullish trend, red for bearish, yellow/orange for mean reversion).
Triangles to show recent bullish/bearish signals.
A status table in the top-right corner (optional) displaying key metrics like ADX, RSI, dynamic thresholds, current SL/TP levels, and whether a stop loss has been hit.

How It Works Internally

ADX & Dynamic Thresholds:
A moving average (adx_mean) and standard deviation (adx_std) of the ADX are calculated over a lookback period to define “strong” vs. “weak” ADX thresholds.
This allows the script to adapt to changing volatility and trend strength in different markets or timeframes.

Mean Reversion Criteria:

The indicator checks if price deviates significantly from its own moving average, alongside RSI extremes. If ADX suggests no strong directional push (i.e., the market is “quiet”), it may classify conditions as mean-reverting.

Regime Multipliers:

Once the script identifies the market regime (e.g., strong uptrend, choppy, mean reversion), it applies different multipliers to the user-defined base values for stop-loss and take-profit. For instance, strong trending conditions might allow for wider stops to handle volatility, while mean reversion signals use tighter exits to capture quick reversals.

How to Use It

Timeframe Agnostic
Simply apply it to any timeframe (from 1-minute up to daily or weekly). The “Dynamic Timeframe Factor” will scale the indicator parameters automatically.

Look for Buy/Sell Triangles

When the script detects a valid bullish trend shift or a mean-reversion long setup, it plots a green triangle under the price bar. Conversely, it plots a red triangle above the price bar for bearish or mean-reversion short setups.

Check the Status Table
The table in the top-right corner summarizes the indicator’s current readings: ADX, RSI, volume trends, and the market regime classification.
The table also shows if a stop loss has been hit (SL Hit) and displays recommended SL/TP levels if a signal is active.

Stop Loss & Take Profit
The script plots lines for SL and TP on your chart after a new signal. These lines are automatically adjusted based on ATR, volume conditions, and ADX-derived multipliers.

Mean Reversion vs. Trend-Following
If you see a “Mean Rev” state in the table or the background turning yellow/orange, it suggests potential countertrend trades. Conversely, “STRONG BULL” or “STRONG BEAR” states favor momentum-based entries in the prevailing direction.

Originality & Benefits

Adaptive to Timeframe: Many indicators require reconfiguration when switching from short to long timeframes. This script automates that process using the “timeframe factor” logic.
Regime-Based SL/TP: Instead of fixed risk parameters, the script dynamically tunes stop and target levels depending on whether the market is trending or reverting.
Comprehensive Market View: It combines multiple factors—ADX, RSI, volume, moving averages, and volatility measurements—into a single, integrated framework that categorizes the market regime in real time.

Best Practices & Notes

Timeframes: It typically performs well on intraday timeframes (5m, 15m, 1H) but can also be used for swing trading on 4H or Daily charts.
Settings: The defaults are a good starting point, but you can adjust the base ATR multiplier or ADX lookbacks if you prefer a different balance between sensitivity and stability.
Risk Management: This indicator is not a guarantee of any specific results. Always use proper risk management (position sizing, stop-losses, and diversified strategies).
Alert Conditions: Built-in alert conditions can notify you when a new long or short signal appears, or when a stop loss is triggered.

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.