QV 4D BX Reversal

### Overview of the Strategy
The "QV 4D BX Reversal" is a Pine Script (version 5) trading strategy for TradingView, designed as a reversal-based system using a custom momentum oscillator called "B-Xtrender" on a higher timeframe (default 4-day). It supports user-selected long-only or short-only trading, entering on signs of momentum reversal or continuation in the oscillator's direction. The strategy uses 5% of equity per trade, with no commissions, and focuses on simple entry/exit rules based on the oscillator's value, changes, and thresholds. It's plotted in a separate pane as a colored histogram (green for positive/uptrending, red for negative/downtrending), with a centerline at 0. This script is suited for trend-reversal trading in assets like stocks, forex, or crypto, emphasizing higher-timeframe signals for reduced noise.
The name likely refers to:
- **QV**: QuantVault (the creator).
- **4D**: Default 4-day timeframe for the oscillator.
- **BX**: B-Xtrender oscillator.
- **Reversal**: Focus on detecting momentum shifts for entries and exits.
It's licensed under Mozilla Public License 2.0, making it open-source friendly.
### Key Indicators and Calculations
The core of the strategy is a single indicator fetched from a higher timeframe:
1. **B-Xtrender Oscillator (shortTermXtrender)**:
- Formula: `RSI(EMA(close, short_l1) - EMA(close, short_l2), short_l3) - 50`.
- Defaults: L1=5, L2=20, L3=5.
- This measures momentum in the difference between a fast and slow EMA, normalized via RSI, and centered around 0 (positive = bullish, negative = bearish).
- Fetched via `request.security` from the input timeframe (TF1, default "4D").
- Plotted as a histogram:
- Green (lime if increasing, darker if decreasing) when >0.
- Red (bright if increasing toward 0, darker if decreasing) when <0.
- A dashed gray hline at 0 acts as a centerline for crossovers.
No other indicators like ATR or bands are used—it's purely oscillator-driven.
### How the Strategy Works: Entries
Entries trigger on momentum shifts or continuations in the B-Xtrender, filtered by the selected trade direction. Only one direction is active at a time (no hedging).
- **Long Direction**:
- **Entry Condition** (`long_entry`): Triggers if either:
- Crossover above 0 (from below) AND the value is increasing (current > previous).
- OR simply increasing (current > previous), regardless of level.
- On entry, it records if the oscillator was below the exit level (exit_lvl, default 3.5) via `entryBelowExit` for a special exit rule.
- Enters a long position with 5% of equity.
- **Short Direction**:
- **Entry Condition** (`short_entry`): Triggers if either:
- Crossunder below 0 (from above) AND the value is decreasing (current < previous).
- OR simply decreasing (current < previous), regardless of level.
- Enters a short position with 5% of equity.
No pyramiding or position sizing variations—entries are straightforward and can re-enter immediately after exits if conditions met. No additional filters like volume or price action.
### How the Strategy Works: Exits
Exits close the entire position based on adverse momentum signals, with combined rules for robustness. Exits are direction-specific and only trigger if in a position.
- **Long Exits** (`long_exit`): Closes the long if any of:
- Crossunder below the exit level (default 3.5).
- Oscillator is red (<=0) AND decreasing for 2 consecutive bars (current < prev, prev < prev[1]).
- If entry was below exit level (`entryBelowExit` true), crossunder below 0.
- Comment on close indicates the reason (e.g., "Cross below 3.5" or "Red + 2-bar decline").
- Resets `entryBelowExit` after exit.
- **Short Exits** (`short_exit`): Closes the short if any of:
- Crossover above the negative exit level (-3.5).
- Oscillator is green (>=0) AND increasing for 2 consecutive bars (current > prev, prev > prev[1]).
- Comment on close indicates the reason (e.g., "Cross above -3.5" or "Green + 2-bar increase").
This setup aims to exit on weakening momentum or threshold breaches, protecting against reversals. No partial exits or trailing stops—full close only.
### Alerts
The script includes alert conditions for key events, which can be set up in TradingView for notifications:
- Long Entry (Crossover): "B-Xtrender crossed above 0 and is rising → LONG".
- Long Entry (Increasing): "B-Xtrender TF1 is increasing → LONG".
- Long Exit (Red + 2-Bar Decline): "B-Xtrender is red and decreased for 2 bars → EXIT LONG".
- Short Entry (Crossunder): "B-Xtrender crossed below 0 and is falling → SHORT".
- Short Entry (Decreasing): "B-Xtrender TF1 is decreasing → SHORT".
- Short Exit (Green + 2-Bar Increase): "B-Xtrender is green and increased for 2 bars → EXIT SHORT".
These use `alertcondition` for easy setup.
### Additional Notes
- **Customization**: Inputs allow tweaking EMA lengths, timeframe, exit level, and direction. Best for higher TFs like 4D to capture multi-day reversals.
- **Risk Management**: Relies on equity percentage sizing; no built-in stops beyond oscillator exits. Users should backtest for drawdowns.
- **Limitations**: Single-timeframe focus may miss broader trends; no volume or volatility filters. Assumes chart TF is lower than "4D" for accurate security requests.
- **Performance**: Suited for ranging or reversing markets where momentum shifts are frequent. In strong trends, it might enter/exit prematurely.
This strategy provides a simple, momentum-based reversal system, ideal for beginners or as a building block for more complex setups.
Script sur invitation seulement
Seuls les utilisateurs approuvés par l'auteur peuvent accéder à ce script. Vous devrez demander et obtenir l'autorisation pour l'utiliser. Celle-ci est généralement accordée après paiement. Pour plus de détails, suivez les instructions de l'auteur ci-dessous ou contactez directement QuantVault.
TradingView ne recommande PAS de payer ou d'utiliser un script à moins que vous ne fassiez entièrement confiance à son auteur et que vous compreniez comment il fonctionne. Vous pouvez également trouver des alternatives gratuites et open-source dans nos scripts communautaires.
Instructions de l'auteur
Clause de non-responsabilité
Script sur invitation seulement
Seuls les utilisateurs approuvés par l'auteur peuvent accéder à ce script. Vous devrez demander et obtenir l'autorisation pour l'utiliser. Celle-ci est généralement accordée après paiement. Pour plus de détails, suivez les instructions de l'auteur ci-dessous ou contactez directement QuantVault.
TradingView ne recommande PAS de payer ou d'utiliser un script à moins que vous ne fassiez entièrement confiance à son auteur et que vous compreniez comment il fonctionne. Vous pouvez également trouver des alternatives gratuites et open-source dans nos scripts communautaires.