PINE LIBRARY
AxiomMovingAverageLibrary

Axiom Moving Average Library
Overview
If your Pine script offers a moving average type selector, you have probably written the same dispatch logic more than once. An enum, a switch, and a quiet hope that the next script you copy it into stays consistent with the last one.
This library replaces that pattern. Import it, use the MaType enum for your dropdown, and call get_ma() to route the user's choice to the right computation. Eight standard moving average types — SMA, EMA, RMA, WMA, VWMA, HMA, and SWMA — all backed by Pine's built-in ta.* functions. Nothing custom under the hood.
Why it exists
This is a maintenance problem, and it compounds.
Every Axiom indicator and strategy that gives users a moving average choice needs the same underlying infrastructure: a type list, a dispatcher, and correct parameter handling for each type. When that logic lives inside every script individually, it drifts. One script picks up HMA support; another doesn't. A third gets the defaults wrong. None of this is visible until someone notices that the same configuration produces different behavior across two Axiom tools.
That kind of inconsistency doesn't announce itself — it just erodes confidence in the products over time.
This library makes the dispatch code shared. Every consuming script references the same enum, calls the same wrappers, and gets the same result for the same inputs. The repetitive parts stay consistent so you can focus on the work that's actually yours — choosing which averages to offer, deciding what lengths make sense, and building the logic around the result. The plumbing shouldn't be something you rewrite every time.
Quickstart
Pine Script®
Import the library, give your users a dropdown, and route their selection through get_ma(). That covers the standard integration.
Recommended alias: maLib — short, and it distinguishes this from the Pro library if you end up using both.
API
The library exports three things: an enum, eight individual wrapper functions, and one dispatcher.
MaType enum
Eight values, each mapping to a standard moving average:
The enum works directly with input.enum(), so you can wire it into a settings dropdown without building your own type list.
Wrapper functions
Each type has a named function: ma_sma(src, length), ma_ema(src, length), ma_rma(src, length), ma_wma(src, length), ma_vwma(src, length), ma_hma(src, length), and ma_swma(src).
Two behaviors worth knowing before you use them:
get_ma dispatcher
Accepts a MaType value and routes to the correct wrapper. If an unrecognized value reaches the switch, it falls back to SMA as a safety net.
Examples
Direct wrapper call
When you only need one moving average type and don't need a dropdown:
Pine Script®
For a single MA type in a single script, a direct ta.ema(close, 20) is simpler and carries no dependency. The library earns its keep when you need the shared enum or when multiple scripts need to stay in sync.
User-selectable dropdown
The most common pattern — let users pick the MA type from a settings menu:
Pine Script®
Watch for: VWMA on symbols without volume
ta.vwma requires volume data. On symbols that don't report volume — some forex feeds, certain indices — the result is na. The library does not guard against this. If your script includes VWMA as an option, handle the no-volume case in your own code.
FAQ
What's the difference between Lite and Pro?
Lite covers eight standard moving averages. Each one wraps a Pine built-in — no custom math involved. The Pro library adds thirteen additional types on top of those eight, including DEMA, TEMA, KAMA, JMA, FRAMA, T3MA, VAMA, ZLMA, ZLEMA, Laguerre, and McGinley variants. If your needs outgrow the standard eight, that's when Pro becomes relevant.
Why doesn't SWMA accept a length?
That's a Pine constraint. ta.swma applies a fixed symmetrical weighting across 4 bars. There is no length parameter to pass, so the wrapper doesn't accept one either. If you route through get_ma with MaType.SWMA, the length argument is there for API consistency but doesn't affect the output.
Can I use VWMA on any symbol?
Only on symbols that report volume data. On instruments without volume, VWMA returns na. The library won't catch that for you — if your script offers VWMA, check for volume data and handle the na case in your own code.
What Pine version do I need?
Pine v6. The library uses v6 enum syntax, so scripts on v5 or earlier cannot import it.
Limitations
Versioning and release notes
Pin your import to a specific version number you have actually verified in the environment where you are using the library:
import AxiomCharts/AxiomMovingAverageLibrary/<version>
If you later need to move from Lite to Pro, expect changes: a different library title and an expanded MaType enum with additional values. It's not a drop-in swap — your code will need updating.
Support and training
Visit our website at axiomcharts.com for any documentation or questions.
Disclaimer
This library is published for educational and informational purposes. It provides standardized moving average computation utilities for Pine Script developers. It does not generate trading signals, recommend positions, or guarantee any financial outcome. All trading decisions and their consequences are yours. Use this library as one part of your own research and process.
Overview
If your Pine script offers a moving average type selector, you have probably written the same dispatch logic more than once. An enum, a switch, and a quiet hope that the next script you copy it into stays consistent with the last one.
This library replaces that pattern. Import it, use the MaType enum for your dropdown, and call get_ma() to route the user's choice to the right computation. Eight standard moving average types — SMA, EMA, RMA, WMA, VWMA, HMA, and SWMA — all backed by Pine's built-in ta.* functions. Nothing custom under the hood.
Why it exists
This is a maintenance problem, and it compounds.
Every Axiom indicator and strategy that gives users a moving average choice needs the same underlying infrastructure: a type list, a dispatcher, and correct parameter handling for each type. When that logic lives inside every script individually, it drifts. One script picks up HMA support; another doesn't. A third gets the defaults wrong. None of this is visible until someone notices that the same configuration produces different behavior across two Axiom tools.
That kind of inconsistency doesn't announce itself — it just erodes confidence in the products over time.
This library makes the dispatch code shared. Every consuming script references the same enum, calls the same wrappers, and gets the same result for the same inputs. The repetitive parts stay consistent so you can focus on the work that's actually yours — choosing which averages to offer, deciding what lengths make sense, and building the logic around the result. The plumbing shouldn't be something you rewrite every time.
Quickstart
Import the library, give your users a dropdown, and route their selection through get_ma(). That covers the standard integration.
Recommended alias: maLib — short, and it distinguishes this from the Pro library if you end up using both.
API
The library exports three things: an enum, eight individual wrapper functions, and one dispatcher.
MaType enum
Eight values, each mapping to a standard moving average:
- MaType.SMA - Simple Moving Average
- MaType.EMA - Exponential Moving Average
- MaType.RMA - Wilder / Relative Moving Average
- MaType.WMA - Weighted Moving Average
- MaType.VWMA - Volume-Weighted Moving Average
- MaType.HMA - Hull Moving Average
- MaType.SWMA - Symmetrically Weighted Moving Average
The enum works directly with input.enum(), so you can wire it into a settings dropdown without building your own type list.
Wrapper functions
Each type has a named function: ma_sma(src, length), ma_ema(src, length), ma_rma(src, length), ma_wma(src, length), ma_vwma(src, length), ma_hma(src, length), and ma_swma(src).
Two behaviors worth knowing before you use them:
- SWMA takes no length. Pine's ta.swma applies a fixed symmetrical weighting over 4 bars. The wrapper accepts src only. If you route through get_ma with MaType.SWMA, the length argument is accepted for signature consistency but ignored. The window is always 4.
get_ma dispatcher
Accepts a MaType value and routes to the correct wrapper. If an unrecognized value reaches the switch, it falls back to SMA as a safety net.
Examples
Direct wrapper call
When you only need one moving average type and don't need a dropdown:
For a single MA type in a single script, a direct ta.ema(close, 20) is simpler and carries no dependency. The library earns its keep when you need the shared enum or when multiple scripts need to stay in sync.
User-selectable dropdown
The most common pattern — let users pick the MA type from a settings menu:
Watch for: VWMA on symbols without volume
ta.vwma requires volume data. On symbols that don't report volume — some forex feeds, certain indices — the result is na. The library does not guard against this. If your script includes VWMA as an option, handle the no-volume case in your own code.
FAQ
What's the difference between Lite and Pro?
Lite covers eight standard moving averages. Each one wraps a Pine built-in — no custom math involved. The Pro library adds thirteen additional types on top of those eight, including DEMA, TEMA, KAMA, JMA, FRAMA, T3MA, VAMA, ZLMA, ZLEMA, Laguerre, and McGinley variants. If your needs outgrow the standard eight, that's when Pro becomes relevant.
Why doesn't SWMA accept a length?
That's a Pine constraint. ta.swma applies a fixed symmetrical weighting across 4 bars. There is no length parameter to pass, so the wrapper doesn't accept one either. If you route through get_ma with MaType.SWMA, the length argument is there for API consistency but doesn't affect the output.
Can I use VWMA on any symbol?
Only on symbols that report volume data. On instruments without volume, VWMA returns na. The library won't catch that for you — if your script offers VWMA, check for volume data and handle the na case in your own code.
What Pine version do I need?
Pine v6. The library uses v6 enum syntax, so scripts on v5 or earlier cannot import it.
Limitations
- Pine v6 required. Scripts on earlier versions cannot import this library.
- Eight standard types only. Adaptive averages (KAMA, JMA, FRAMA), lag-compensated filters (T3MA, ZLMA, McGinley), and other specialized types are not included. The Pro library covers those.
- SWMA uses a fixed 4-bar window. The length parameter passed through get_ma is ignored for SWMA.
- VWMA needs volume data. On symbols without volume, it returns na. Your script should account for this.
- The SMA fallback is a safety net, not a feature. If an unrecognized value reaches get_ma, it defaults to SMA. In practice, Pine's enum type system prevents this at compile time. Don't build routing logic around it.
Versioning and release notes
Pin your import to a specific version number you have actually verified in the environment where you are using the library:
import AxiomCharts/AxiomMovingAverageLibrary/<version>
If you later need to move from Lite to Pro, expect changes: a different library title and an expanded MaType enum with additional values. It's not a drop-in swap — your code will need updating.
Support and training
Visit our website at axiomcharts.com for any documentation or questions.
Disclaimer
This library is published for educational and informational purposes. It provides standardized moving average computation utilities for Pine Script developers. It does not generate trading signals, recommend positions, or guarantee any financial outcome. All trading decisions and their consequences are yours. Use this library as one part of your own research and process.
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
Website: axiomcharts.com
Training & Docs: docs.axiomcharts.com
Feedback: feedback.axiomcharts.com
Training & Docs: docs.axiomcharts.com
Feedback: feedback.axiomcharts.com
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
Website: axiomcharts.com
Training & Docs: docs.axiomcharts.com
Feedback: feedback.axiomcharts.com
Training & Docs: docs.axiomcharts.com
Feedback: feedback.axiomcharts.com
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。