mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08:05 +00:00
Refactor documentation for various filters and indicators to enhance clarity and consistency
- Updated Bessel, Bilateral, Blma, Butter, Conv, Ema, Kama, LSMA, MAMA, MGDI, SSF, USF, ATR, ADL, and ADOSC documentation to use bullet points for key concepts and features. - Added a new Qodana configuration file for code analysis. - Removed coverage configuration from Quantower.Tests.csproj to streamline testing setup.
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
# VWAPBANDS: VWAP Bands
|
||||
|
||||
## Overview and Purpose
|
||||
|
||||
VWAP Bands (VWAPBANDS) is a channel indicator that extends the Volume Weighted Average Price (VWAP) concept by adding standard deviation bands above and below the central VWAP line. This indicator combines the volume-weighted fairness concept of VWAP with statistical volatility measurements, creating dynamic support and resistance levels that reflect both price-volume relationships and market volatility.
|
||||
|
||||
Unlike traditional moving average-based bands, VWAPBANDS uses volume-weighted variance calculations to determine band width, making the indicator particularly sensitive to volume-driven price movements. The bands automatically adjust to market conditions while maintaining their statistical significance, providing traders with reliable levels for identifying overbought/oversold conditions and potential reversal points.
|
||||
|
||||
## Core Concepts
|
||||
|
||||
* **Volume-weighted statistics:** Uses volume data to weight price observations, giving more importance to high-volume periods
|
||||
* **Session-based calculation:** Resets calculations based on configurable time periods (daily, hourly, etc.)
|
||||
* **Statistical significance:** Bands represent 1 and 2 standard deviations from the volume-weighted mean
|
||||
* **Dynamic adaptation:** Band width adjusts automatically based on volume-weighted price variance
|
||||
* **Multi-timeframe flexibility:** Supports various reset intervals from minutes to months
|
||||
* **Institutional relevance:** Reflects the same VWAP calculations used by institutional traders
|
||||
|
||||
The key advantage of VWAPBANDS is its ability to combine the fairness concept of VWAP (where institutional orders are often benchmarked) with volatility-based support and resistance levels, making it particularly valuable for understanding institutional price levels and market structure.
|
||||
|
||||
## Common Settings and Parameters
|
||||
|
||||
| Parameter | Default | Function | When to Adjust |
|
||||
| ------ | ------ | ------ | ------ |
|
||||
| Source | HLC3 | Price data used for VWAP calculation | Use Close for end-of-period analysis, HLC3 for comprehensive price representation |
|
||||
| Session Reset | 1D | Time period for VWAP calculation reset | Match to trading strategy timeframe: intraday (1H, 4H), swing (1D), position (1W) |
|
||||
| StdDev Multiplier | 1.0 | Distance of primary bands from VWAP in standard deviations | Increase for wider bands in volatile markets, decrease for tighter levels |
|
||||
| Show 2nd Bands | True | Display secondary bands at 2x multiplier distance | Disable for cleaner charts, enable for additional confluence levels |
|
||||
|
||||
**Pro Tip:** Use daily reset for swing trading strategies, hourly reset for intraday scalping, and weekly reset for position trading to align the indicator with your trading timeframe.
|
||||
|
||||
## Calculation and Mathematical Foundation
|
||||
|
||||
**Simplified explanation:**
|
||||
VWAPBANDS calculates the volume-weighted average price from the session start, then computes the volume-weighted variance of prices around this average. Standard deviation bands are plotted at 1x and 2x the multiplier distance from VWAP.
|
||||
|
||||
**Technical formula:**
|
||||
1. VWAP = Σ(Price × Volume) / Σ(Volume)
|
||||
2. Volume-Weighted Variance = Σ(Price² × Volume) / Σ(Volume) - VWAP²
|
||||
3. Standard Deviation = √(Volume-Weighted Variance)
|
||||
4. Upper Band = VWAP + (Multiplier × Standard Deviation)
|
||||
5. Lower Band = VWAP - (Multiplier × Standard Deviation)
|
||||
|
||||
**Detailed calculation steps:**
|
||||
1. Initialize cumulative sums at session start (price×volume, volume, price²×volume)
|
||||
2. For each bar, add current values to cumulative sums if volume > 0
|
||||
3. Calculate VWAP as ratio of cumulative price×volume to cumulative volume
|
||||
4. Compute volume-weighted second moment and subtract VWAP squared for variance
|
||||
5. Take square root of variance to get standard deviation
|
||||
6. Plot bands at specified multiples of standard deviation from VWAP
|
||||
|
||||
> 🔍 **Technical Note:** The implementation uses session-based resets to ensure VWAP calculations align with market structure. Volume-weighted variance provides more accurate volatility measurement than simple price variance, as it reflects the actual trading intensity at different price levels.
|
||||
|
||||
## Interpretation Details
|
||||
|
||||
VWAPBANDS provides multiple layers of market analysis:
|
||||
|
||||
* **VWAP Line Analysis:**
|
||||
* Price above VWAP: Bullish bias, buyers in control above fair value
|
||||
* Price below VWAP: Bearish bias, sellers in control below fair value
|
||||
* Price oscillating around VWAP: Balanced market, fair value region
|
||||
|
||||
* **Band Interaction Signals:**
|
||||
* Price touching upper 1σ band: Potential resistance, consider profit-taking
|
||||
* Price touching lower 1σ band: Potential support, consider accumulation
|
||||
* Price beyond 2σ bands: Extreme conditions, potential mean reversion opportunity
|
||||
* Price consistently above/below bands: Strong trend continuation signal
|
||||
|
||||
* **Band Width Analysis:**
|
||||
* Expanding bands: Increasing volatility, larger price movements expected
|
||||
* Contracting bands: Decreasing volatility, potential breakout setup
|
||||
* Stable band width: Consistent volatility environment
|
||||
|
||||
* **Volume-Price Relationship:**
|
||||
* High volume near bands: Increased significance of support/resistance levels
|
||||
* Low volume near bands: Potential for false breakouts or weak reversals
|
||||
* Volume expansion with band breaks: Confirmation of directional moves
|
||||
|
||||
## Trading Applications
|
||||
|
||||
**Mean Reversion Strategy:**
|
||||
* Buy when price touches or exceeds lower 1σ band with volume confirmation
|
||||
* Sell when price reaches VWAP or upper bands
|
||||
* Use 2σ bands for extreme mean reversion opportunities
|
||||
* Set stops beyond 2σ levels to account for extended moves
|
||||
|
||||
**Trend Following Strategy:**
|
||||
* Enter long positions when price breaks above upper bands with volume
|
||||
* Enter short positions when price breaks below lower bands with volume
|
||||
* Use VWAP as dynamic support/resistance in trending markets
|
||||
* Trail stops using the opposite band or VWAP line
|
||||
|
||||
**Institutional Level Trading:**
|
||||
* Monitor price action around VWAP for institutional interest
|
||||
* Look for volume spikes when price approaches VWAP after extended moves
|
||||
* Use VWAP as benchmark for order execution efficiency
|
||||
* Identify accumulation/distribution phases based on VWAP interaction
|
||||
|
||||
**Breakout Strategy:**
|
||||
* Monitor periods of contracting bands for potential breakouts
|
||||
* Enter positions on volume-confirmed breaks beyond 1σ bands
|
||||
* Target 2σ bands for profit-taking on breakout moves
|
||||
* Use failed breakouts as contrarian signals
|
||||
|
||||
## Signal Combinations
|
||||
|
||||
**High-Probability Long Signals:**
|
||||
* Price bounces off lower 1σ band with increasing volume
|
||||
* Price reclaims VWAP after period below with strong volume
|
||||
* Bullish divergence between price and volume at lower bands
|
||||
* Multiple timeframe VWAP alignment supporting upward bias
|
||||
|
||||
**High-Probability Short Signals:**
|
||||
* Price fails at upper 1σ band with declining volume
|
||||
* Price breaks below VWAP after period above with strong volume
|
||||
* Bearish divergence between price and volume at upper bands
|
||||
* Multiple timeframe VWAP alignment supporting downward bias
|
||||
|
||||
**Consolidation Warnings:**
|
||||
* Price oscillating between narrow bands around VWAP
|
||||
* Decreasing volume with price approaching bands
|
||||
* Multiple false breakouts beyond bands
|
||||
* Band width contracting significantly
|
||||
|
||||
## Advanced Techniques
|
||||
|
||||
**Multi-Timeframe Analysis:**
|
||||
* Use higher timeframe VWAPBANDS for major support/resistance levels
|
||||
* Combine daily VWAP with intraday bands for precision timing
|
||||
* Look for confluence between different session VWAP levels
|
||||
* Identify key levels where multiple timeframe VWAPs converge
|
||||
|
||||
**Volume Profile Integration:**
|
||||
* Combine VWAPBANDS with volume profile for enhanced context
|
||||
* Identify high-volume nodes near VWAP levels
|
||||
* Use volume-at-price data to validate band significance
|
||||
* Monitor institutional order flow around VWAP levels
|
||||
|
||||
**Session-Specific Analysis:**
|
||||
* Analyze different session reset periods for various market conditions
|
||||
* Use overnight VWAP for gap analysis and fair value assessment
|
||||
* Apply weekly VWAP for longer-term institutional benchmarking
|
||||
* Implement monthly VWAP for portfolio rebalancing levels
|
||||
|
||||
## Limitations and Considerations
|
||||
|
||||
* **Session dependency:** Reset timing significantly affects indicator behavior and relevance
|
||||
* **Volume quality:** Requires accurate volume data; may be less reliable in low-volume periods
|
||||
* **Lag component:** VWAP calculations create some lag, especially early in sessions
|
||||
* **Market structure:** Most effective in liquid markets with consistent volume patterns
|
||||
* **Gap handling:** Overnight gaps can affect VWAP relevance at session open
|
||||
* **False signals:** Low-volume periods may produce unreliable band interactions
|
||||
|
||||
## Comparison with Related Indicators
|
||||
|
||||
**VWAPBANDS vs. Bollinger Bands:**
|
||||
* VWAPBANDS: Volume-weighted center line with volume-weighted variance
|
||||
* Bollinger Bands: Simple moving average center with price-based standard deviation
|
||||
|
||||
**VWAPBANDS vs. Keltner Channels:**
|
||||
* VWAPBANDS: VWAP-based with statistical variance measurements
|
||||
* Keltner Channels: EMA-based with ATR-derived band width
|
||||
|
||||
**VWAPBANDS vs. Standard VWAP:**
|
||||
* VWAPBANDS: Adds volatility context with standard deviation bands
|
||||
* Standard VWAP: Single line without volatility or support/resistance context
|
||||
|
||||
## Best Practices
|
||||
|
||||
**Parameter Optimization:**
|
||||
* Match session reset to trading strategy timeframe
|
||||
* Adjust multiplier based on asset volatility characteristics
|
||||
* Test different source prices (close vs. HLC3) for optimal results
|
||||
* Consider market hours and session boundaries for reset timing
|
||||
|
||||
**Risk Management:**
|
||||
* Use bands for position sizing (larger positions near support bands)
|
||||
* Set stops beyond 2σ levels to avoid normal volatility whipsaws
|
||||
* Monitor volume confirmation for all band interaction signals
|
||||
* Avoid trading during low-volume periods when bands may be unreliable
|
||||
|
||||
**Market Context:**
|
||||
* Consider overall market regime (trending vs. ranging)
|
||||
* Account for news events and earnings that may affect volume patterns
|
||||
* Monitor correlation with institutional trading patterns
|
||||
* Adjust expectations based on market volatility environment
|
||||
|
||||
## References
|
||||
|
||||
* Harris, L. (2003). Trading and Exchanges: Market Microstructure for Practitioners. Oxford University Press.
|
||||
* Berkowitz, S. A. (1993). The Advantages of Volume Weighted Average Price Trading. Journal of Portfolio Management.
|
||||
@@ -0,0 +1,92 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("VWAP Bands (VWAPBANDS)", "VWAPBANDS", overlay=true)
|
||||
|
||||
//@function Calculates VWAP Bands with standard deviation bands
|
||||
//@param src Source price series (typically hlc3)
|
||||
//@param vol Volume series
|
||||
//@param reset_condition Condition to reset VWAP calculation
|
||||
//@param multiplier Standard deviation multiplier for bands
|
||||
//@returns [vwap_value, upper_band1, lower_band1, upper_band2, lower_band2, stdev] VWAP and band values
|
||||
//@optimized for performance and dirty data
|
||||
vwapbands(series float src, series float vol, series bool reset_condition, series float multiplier) =>
|
||||
var float sum_pv = 0.0, var float sum_vol = 0.0, var float sum_pv2 = 0.0, var int count = 0
|
||||
float current_price = nz(src), float current_vol = nz(vol, 0.0)
|
||||
if reset_condition
|
||||
if current_vol > 0.0
|
||||
sum_pv := current_price * current_vol
|
||||
sum_vol := current_vol
|
||||
sum_pv2 := current_price * current_price * current_vol
|
||||
count := 1
|
||||
else
|
||||
sum_pv := 0.0, sum_vol := 0.0, sum_pv2 := 0.0, count := 0
|
||||
else
|
||||
if current_vol > 0.0
|
||||
sum_pv += current_price * current_vol
|
||||
sum_vol += current_vol
|
||||
sum_pv2 += current_price * current_price * current_vol
|
||||
count += 1
|
||||
float vwap_val = sum_vol > 0.0 ? sum_pv / sum_vol : src
|
||||
float variance = 0.0
|
||||
if sum_vol > 0.0 and count > 1
|
||||
mean_p2 = sum_pv2 / sum_vol
|
||||
vwap_squared = vwap_val * vwap_val
|
||||
variance := math.max(0.0, mean_p2 - vwap_squared)
|
||||
float stdev = math.sqrt(variance)
|
||||
float upper1 = vwap_val + multiplier * stdev
|
||||
float lower1 = vwap_val - multiplier * stdev
|
||||
float upper2 = vwap_val + 2.0 * multiplier * stdev
|
||||
float lower2 = vwap_val - 2.0 * multiplier * stdev
|
||||
[vwap_val, upper1, lower1, upper2, lower2, stdev]
|
||||
|
||||
// ---------- Main loop ----------
|
||||
|
||||
// Inputs
|
||||
i_source = input.source(hlc3, "Source")
|
||||
i_session_type = input.string("1D", "Session Reset", options=["1m", "2m", "3m", "5m", "10m", "15m", "30m", "45m", "1H", "2H", "3H", "4H", "1D", "1W", "1M", "3M", "6M", "12M", "Never"])
|
||||
i_multiplier = input.float(1.0, "Standard Deviation Multiplier", minval=0.1, step=0.1)
|
||||
i_show_bands2 = input.bool(true, "Show 2nd Standard Deviation Bands")
|
||||
|
||||
// Calculate reset condition
|
||||
reset_condition = switch i_session_type
|
||||
"1m" => ta.change(time("1")) != 0
|
||||
"2m" => ta.change(time("2")) != 0
|
||||
"3m" => ta.change(time("3")) != 0
|
||||
"5m" => ta.change(time("5")) != 0
|
||||
"10m" => ta.change(time("10")) != 0
|
||||
"15m" => ta.change(time("15")) != 0
|
||||
"30m" => ta.change(time("30")) != 0
|
||||
"45m" => ta.change(time("45")) != 0
|
||||
"1H" => ta.change(time("60")) != 0
|
||||
"2H" => ta.change(time("120")) != 0
|
||||
"3H" => ta.change(time("180")) != 0
|
||||
"4H" => ta.change(time("240")) != 0
|
||||
"1D" => ta.change(time("1D")) != 0
|
||||
"1W" => ta.change(time("1W")) != 0
|
||||
"1M" => ta.change(time("1M")) != 0
|
||||
"3M" => ta.change(time("3M")) != 0
|
||||
"6M" => ta.change(time("6M")) != 0
|
||||
"12M" => ta.change(time("12M")) != 0
|
||||
"Never" => bar_index == 0
|
||||
=> false
|
||||
|
||||
// Calculation
|
||||
[vwap_value, upper_band1, lower_band1, upper_band2, lower_band2, stdev] = vwapbands(i_source, volume, reset_condition, i_multiplier)
|
||||
|
||||
// Colors
|
||||
vwap_color = color.yellow
|
||||
band1_color = color.blue
|
||||
band2_color = color.purple
|
||||
fill_color1 = color.blue
|
||||
fill_color2 = color.purple
|
||||
|
||||
// Plot
|
||||
p_vwap = plot(vwap_value, "VWAP", color=color.yellow, linewidth=2)
|
||||
p_upper1 = plot(upper_band1, "Upper Band 1σ", color=color.yellow, linewidth=2)
|
||||
p_lower1 = plot(lower_band1, "Lower Band 1σ", color=color.yellow, linewidth=2)
|
||||
p_upper2 = plot(i_show_bands2 ? upper_band2 : na, "Upper Band 2σ", color=color.yellow, linewidth=2)
|
||||
p_lower2 = plot(i_show_bands2 ? lower_band2 : na, "Lower Band 2σ", color=color.yellow, linewidth=2)
|
||||
fill(p_upper1, p_lower1, color=color.new(color.blue, 90), title="1σ Band Fill")
|
||||
fill(p_upper2, p_upper1, color=i_show_bands2 ? color.new(color.purple, 90) : na, title="Upper 2σ Fill")
|
||||
fill(p_lower1, p_lower2, color=i_show_bands2 ? color.new(color.purple, 90) : na, title="Lower 2σ Fill")
|
||||
Reference in New Issue
Block a user