Trend / Volatility-AdaptivePine Script v6

Coefficient of Variation Weighted Moving Average Pine Script — Complete TradingView Guide

The Coefficient of Variation Weighted Moving Average (COVWMA) is a volatility-adaptive moving average indicator for Pine Script that weights each price bar by its coefficient of variation — the ratio of standard deviation to mean — over a rolling lookback window. Bars with higher relative volatility receive greater influence in the calculation, making COVWMA automatically more responsive during sharp market moves and smoother during low-volatility consolidation. Unlike a simple moving average (SMA) or exponential moving average (EMA), COVWMA dynamically adjusts its sensitivity based on recent price dispersion rather than a fixed decay factor. It plots as a continuous overlay line on any TradingView chart, works across all asset classes — stocks, crypto, forex, and futures — and performs well on timeframes from 15-minute intraday charts to daily swing charts. This complete guide covers the Pine Script v6 implementation, configurable parameters, three concrete trading strategies, and step-by-step instructions for generating COVWMA instantly with Pineify.

What Is the Coefficient of Variation Weighted Moving Average?

The Coefficient of Variation Weighted Moving Average (COVWMA) is a volatility-adaptive moving average that weights each bar by the ratio of its rolling standard deviation to its rolling mean, used to track trend direction with automatic sensitivity adjustment. Standard moving averages treat all time periods equally (SMA) or apply a fixed exponential decay (EMA), regardless of how volatile the market was at each point in time. COVWMA solves this by using the coefficient of variation (CV = stdev ÷ mean) as a weighting factor — bars during high-volatility regimes contribute more to the average, while quiet, low-volatility bars are down-weighted automatically.

The concept of volatility-weighting in moving averages has roots in adaptive signal processing research from the 1990s and 2000s, where engineers and quantitative analysts explored ways to make smoothing filters respond proportionally to the signal-to-noise ratio of the input. COVWMA applies this principle directly to price series: when price dispersion (relative to its mean) is large, the MA reacts faster; when price is calm and tightly ranged, the MA stays smooth.

Core formula: For a lookback window of N bars ending at bar t:

  1. Compute the coefficient of variation for each bar i: cov[i] = ta.stdev(source, N) / ta.sma(source, N)
  2. Compute the weighted price: cw[i] = source[i] × cov[i]
  3. Average over the window: COVWMA = sum(cw, N) / sum(cov, N)

In Pine Script v6, this is implemented using ta.stdev(), ta.sma(), and math.sum(). The result is a series float that updates on every bar and plots directly on the price chart as an overlay.

Best Markets

Stocks · Crypto · Forex · Futures

Best Timeframes

15m, 1H, 4H, Daily

Overlay

Yes — plots directly on price chart

COVWMA Pine Script Code Example

The Pine Script v6 code below implements the full COVWMA calculation and plots it as a blue overlay line on the price chart. To use it in TradingView, open the Pine Script editor (press Alt+P), paste the code, and click Add to chart. Change the 14 in p_ta_covwma(close, 14) to any lookback period that suits your trading style.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="Coefficient of Variation Weighted Moving Average", overlay=true, max_labels_count=500)

// Coefficient of Variation Weighted Moving Average (COVWMA)
// Weights each bar by its coefficient of variation (stdev / mean),
// so periods of high relative volatility receive greater influence.
p_ta_covwma(series float source, simple int length) =>
    cov = ta.stdev(source, length) / ta.sma(source, length)
    cw = source * cov
    covwma = math.sum(cw, length) / math.sum(cov, length)
    covwma

p_ind_1 = p_ta_covwma(close, 14) // COVWMA with 14-bar period

// Plot COVWMA as a blue overlay line
plot(p_ind_1, "COVWMA", color.rgb(41, 98, 255, 0), 1)

Chart Preview

Coefficient of Variation Weighted Moving Average (COVWMA) indicator Pine Script code example in TradingView

Parameters

ParameterDefault ValueDescriptionRecommended Range
sourcecloseThe price series to compute COVWMA on. Any numeric series is valid: close, open, hlc3, or a calculated indicator value.Any numeric series
length14Number of bars in the rolling lookback window for computing stdev, SMA, and the weighted sum. Larger values produce a smoother, slower-turning line; smaller values react faster to volatility changes.5–55 depending on style

