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.
| Observation | Source | CV window | Mean | SD | CV | Source × CV |
|---|---|---|---|---|---|---|
| 2 | 110 | 100, 110 | 105 | 5 | 1/21 ≈ 0.047619 | 110/21 ≈ 5.238095 |
| 3 | 90 | 110, 90 | 100 | 10 | 0.1 | 9 |
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.
// 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.

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
| Average | Weight rule |
|---|---|
| SMA | Equal weights over the window |
| Linear WMA | Weights increase with recency |
| EMA | Recursive exponential weighting with alpha set by length |
| VWMA | Reported bar volume within the window |
| COVWMA | Each 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
- Record the symbol, venue, session, candle type, source, N and missing-data policy. Use the same settings in both calculations.
- Inspect all N historical CV weights, their sum and weighted source sum. Test the N = 2 example and a flat interval before testing entries.
- 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.
- 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.
- 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
Sources and related calculations
Formula reviewed against Pineify's COVWMA implementation on October 20, 2026. Numerical cases are reproducible examples, not market observations.