RSI & VWAP Strategy

Strategy Overview
This is a long-only, mean-reversion "buy the dip" strategy designed to identify and capitalize on oversold conditions in the market. The core philosophy is to enter positions when an asset is technically oversold (confirmed by RSI) and trading at a "discount" relative to its recent volume (confirmed by VWAP).
The strategy does not just look for weakness; it waits for a single bar of bullish confirmation (a green candle) before triggering an entry. This helps to filter out "falling knives" and improves the quality of the entry signal.
The true power of this script lies in its sophisticated position management, which includes:
Smart Pyramiding: A "scale-in" feature that allows you to add to your position at cheaper prices.
Dual-Mode Exit System: You can choose between a simple, fixed Stop-Loss/Take-Profit or an advanced, multi-stage trailing stop designed to protect profits and let winners run.
1. The Entry Signal: "The Dip"
A buy signal (marked by a green triangle below the bar) is generated only when all three of the following conditions are met simultaneously:
RSI is Oversold: The RSI value drops below the user-defined RSI Oversold Level (default: 30). This identifies technically oversold weakness.
Price is Below VWAP: The closing price is below the Volume-Weighted Average Price. This indicates the price is "cheap" relative to where the majority of volume has traded.
Bullish Confirmation Bar: The bar itself must be green (close > open). This acts as a confirmation signal, showing that buyers are stepping in to defend the oversold/undervalued level.
2. Position Management: Smart Pyramiding
This strategy allows for pyramiding (default: 1 additional entry). However, it doesn't just buy every new signal. It uses a "Smart Pyramiding" feature controlled by the "Percent Decrease" input.
How it works: When a new buy signal appears after you are already in a position, the strategy checks the Percent Decrease value.
Example (Percent Decrease = 5%): The strategy will only add to your position if the new entry price is at least 5% lower than your last entry price. This is an "average down" or "scale-in" feature that ensures you only add to your position at significantly better prices.
If set to 0%: The strategy will add to the position on any new valid buy signal (up to the pyramid limit).
3. The Dual-Mode Exit System
This is the most advanced feature of the script. You can choose your exit logic using the "Enable Trailing Stop" checkbox.
Mode 1: Standard SL/TP (Trailing Stop = OFF)
This is the simple, traditional exit mode.
It uses a fixed percentage-based Stop Loss and Take Profit.
These are calculated from the strategy.position_avg_price (your average entry cost).
Ideal for straightforward backtesting or a "set it and forget it" approach.
Mode 2: Advanced Trailing Stop (Trailing Stop = ON)
This is a dynamic, multi-phase exit logic designed to maximize gains and protect profits. It works in three distinct phases:
Phase 1: Entry (No Stop-Loss)
CRITICAL: When a position is first opened in this mode, no stop-loss is active. This is a deliberate design choice to avoid being stopped out by initial volatility before the trade has a chance to move in your favor. The position is "naked" until it hits the first profit target.
Phase 2: Activation (Breakeven Trigger)
When the price's high reaches your "First Profit Target (%)" (default: 5%), the trailing stop activates.
The script now begins tracking the highestPrice achieved since activation.
Phase 3: Trailing & Profit Protection
Once activated, the script places a dynamic stop-loss at a distance of "Trailing Pullback Stop (%)" (default: 3%) below the highestPrice.
Profit Lock-In: This stop-loss can only move up. It includes a breakeven-plus feature (math.max(trailingStopLevel, entryPrice)). This means that once your stop is activated, it will never move back below your average entry price, effectively guaranteeing that a winning trade cannot turn into a loss.
Example: Your First Profit Target is 5% and Trailing Pullback is 3%. The trade goes to +5% (trail activates, breakeven stop is placed). It then goes to +10% (stop moves up to +7%). If the price then falls to +6.9%, you are stopped out with a +7% gain.
Pyramid-Reset Logic: If you pyramid into a position (add a second entry), the entire Trailing Stop mechanism resets. The strategy.position_avg_price is recalculated, and the logic returns to Phase 1 (No Stop-Loss) until the new First Profit Target is hit based on the new average cost.
Key Inputs & Features
RSI Settings: RSI Period and RSI Oversold Level to fine-tune the entry signal.
ADVANCE SETTINGS:
Use Percentage Decrease?: Enables the "Smart Pyramiding" feature.
Percent Decrease: The percentage discount required for a pyramid entry.
TRAILING STOP (Group):
Enable Trailing Stop: The master switch for the exit logic (Mode 1 vs. Mode 2).
First Profit Target (%): The percentage gain required to activate the trailing stop.
Trailing Pullback Stop (%): How "tight" the trailing stop will be once active.
Standard SL/TP (Group):
Stop Loss %: Used only if the Trailing Stop is OFF.
Take Profit %: Used only if the Trailing Stop is OFF.
Backtesting Date Range: Built-in date filters allow you to easily test the strategy's performance during specific market periods (e.g., bull markets, bear markets, or choppy ranges).
How to Use & Recommendations
Test Both Exit Modes: Run backtests using both the Standard SL/TP mode and the Advanced Trailing Stop mode to see which performs better on your asset and timeframe.
Understand the Risk: Be fully aware that in Advanced Trailing Mode, there is no hard stop-loss between your entry and the "First Profit Target." This requires a higher risk tolerance but can prevent premature stop-outs.
Tune for Your Asset: This is a mean-reversion strategy. It may perform best in markets that are ranging or "choppy." It may perform poorly in very strong, one-directional trending markets. Adjust the RSI and Percent Decrease settings to match the volatility of your chosen asset.
Disclaimer: This script is for educational and informational purposes only. It is not financial advice. All trading involves risk, and past performance is not indicative of future results. Please conduct your own thorough backtesting and research before using this strategy with real funds.
Skrip hanya-undangan
Hanya pengguna yang disetujui oleh penulis yang dapat mengakses skrip ini. Anda harus meminta dan mendapatkan izin untuk menggunakannya. Izin ini biasanya diberikan setelah pembayaran. Untuk detail lebih lanjut, ikuti petunjuk penulis di bawah ini atau hubungi TrendciHoca secara langsung.
TradingView TIDAK menyarankan untuk membayar atau menggunakan skrip kecuali anda benar-benar percaya kepada pembuatnya dan memahami cara kerjanya. Anda juga dapat menemukan alternatif sumber terbuka yang gratis di skrip komunitas kami.
Instruksi penulis
Pernyataan Penyangkalan
Skrip hanya-undangan
Hanya pengguna yang disetujui oleh penulis yang dapat mengakses skrip ini. Anda harus meminta dan mendapatkan izin untuk menggunakannya. Izin ini biasanya diberikan setelah pembayaran. Untuk detail lebih lanjut, ikuti petunjuk penulis di bawah ini atau hubungi TrendciHoca secara langsung.
TradingView TIDAK menyarankan untuk membayar atau menggunakan skrip kecuali anda benar-benar percaya kepada pembuatnya dan memahami cara kerjanya. Anda juga dapat menemukan alternatif sumber terbuka yang gratis di skrip komunitas kami.