INVITE-ONLY SCRIPT

Median EMA IQR Bands | Oquant

96
Overview
The Median EMA IQR Bands is a indicator designed to provide a robust trend-following framework combined with volatility-based bands. It overlays a smoothed central line derived from exponential moving averages (EMAs) and interquartile range (IQR) bands on price charts, helping traders identify potential entry and exit points for long or short positions. Beyond visualization, it incorporates a built-in strategy simulator that calculates key performance metrics, equity curves, and comparisons to a simple buy-and-hold approach. This tool is ideal for quantifying the effectiveness of a median-filtered EMA strategy with IQR-adjusted bands(remember past performance doesn’t guarantee future results), offering insights into risk-adjusted returns without requiring external backtesting software.

Key Factors/Components
Median EMA Line: A core smoothing mechanism that filters out noise from traditional EMAs by applying a median calculation over a series of EMA values, creating a more stable and outlier resistant trend indicator.
IQR Bands: Dynamic upper and lower bands based on the interquartile range of price data, multiplied by a user-defined factor, to capture volatility and define breakout thresholds.
Position Signals: Simple rules for generating long (bullish) or short (bearish) allocations based on price crossings of the bands, with options to enable/disable longs or shorts (defaulting to cash when disabled).
Performance Metrics: Comprehensive calculations including maximum drawdown (overall and intra-trade), Sharpe ratio, Sortino ratio, Omega ratio, percent profitable trades, profit factor, total trades, and net profit.
Equity Curve and Visualization: Optional plotting of the strategy's equity curve, colored bars/candles for signals, and filled bands for better readability.
Tables: Two optional tables displaying indicator metrics and buy-and-hold benchmarks for quick at-a-glance analysis.
Date Filter: A start date input to focus analysis on specific historical periods, ensuring relevance to user-defined backtests.

How It Works
The indicator starts by computing a smoothed central line that combines EMA smoothing with median filtering to reduce sensitivity to outliers and possibly provide a more reliable trend baseline than just using ema. Volatility bands are then constructed around this line using the interquartile range of recent price data, scaled by a multiplier to adjust band width—wider bands for more conservative signals, narrower for aggressive ones. Price breaking above the upper band triggers a long position (if enabled), while dropping below the lower band signals a short (if enabled); otherwise, it defaults to a neutral cash position. Behind the scenes, it simulates a strategy equity curve by applying daily returns based on these signals, while tracking risk metrics like drawdowns and ratios that account for both upside performance and downside risk. Tables compare these to a passive buy-and-hold strategy on the underlying asset, helping users evaluate if the active approach adds value. The logic emphasizes trend persistence filtered through statistical robustness.

For Who Is Best/Recommended Use Cases
It's recommended for:
Trend Followers: Those trading cryptocurrencies where median filtering helps in noisy markets by ignoring extreme price spikes.
Risk-Aware Investors: Users focused on risk-adjusted metrics (e.g., Sharpe/Sortino) to compare active strategies against benchmarks, ideal for portfolio managers or algorithmic traders.
Backtesters and Researchers: Anyone testing historical performance on specific assets or time periods, such as post-2018 bull markets, without needing complex coding.

Settings and Def Settings
The indicator offers customizable inputs grouped for ease of use, allowing users to tailor it to their trading style or asset:
Start Date: Defines the beginning of the analysis period (default: "1 Jan 2018") to exclude older data and focus on relevant history.
Source: The price input for calculations (default: close), which can be changed to open, high, low, or other series.
EMA Length: Period for the underlying EMA smoothing (default: 30); longer values create smoother trends but lag more.
Median Length: Window for median filtering on the EMA (default: 20).
Interquartile Range Length: Period for IQR calculation (default: 20); shorter for reactive bands, longer for stable ones.
Band Multiplier: Scales the IQR for band width (default: 1.2); higher values widen bands for fewer signals, lower for more frequent trades.
Allow Long Trades: Enables long positions (default: true); if false, longs default to cash.
Allow Shorts: Enables short positions (default: false); if false, shorts default to cash.
Show Indicator Metrics Table: Displays the performance table (default: true).
Show Buy&Hold Table: Shows benchmark metrics (default: true).
Plot Equity Curve: Overlays the strategy's equity line (default: false) for visual backtesting.

Conclusion
The Median EMA IQR Bands stands out as a comprehensive tool that merges visual trend analysis with quantitative strategy evaluation, empowering traders to make data-driven decisions. By incorporating median filtering and IQR for robustness, it offers an possible edge in identifying sustainable trends while highlighting risks through advanced metrics(remember past performance doesn’t guarantee future results). Whether for live trading signals or historical analysis, it simplifies complex concepts into an accessible package.

⚠️ Disclaimer: This indicator is intended for educational and informational purposes only. Trading/investing involves risk, and past performance does not guarantee future results. Always test and evaluate indicators/strategies before applying them in live markets. Use at your own risk.

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.