OPEN-SOURCE SCRIPT

VAPI with MA (no ta.sum)

107
## 📘 Indicator: **VAPI with MA (no ta.sum)**

This custom indicator is a version of the **Volume Adjusted Price Indicator (VAPI)** combined with a selectable **moving average (MA)**. It manually computes the volume-weighted price momentum over a period and smooths it with a chosen type of moving average. The purpose is to assess directional volume pressure and potential trend shifts.

---

### 🔧 Inputs:

* **VAPI Length (`length`)**: Number of bars used for calculating the VAPI.
* **MA Length (`maLength`)**: Number of bars for smoothing VAPI with a moving average.
* **MA Type (`maType`)**: Type of moving average to apply (options: SMA, EMA, WMA, RMA, HMA, VWMA).

---

### 📈 Calculation Logic:

1. **x = (2 × close − high − low) / (high − low)**
Measures where the closing price lies within the candle range:

* Close at high → x = 1
* Close at low → x = -1
* Close in the middle → x = 0
A small constant (0.0001) is used to avoid division by zero.

2. **volX = volume × x**
This adjusts volume based on the candle's directional momentum.

3. **Manual summation over `length` bars** (instead of using `ta.sum`):

* `tva` accumulates the volume-adjusted values (`volX`)
* `tv` accumulates the total volume

4. **VAPI = 100 × (tva / tv)**
Gives a percentage-style oscillator:

* Positive values → bullish pressure
* Negative values → bearish pressure

5. **MA = Moving Average of VAPI**
Type of MA is user-defined (SMA, EMA, WMA, RMA, HMA, or VWMA).

---

### 📊 Plots:

* **VAPI Line** — Gray line (shows raw volume-adjusted price impulse).
* **MA Line** — Orange line (smoothed VAPI).
* **Zero Line** — Dashed horizontal reference at 0:

* Crossovers may suggest trend direction changes.

---

### 💡 Use Cases:

* **Volume momentum analysis**: Shows if volume supports current price action.
* **Divergence spotting**: Compare VAPI behavior against price movements.
* **Trend filtering**: The MA smooths out noise for clearer signals.
* **Entry/exit signals**: Use crossovers of VAPI/MA or zero line as potential triggers.


Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.