TradingView indicator guides

COVWMA: understand the rolling weights before reading a crossover

The Coefficient of Variation Weighted Moving Average assigns each source value a weight calculated from its own trailing price window. It then averages the latest values using those weights. A high weight can belong to an older bar; the formula does not guarantee that the line follows the current price more closely during volatility.

CV[t] = stdev(source, N)[t] / SMA(source, N)[t]
COVWMA[t] = Σ(source[t−i] × CV[t−i]) / ΣCV[t−i], i = 0…N−1
Inspect the calculation code

Two rolling windows, one source series

First calculate the mean and standard deviation of the latest N source observations. Their ratio is the current CV. Keep that value alongside the current source. The second rolling operation sums the latest N source-times-CV products and divides by the sum of those N CV values.

Do not multiply all N prices by today's CV: that common factor cancels and produces an SMA. The stored historical CVs are what distinguish this calculation. For continuous valid data, the first full set of N complete CV windows needs 2N − 1 source observations: 27 when N is 14.

The example uses population standard deviation, the default of Pine's ta.stdev. Using sample standard deviation multiplies every complete fixed-length CV by the same factor √(N/(N−1)); that factor cancels from the final weighted average when all windows have the same N and valid data. It still changes the reported CV values.

NIST defines CV as standard deviation divided by mean and explains its sensitivity near a zero mean. The moving-average construction on this page is the explicit Pineify implementation; no inventor or historical trading record is inferred from that statistical definition.

A three-observation calculation

Use hypothetical closes 100, 110 and 90 with N = 2. These are calculation inputs, not a trade history. Each two-value population standard deviation is half the distance between the values.

Weights for the first complete COVWMA value, at observation 3
ObservationSourceCV windowMeanSDCVSource × CV
2110100, 11010551/21 ≈ 0.047619110/21 ≈ 5.238095
390110, 90100100.19

COVWMA = (110/21 + 9) / (1/21 + 0.1) = 96.451613. The current observation receives 21/31 of the total weight; the previous one receives 10/31. The corresponding SMA is 100 and a linear WMA with newest weight 2 is 96.666667. These differences describe arithmetic, not which line gives a better trade.

If every source value is multiplied by 10, each CV remains the same and COVWMA becomes 964.516129. If every CV weight alone is multiplied by 10, the output remains 96.451613. A larger absolute CV across an asset class therefore does not, by itself, establish a faster average.

Bounds and undefined cases

For positive rolling means, CV weights are nonnegative. If their sum is positive, dividing them by that sum gives weights that add to one. COVWMA must then lie within the minimum and maximum of the N averaged source values. The three-observation example is between 90 and 110. A short length alone cannot make this positive-weight average jump to twice the window maximum.

  • Constant positive prices give CV = 0. Once all N final weights are zero, COVWMA is undefined, not automatically equal to an SMA. Length 1 has this problem on every valid nonzero source observation.
  • A zero rolling mean makes CV undefined. A mean close to zero can create a very large weight. The displayed helper has no explicit denominator guard.
  • Negative or mixed-sign sources need separate treatment. With source −3, 1, 3 and N = 2, the two CVs are −2 and 0.5. The resulting average is (−2 + 1.5)/(−2 + 0.5) = 0.333333, below both averaged values 1 and 3. The positive-weight bound no longer applies.
  • Missing source values can alter the windows used by built-ins. Compare populated, continuous data first; a strict consecutive-data policy would need additional checks.

A zero weight affects one contribution, not necessarily the entire result. With N = 3 and source 100, 100, 110, 110, 110, the last CV is zero, but the two preceding CVs remain positive. All three averaged source values are 110, so COVWMA is still 110. It becomes undefined only after the remaining positive weights have also left the final window.

Pine Script v6: the current calculation

The helper below matches Pineify's COVWMA formula. It plots one blue line from close and length 14. These are hardcoded arguments: there are no source or length inputs in this copied script, and no alerts, markers, confirmation gate or strategy orders.

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)

// COVWMA — weights price bars by their coefficient of variation
// Parameters: source=close, length=14
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

