PROTECTED SOURCE SCRIPT

SwingTrade VWAP Strategy[TiamatCrypto]V1.1

39
This Pine Script® code creates a trading strategy called "SwingTrade VWAP Strategy [TiamatCrypto] V1.1." This strategy incorporates various trading tools, such as VWAP (Volume Weighted Average Price), ADX (Average Directional Index), and volume signals. Below is an explanation of the components and logic within the script:

### Overview of Features
- **VWAP:** A volume-weighted moving average that assesses price trends relative to the VWAP level.
- **ADX:** A trend strength indicator that helps confirm the strength of bullish or bearish trends.
- **Volume Analysis:** Leverages volume data to gauge momentum and identify volume-weighted buy/sell conditions.
- **Dynamic Entry/Exit Signals:** Combines the above indicators to produce actionable buy/sell or exit signals.
- **Customizable Inputs:** Inputs for tuning parameters like VWAP period, ADX thresholds, and volume sensitivity.

---

### **Code Breakdown**

#### **Input Parameters**
The script begins by defining several user-configurable variables under groups. These include indicators' on/off switches (`showVWAP`, `enableADX`, `enableVolume`) and input parameters for VWAP, ADX thresholds, and volume sensitivity:
- **VWAP Period and Threshold:** Controls sensitivity for VWAP signal generation.
- **ADX Settings:** Allows users to configure the ADX period and strength threshold.
- **Volume Ratio:** Detects bullish/bearish conditions based on relative volume patterns.

---

#### **VWAP Calculation**
The script calculates VWAP using the formula:
\[ \text{VWAP} = \frac{\text{Cumulative(P * V)}}{\text{Cumulative(V)}} \]
Where `P` is the typical price (`(high + low + close)/3`) and `V` is the volume.
- It resets cumulative values (`sumPV` and `sumV`) at the start of each day.
- Delta percentage (`deltaPercent`) is calculated as the percentage difference between the close price and the VWAP.

---

#### **Indicators and Signals**
1. **VWAP Trend Signals:**
- Identifies bullish/bearish conditions based on price movement (`aboveVWAP`, `belowVWAP`) and whether the price is crossing the VWAP level (`crossingUp`, `crossingDown`).
- Also detects rising/falling delta changes based on the VWAP threshold.

2. **ADX Calculation:**
- Calculates the directional movement (`PlusDM`, `MinusDM`) and smoothed values for `PlusDI`, `MinusDI`, and `ADX`.
- Confirms strong bullish/bearish trends when ADX crosses the defined threshold.

3. **Volume-Based Signals:**
- Evaluates the ratio of bullish volume (when `close > VWAP`) to bearish volume (when `close < VWAP`) over a specified lookback period.

---

#### **Trade Signals**
The buy and sell signals are determined by combining conditions from the VWAP, ADX, and volume signals:
- **Buy Signal:** Triggered when price upward crossover VWAP, delta rises above the threshold, ADX indicates a strong bullish trend, and volume confirms bullish momentum.
- **Sell Signal:** Triggered under inverse conditions.
- Additionally, exit conditions (`exitLong` and `exitShort`) are based on VWAP crossovers combined with the reversal of delta values.

---

#### **Plotting and Display**
The strategy plots VWAP on the chart and adds signal markers for:
- **Buy/Long Entry:** Green triangle below bars.
- **Sell/Short Entry:** Red triangle above bars.
- **Exit Signals:** Lime or orange "X" shapes for exits from long/short positions.
- Additionally, optional text labels are displayed to indicate the type of signal.

---

#### **Trading Logic**
The script's trading logic executes as follows:
- **Entries:**
- Executes long trades when the `buySignal` condition is true.
- Executes short trades when the `sellSignal` condition is true.
- **Exits:**
- Closes long positions upon `exitLong` conditions.
- Closes short positions upon `exitShort` conditions.
- The strategy calculates profits and visualizes the trade entry, exit, and running profit within the chart.

---

#### **Alerts**
Alerts are set up to notify traders via custom signals for buy and sell trades.

---

### **Use Case**
This script is suitable for day traders, swing traders, or algorithmic traders who rely on confluence signals from VWAP, ADX, and volume momentum. Its modular structure (e.g., the ability to enable/disable specific indicators) makes it highly customizable for various trading styles and financial instruments.

#### **Customizability**
- Adjust VWAP, ADX, and volume sensitivity levels to fit unique market conditions or asset classes.
- Turn off specific criteria to focus only on VWAP or ADX signals if desired.

#### **Caution**
As with all trading strategies, this script should be used for backtesting and analysis before live implementation. It's essential to validate its performance on historical data while considering factors like slippage and transaction costs.

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.