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.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.