plot(p_ind_1, "COVWMA", color.rgb(41, 98, 255, 0), 1)

Open TradingView's Pine Editor, paste the source and add it to the chart. Compare a completed bar with a separate calculation using the same feed, source and history. The current line can move as the live close changes. Because this version uses close, a different candle wick with the same close does not directly enter the formula.

Existing COVWMA chart illustration with a moving-average overlay

The retained illustration shows the indicator context. It is not a verification of the calculation table or a record of trading performance.

Compare weights, not unsupported speed rankings

AverageWeight rule
SMAEqual weights over the window
Linear WMAWeights increase with recency
EMARecursive exponential weighting with alpha set by length
VWMAReported bar volume within the window
COVWMAEach observation’s trailing standard deviation divided by its trailing mean

Equal positive CVs produce an SMA. Small CVs do not have to be equal, and all-zero CVs do not produce an SMA. Increasing volatility does not guarantee that the newest price receives the most weight. None of these formulas supplies a universal crossover count, delay ranking or success rate.

The coefficient measures dispersion of source levels across bars. It is not realized return volatility, intrabar high-low range, traded volume or statistical significance. A smooth directional price path can have substantial dispersion around its rolling mean.

Turn a line comparison into an explicit experiment

  1. Record the symbol, venue, session, candle type, source, N and missing-data policy. Use the same settings in both calculations.
  2. Inspect all N historical CV weights, their sum and weighted source sum. Test the N = 2 example and a flat interval before testing entries.
  3. Define a close-cross event precisely: current close above current COVWMA and previous close at or below previous COVWMA, with both line values valid. A wick touch is a different event. Confirming the current chart bar adds waiting time.
  4. If adding ATR, distinguish a mean from a median. An ATR above its 20-bar SMA is above an average; it need not be rising on the current bar. Compare filtered and unfiltered rules on the same independent evaluation interval.
  5. Specify exits, fill timing, position size, spread, commission and slippage. For a hypothetical entry at 100 and stop reference 98, a gap fill at 96 loses 4 per unit before costs, twice the planned 2. A weighted average cannot cap that loss.

There is no best timeframe, coin or stock established by this calculation. Length 14 is the product's starting value; changing it affects both rolling operations. A bullish cross says where two series stand relative to each other, not that buying pressure has been measured.

Adapt the formula with Pineify

The Visual Editor exposes COVWMA source and length before generation. The Pine Script AI Coding Agent can help write a version with explicit inputs and data guards. Check the generated source and its numerical behavior; generation speed or profitable signals are not promised.

Keep the two-stage COVWMA weighting. Add editable source and length inputs, require length at least 2, and define behavior for nonpositive rolling means, missing values and a zero total weight. Expose CV, weight sum and weighted source sum in the Data Window. Compare the 100, 110, 90 example at length 2 before adding closed-bar alerts.
Open Pine Script AI Coding Agent

COVWMA questions

Each source observation receives the standard deviation divided by the mean of the window ending on that observation. The final average uses the latest N observations and their own historical CV values. A weight describes a rolling window, not the movement inside one candle.

No. Only relative weights within the averaging window matter. Multiplying every weight by the same positive constant leaves the average unchanged. An older high-CV observation can retain more weight than the current one.

With finite nonnegative weights and a positive weight sum, it stays between the minimum and maximum of the averaged observations. Negative rolling means can create negative weights and break that bound. The displayed code does not reject those cases.

A constant positive source gives standard deviation zero and CV zero. Once every weight in the final window is zero, the formula divides zero by zero. Returning the source or an SMA would be an explicit fallback, which this code does not implement.

The copied example hardcodes close and 14 and has no input controls. Edit that call or request a version with explicit inputs. The Visual Editor exposes source and length before generation; those builder controls are separate from the copied script.

No best market, timeframe or length is established here. Length changes both the CV calculation window and the weighted-average window. Compare values and crossing rules on the same data before evaluating a strategy with exits and costs.

Sources and related calculations

Formula reviewed against Pineify's COVWMA implementation on October 20, 2026. Numerical cases are reproducible examples, not market observations.