INVITE-ONLY SCRIPT

QV 4D BX Reversal

19
This algorithm excels in long-term trading and identifying momentum reversals on higher timeframes. To maximize profits, you can then leverage the QV 2H/4D 2BX & FVB Strategy algorithm, switching to a lower timeframe for precise short-term trades.

### 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.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。