This new version of the script is significantly more flexible and powerful compared to the old version. First, it has been updated from Pine Script version 5 to version 6, which makes it compatible with newer TradingView features and functions. Instead of plotting one moving average at a time, the new script lets you apply up to three layers of smoothing in sequence. You can enable each smoothing layer independently, choose from many different types of moving averages, and set a custom length for each layer. This chain-like approach (where the output of one layer is fed into the next) offers more adaptability in analyzing market trends.
In the old script, you had a handful of predefined moving averages like SMA, EMA, WMA, HMA, and KAMA, each with its own length input. You would toggle them on or off individually, and you could also toggle volume plotting features. The calculations were mostly done by hand-coded loops, such as summing up the last N bars for the custom SMA or using a custom loop for EMA. That approach works but is less efficient and less flexible when you want to add more complex moving averages.
In the new version, each moving average type is its own function. Whenever the user chooses a specific MA type, the script calls the corresponding function. Examples include SMA (simple average of recent prices), EMA (exponential average that places more weight on recent values), WMA (weighted average that applies different weights to each bar), and more advanced forms like KAMA (Kaufman’s Adaptive MA, which changes its smoothing based on market volatility), HMA (Hull MA, designed to reduce lag while remaining smooth), DEMA (Double EMA), TEMA (Triple EMA), VWMA (Volume Weighted MA), ZLEMA (Zero-Lag EMA), ALMA (Arnaud Legoux MA), and many others. Each function encapsulates its own logic for calculating that specific moving average. For instance, the f_ema function calls TradingView’s built-in ta.ema, whereas f_hma implements the Hull MA logic by applying WMA to a WMA difference. This modular approach is much easier to maintain and extend, because you can just add a new function without rewriting the entire script.
Another difference is that you can now enable or disable each smoothing step with a simple boolean input. For example, Enable Smoothing #1 is turned on by default, while Smoothing #2 and #3 are optional. If you enable Smoothing #2 or Smoothing #3, it takes the output of the previous step as its input. This layered smoothing can produce very different results compared to traditional single-step moving averages because you might, for example, smooth the data with a fast HMA first, then apply a slower EMA, and finally a third pass using something like ZLEMA. Each step has its own dropdown menu to pick the type of moving average and a length input to define how many bars it considers.
Additionally, the new version colors the final smoothed line based on its slope. If the current value is higher than the previous bar, it plots the line in green; otherwise, it plots it in red. This helps you visually identify whether the final moving average is rising or falling at each bar.
Finally, the old script included optional volume features that allowed you to plot average volume or color bars based on a high-volume threshold. The new script is more focused on the moving averages themselves and includes a volume-weighted option (VWMA) if users want to incorporate volume data into their smoothing. If you wanted the same volume plot features from the old script, you could easily add them back or create a separate script, but the new version is primarily dedicated to multi-step, user-configurable moving averages.
Regarding what each moving average does in a broad sense: SMA (simple moving average) is a straightforward average of the most recent N prices. EMA (exponential moving average) applies exponential weighting to recent prices, giving them more influence and usually reacting faster to changes than SMA. WMA and LWMA (linearly weighted) both give different weights to each bar; often more weight is put on the most recent bar. HMA, or Hull MA, is specifically designed to reduce lag while preserving smoothness by combining WMA calculations in a particular way. DEMA and TEMA try to further reduce lag by applying EMA calculations multiple times. Adaptive averages like KAMA or VIDYA adjust their smoothing speed based on recent volatility, attempting to smooth out noise while still reacting quickly to genuine market changes. ZLEMA tries to remove lag by adjusting the input data so the resulting average reacts more quickly. VWMA weights each price by the trading volume for that bar. Other specialized filters like FRAMA, Butterworth, or McGinley Dynamic also exist, each using unique math to adapt to price changes in different ways.
In short, the new version:
1. Uses Pine Script version 6.
2. Lets you apply up to three smoothing steps in sequence.
3. Supports a wide variety of moving average types, each with its own function.
4. Eliminates the need to manually code loops for common MAs by leveraging built-in functions or concise logic blocks.
5. Colors the final output based on slope.
6. Provides a more modular, extendable design for future enhancements.
In the new version, the volume-based visualization features from the old script, such as high-volume bar coloring and average volume plotting, have been removed. Instead, users who want to incorporate volume data can use the VWMA (Volume-Weighted Moving Average) option as one of the smoothing types. This change keeps the script focused on multi-step moving average smoothing while still providing a way to factor in volume when needed.