Tuning Guide by Trading Style

  • Scalping (1m–5m charts): length 5–10 — maximizes responsiveness to intraday volatility spikes
  • Day trading (15m–1H charts): length 10–20 — captures intraday regime shifts without excessive noise
  • Swing trading (4H–Daily charts): length 14–21 — the standard default that works across most assets
  • Position trading (Daily–Weekly charts): length 30–55 — smooth trend filter for multi-week moves

Trading Strategies Using COVWMA

COVWMA is most effective as a dynamic trend filter and pullback entry tool because its volatility-weighted design makes it more reliable than an EMA during high-volatility breakouts. Below are three concrete strategies with specific entry and exit conditions.

Strategy 1 — COVWMA Trend-Following with RSI Confirmation

Market environment: trending markets · Best timeframe: 4H, Daily

Use COVWMA as the trend direction filter paired with RSI(14) to confirm momentum. Because COVWMA reacts faster during high-volatility trending moves, it turns before a standard EMA when a genuine trend begins.

  1. Calculate COVWMA(14): covwma = p_ta_covwma(close, 14)
  2. Calculate RSI(14): rsi = ta.rsi(close, 14)
  3. Long entry: close crosses above covwma[1] AND rsi > 50 (momentum confirming uptrend)
  4. Short entry: close crosses below covwma[1] AND rsi < 50
  5. Exit long: close crosses below covwma[1] or rsi falls below 40
  6. Stop loss: 1.5× ATR(14) below entry bar low

Strategy 2 — COVWMA Pullback Entry

Market environment: trending markets · Best timeframe: 1H, 4H

During a confirmed uptrend, COVWMA acts as a dynamic support level. Buying pullbacks to COVWMA offers better risk-reward than chasing breakouts. Pair with a 50-bar SMA to confirm the broader trend direction.

  1. Confirm uptrend: close > ta.sma(close, 50) AND COVWMA(14) is rising (covwma > covwma[1])
  2. Wait for close to pull back within 0.2% of COVWMA(14) from above
  3. Long entry: next bar opens above COVWMA after touch
  4. Target: 2× ATR(14) above entry price
  5. Stop loss: close below COVWMA on the same bar

Strategy 3 — Dual COVWMA Crossover

Market environment: trending markets · Best timeframe: Daily, Weekly

Use two COVWMA lines of different lengths — a fast line (period 10) and a slow line (period 30) — in a crossover system. Because both lines are volatility-weighted, crossovers during high-volatility breakouts are more decisive than a standard dual-EMA crossover.

  1. Compute fast COVWMA: fast = p_ta_covwma(close, 10)
  2. Compute slow COVWMA: slow = p_ta_covwma(close, 30)
  3. Long entry: fast crosses above slow (golden cross)
  4. Short entry: fast crosses below slow (death cross)
  5. Confirm with volume: require volume > ta.sma(volume, 20) on crossover bar

Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.

How to Generate COVWMA in Pineify

  1. 1

    Open Pineify

    Go to pineify.app and sign in — a free account gives you full access to the AI Coding Agent.

  2. 2

    Click "New Indicator"

    Select "Indicator" as the script type from the creation panel to start a new overlay indicator.

  3. 3

    Describe the COVWMA indicator

    Type a prompt such as: "Create a Coefficient of Variation Weighted Moving Average (COVWMA) with a 14-bar period on the close price, plotted as a blue overlay line." The AI Coding Agent generates the complete Pine Script v6 code in seconds.

  4. 4

    Copy the generated code to TradingView

    Click "Copy to TradingView" to copy the script, then open the TradingView Pine Script editor (Alt+P), paste the code, and click "Add to chart" to apply the indicator instantly.

  5. 5

    Adjust the length and source parameters

    In the TradingView indicator settings panel, change the lookback length (default 14) and source series to match your asset class and trading timeframe — no code editing required.

Frequently Asked Questions

Related Indicators

Build Your COVWMA Indicator in Seconds

Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script indicators — including volatility-adaptive moving averages like COVWMA — instantly for free.

Try Pineify Free