OPEN-SOURCE SCRIPT

Contrarian with 5 Levels

1 036
5 Levels application was inspired and adapted from Predictive Ranges indicator developed by Lux Algo. So much credit to their work.

Indicator Description: Contrarian with 5 Levels

Overview
The "Contrarian with 5 Levels" indicator is a powerful tool designed for traders seeking to identify potential reversal points in the market by combining contrarian trading principles with dynamic support and resistance levels. This indicator overlays a Simple Moving Average (SMA) shadow and five adaptive price levels, integrating Institutional Concepts of Structure (ICT) such as Break of Structure (BOS) and Market Structure Shift (MSS) to provide clear buy and sell signals. It is ideal for traders looking to capitalize on overextended price movements, particularly on the daily timeframe, though it is adaptable to other timeframes with proper testing.

How It Works
The indicator operates on two core components:
Contrarian SMA Shadow: A shaded region between the SMA of highs and lows (default length: 100) acts as a dynamic zone to identify overbought or oversold conditions. When the price moves significantly outside this shadow, it signals potential exhaustion, aligning with contrarian trading principles.

Five Adaptive Levels: Using a modified ATR-based calculation, the indicator plots five key levels (two resistance, one average, and two support) that adjust dynamically to market volatility. These levels serve as critical zones for potential reversals.

ICT Structure Analysis: The indicator incorporates BOS and MSS logic to detect shifts in market structure, plotting bullish and bearish breaks with customizable colors for clarity.

Buy and sell signals are generated when the price crosses key levels while outside the SMA shadow, indicating potential reversal opportunities. The signals are visualized as small circles above (sell) or below (buy) the price bars, making them easy to interpret.

Mathematical Concepts
SMA Shadow: The indicator calculates the SMA of the highest highs and lowest lows over a user-defined period (default: 100). This creates a dynamic range that highlights extreme price movements, which contrarian traders often target for reversals.

Five Levels Calculation: The five levels are derived using a volatility-adjusted formula based on the Average True Range (ATR). The average level (central pivot) is calculated as a smoothed price, with two upper (resistance) and two lower (support) levels offset by a multiple of the ATR (default multiplier: 6.0). This adaptive approach ensures the levels remain relevant across varying market conditions.

ICT BOS/MSS Logic: The indicator identifies pivot highs and lows on a user-defined timeframe (default: daily) to detect structural breaks. A BOS occurs when the price breaks a prior pivot high (bullish) or low (bearish), while an MSS signals a shift in market direction, providing context for potential reversals.

Entry and Exit Rules
Buy Signal (Blue Dot Below Bar): Triggered when the closing price is below both the SMA shadow (smaLow) and the average level (avg), and the price crosses under either the first or second support level (prS1 or prS2). This suggests the market may be oversold, indicating a potential reversal upward.

Sell Signal (White Dot Above Bar): Triggered when the closing price is above both the SMA shadow (smaHigh) and the average level (avg), and the price crosses over either the first or second resistance level (prR1 or prR2). This suggests the market may be overbought, indicating a potential reversal downward.

Recommended Usage
This indicator is optimized for the daily timeframe, where it has been designed to capture significant reversal opportunities in trending or ranging markets. However, it can be adapted to other timeframes (e.g., 1H, 4H, 15M) with proper testing of settings such as SMA length, ATR multiplier, and structure timeframe. Users are encouraged to backtest and optimize parameters to suit their trading style and asset class.

Customization Options
SMA Length: Adjust the SMA period (default: 100) to control the sensitivity of the shadow.

Five Levels Length and Multiplier: Modify the length (default: 200) and ATR multiplier (default: 6.0) to fine-tune the support/resistance levels.

Timeframe Settings: Set separate timeframes for structure analysis and five levels to align with your trading strategy.

Color and Signal Display: Customize colors for BOS/MSS lines and toggle buy/sell signals on or off for a cleaner chart.

Why Use This Indicator?
The "Contrarian with 5 Levels" indicator combines the power of contrarian trading with dynamic levels and market structure analysis, offering a unique perspective for identifying high-probability reversal setups. Its intuitive design, customizable settings, and clear signal visualization make it suitable for both novice and experienced traders. Whether you're trading forex, stocks, or cryptocurrencies, this indicator provides a robust framework for spotting potential turning points in the market.

We hope you find the "Contrarian with 5 Levels" indicator a valuable addition to your trading toolkit! Happy trading!

Please leave feedback in the comments section.



Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.