Moving Average Compendium===========
Moving Average Compendium (16 MA Types)
===========
A selection of the most popular, widely used, interesting and most powerful Moving Averages we can think of. We've compiled 16 MA's into this script, and allowed full access to the source code so you can use what you need, as you need it.
-----------
From very simple moving averages using built-in functions, all the way through to Fractal Adaptive Averages, we've tried to cover as much as we can think of! BUT, if you would like to make a suggestion or recommendation to be added to this compendium of MA's please let us know! Together we can get a complete list of many dozens of types of Moving Average.
Full List (so far)
---
SMA - Simple Moving Average
EMA - Exponential Moving Average
WMA - Weighted Moving Average
VWMA - Volume Weighted Moving Average
DEMA - Double Exponential Moving Average
TEMA - Triple Exponential Moving Average
SMMA - Smoothed Moving Average
HMA - Hull Moving Average
ZLEMA - Zero-Lag Exponential Moving Average
KAMA - Kaufman Adaptive Moving Average
JMA - Jurik Moving Average
SWMA - Sine-Weighted Moving Average
TriMA - Triangular Moving Average
MedMA - Moving Median Average
GeoMA - Geometric Mean Moving Average
FRAMA - Fractal Adaptive Moving Average
Line color changes from green (upward) to red (downward) - some of the MA types will "linger" without moving up or down and when they are in this state they should appear gray in color.
Thanks to all involved -
Good Luck and Happy Trading!
Hull
CBG MultiAverages ColorsThe latest version of my multiple moving averages. Now includes up to 14 moving averge lines plus a separate slow and fast moving average that can be assigned a different MA type.
In the screen shot is the fast/slow set to Hull with 15/50 periods. It is overlaid on top of my Key Numbers indicator.
7 moving averages in 1 indicator, including the Hull Moving Average .
SMA
EMA
Weighted
Hull
Symetrical
Volume Weighted
Wilder
Linear Regression
Lots of other features like background shading and paint bar colors.
Zero Lag Keltner ChannelsThis is Keltner Channelz (KC) with Zero Lag Moving Average (ZLMA as base). It is smoother and has less lag than the original (EMA/SMA) variant.
It also can be used as a trend indicator and trend confirmation indicator. The upper and lower bands are green if it is an up trend, and red if a down trend. If both have the same color it is a stronger trend.
HEMA - A Fast And Efficient Estimate Of The Hull Moving AverageIntroduction
The Hull moving average (HMA) developed by Alan Hull is one of the many moving averages that aim to reduce lag while providing effective smoothing. The HMA make use of 3 linearly weighted (WMA) moving averages, with respective periods p/2 , p and √p , this involve three convolutions, which affect computation time, a more efficient version exist under the name of exponential Hull moving average (EHMA), this version make use of exponential moving averages instead of linearly weighted ones, which dramatically decrease the computation time, however the difference with the original version is clearly noticeable.
In this post an efficient and simple estimate is proposed, the estimation process will be fully described and some comparison with the original HMA will be presented.
This post and indicator is dedicated to LucF
Estimation Process
Estimating a moving average is easier when we look at its weights (represented by the impulse response), we basically want to find a similar set of weights via more efficient calculations, the estimation process is therefore based on fully understanding the weighting architecture of the moving average we want to estimate.
The impulse response of an HMA of period 20 is as follows :
We can see that the first weights increases a bit before decaying, the weights then decay, cross under 0 and increase again. More recent closing price values benefits of the highest weights, while the oldest values have negatives ones, negative weighting is what allow to drastically reduce the lag of the HMA. Based on this information we know that our estimate will be a linear combination of two moving averages with unknown coefficients :
a × MA1 + b × MA2
With a > 0 and b < 0 , the lag of MA1 is lower than the lag of MA2 . We first need to capture the general envelope of the weights, which has an overall non-linearly decaying shape, therefore the use of an exponential moving average might seem appropriate.
In orange the impulse response of an exponential moving average of period p/2 , that is 10. We can see that such impulse response is not a bad estimate of the overall shape of the HMA impulse response, based on this information we might perform our linear combination with a simple moving average :
2EMA(p/2) + -1SMA(p)
this gives the following impulse response :
As we can see there is a clear lack of accuracy, but because the impulse response of a simple moving is a constant we can't have the short increasing weights of the HMA, we therefore need a non-constant impulse response for our linear combination, a WMA might be appropriate. Therefore we will use :
2WMA(p/2) + -1EMA(p/2)
Note that the lag a WMA is inferior to the lag of an EMA of same period, this is why the period of the WMA is p/2 . We obtain :
The shape has improved, but the fit is poor, which mean we should change our coefficients, more precisely increasing the coefficient of the WMA (thus decreasing the one of the EMA). We will try :
3WMA(p/2) + -2EMA(p/2)
We then obtain :
This estimate seems to have a decent fit, and this linear combination is therefore used.
Comparison
HMA in blue and the estimate in fuchsia with both period 50, the difference can be noted, however the estimate is relatively accurate.
In the image above the period has been set to 200.
Conclusion
In this post an efficient estimate of the HMA has been proposed, we have seen that the HMA can be estimated via the linear combinations of a WMA and an EMA of each period p/2 , this isn't important for the EMA who is based on recursion but is however a big deal for the WMA who use recursion, and therefore p indicate the number of data points to be used in the convolution, knowing that we use only convolution and that this convolution use twice less data points then one of the WMA used in the HMA is a pretty great thing.
Subtle tweaking of the coefficients/moving averages length's might help have an even more accurate estimate, the fact that the WMA make use of a period of √p is certainly the most disturbing aspect when it comes to estimating the HMA. I also described more in depth the process of estimating a moving average.
I hope you learned something in this post, it took me quite a lot of time to prepare, maybe 2 hours, some pinescripters pass an enormous amount of time providing content and helping the community, one of them being LucF, without him i don't think you'll be seeing this indicator as well as many ones i previously posted, I encourage you to thank him and check his work for Pinecoders as well as following him.
Thanks for reading !
MasterMAThis study demonstrates 15 different common moving averages.
SMA, Double SMA, Triple SMA
EMA, Double EMA, Triple EMA
WMA, Double WMA, Triple WMA
VWMA, Double VWMA, Triple VWMA
Hull, Double Hull, Triple Hull
Buy/Sell alerts are given for crossover/under conditions.
Triangles at the bottom, pointing up are buy signals. Triangles at the top, pointing down, are sell signals
Hull 2xPlots 2 Hull MA's, 1 Fast and 1 Slow
Can Paint Bars according to Hull MA Cross
Buy / Sell Alerts for MA Crossing
TSI CCI HullThis is TSI and CCI combined. The CCI is customized and is using HullMA, but the TSI is default TSI
For use with the HMAv420 indicator, to form trading strategy based on the 3 indicators.
Best as all 3 indicators used on 3 timeframes at once, ie 1m 5m 1H
Triple Hull Moving AverageCalculates and plots 3 Hull Moving Averages. Color of plot changes to indicate positive or negative slope. Original Hull MA code written by mohamed982.
Hull SuiteHull is its extremely responsive and smooth moving average created by Alan Hull in 2005.
Minimal lag and smooth curves made HMA extremely popular TA tool.
alanhull.com
Script was made to regroup multiple hull variants in one indicator,maintaining flexible customization and intuitive visualization
Option to chose between 3 Hull variations
Option to chose between 2 visualization modes ( Bands or single line)
Option to Paint hull and/or candlesticks according to hulls trend
Shortcut for personalizing Line/band thickness,instead of changing every object manually ,there is global option in inputs
HMA
THMA ( 3HMA)
EHMA
HMA:
Alan Hull
EHMA:
Slower than hull by default.
Raudys, Aistis & Lenčiauskas, Vaidotas & Malčius, Edmundas. (2013). Moving Averages for Financial Data Smoothing ( 403. 34-45. 10.1007/978-3-642-41947-8_4.) Vilnius University, Faculty of Mathematics and Informatics
3HMA (THMA) :
Documentation on link below
alexgrover
Multiple HMA - bgeraghtyTo save space on a chart's maximum indicator count, this single indicator includes:
- Three Hull Moving Averages, Defaulted to 13, 26, and 55 Periods.
- Customizable Time-Frame for Each HMA.
- Customizable Triple Weighted MA Smoothing for Jagged Lines from Higher Time-Frame
- Alert Conditions for Price Cross Over/Under the HMAs.
Hull Trend with KahlmanThis is an update to the idea of
The Kahlman smoother makes the signal more precise (by one candle).
Hull TrendHere we are using Hull Moving Average crossovers as an experiment in trend detection.
The Hull Moving Average (HMA) is an extremely fast and smooth moving average.
Credit to alexgrover & RicardoSantos:
Keltner Channels around Hull MAKeltner Channels around Hull Moving Average
Script shared upon request. No guarantees on accuracy.
Parabolic Hull MA [wm]
Based on Everget's Parabolic WMA and Mladen MT5 Hull MA.
Power = 1 behaves the same as a standard HMA , > 1 speeds it up, < 1 slows it down
HMA ColoredThis is a typical hull moving average that is colored based on if the average is increasing or decreasing.
Hull MAThis Hull MA uses the default settings of the built-in MA. The basic idea is that we are in a buy setup when hull is below price, and a sell setup when hull is above price. The indicator is extended with slightly change in contrast when moving average is declining and it plot the ma/price crossovers: green dot when a buy setup is appearing, and red dot when a sell setup is forming. It is possible to hide crossovers in the option panel.
Three alert conditions is added "Hull MA cross", "Hull MA sell" and "Hull MA buy". I use "Hull MA cross" on slow frames (2w, M) and "Hull MA buy/sell" on faster frames.
ATR smoothed by Hull MAThis is Average True Range indicator, but it is smoothed with Hull MA ( not WMA etc )
It is set to overlay the candles so looks different from normal ATR but i assure you it is ATR
Script open so you can see for yourself.
perhaps different settings are better,
Help me test it, and suggest improvements thankyou
Multi SMA EMA WMA HMA BB (5x8 MAs Bollinger Bands) MAX MTF - RRBMulti SMA EMA WMA HMA 4x7 Moving Averages with Bollinger Bands MAX MTF by RagingRocketBull 2019
Version 1.0
All available MAX MTF versions are listed below (They are very similar and I don't want to publish them as separate indicators):
ver 1.0: 4x7 = 28 MTF MAs + 28 Levels + 3 BB = 59 < 64
ver 2.0: 5x6 = 30 MTF MAs + 30 Levels + 3 BB = 63 < 64
ver 3.0: 3x10 = 30 MTF MAs + 30 Levels + 3 BB = 63 < 64
ver 4.0: 5(4+1)x8 = 8 CurTF MAs + 32 MTF MAs + 20 Levels + 3 BB = 63 < 64
ver 5.0: 6(5+1)x6 = 6 CurTF MAs + 30 MTF MAs + 24 Levels + 3 BB = 63 < 64
ver 6.0: 4(3+1)x10 = 10 CurTF MAs + 30 MTF MAs + 20 Levels + 3 BB = 63 < 64
Fib numbers: 8, 13, 21, 34, 55, 89, 144, 233, 377
This indicator shows multiple MAs of any type SMA EMA WMA HMA etc with BB and MTF support, can show MAs as dynamically moving levels.
There are 4 MA groups + 1 BB group, a total of 4 TFs * 7 MAs = 28 MAs. You can assign any type/timeframe combo to a group, for example:
- EMAs 9,12,26,50,100,200,400 x H1, H4, D1, W1 (4 TFs x 7 MAs x 1 type)
- EMAs 8,13,21,30,34,50,55,89,100,144,200,233,377,400 x M15, H1 (2 TFs x 14 MAs x 1 type)
- D1 EMAs and SMAs 8,13,21,30,34,50,55,89,100,144,200,233,377,400 (1 TF x 14 MAs x 2 types)
- H1 WMAs 13,21,34,55,89,144,233; H4 HMAs 9,12,26,50,100,200,400; D1 EMAs 12,26,89,144,169,233,377; W1 SMAs 9,12,26,50,100,200,400 (4 TFs x 7 MAs x 4 types)
- +1 extra MA type/timeframe for BB
There are several versions: Simple, MTF, Pro MTF, Advanced MTF, MAX MTF and Ultimate MTF. This is the MAX MTF version. The Differences are listed below. All versions have BB
- Simple: you have 2 groups of MAs that can be assigned any type (5+5)
- MTF: +2 custom Timeframes for each group (2x5 MTF) +1 TF for BB, TF XY smoothing
- Pro MTF: 4 custom Timeframes for each group (4x3 MTF), 1 TF for BB, MA levels and show max bars back options
- Advanced MTF: +4 extra MAs/group (4x7 MTF), custom Ticker/Symbols, Timeframe <>= filter, Remove Duplicates Option
- MAX MTF: +2 subtypes/group, packed to the limit with max possible MAs/TFs: 4x7, 5x6, 3x10, 4(3+1)x10, 5(4+1)x8, 6(5+1)x6
- Ultimate MTF: +individual settings for each MA, custom Ticker/Symbols
MAX MTF version tests the limits of Pinescript trying to squeeze as many MAs/TFs as possible into a single indicator.
It's basically a maxed out Advanced version with subtypes allowing for mixed types within a group (i.e. both emas and smas in a single group/TF)
Pinescript has the following limits:
- max 40 security calls (6 calls are reserved for dupe checks and smoothing, 2 are used for BB, so only 32 calls are available)
- max 64 plot outputs (BB uses 3 outputs, so only 61 plot outputs are available)
- max 50000 (50kb) size of the compiled code
Based on those limits, you can only have the following MAs/TFs combos in a single script:
1. 4x7, 5x6, 3x10 - total number of MTF MAs must always be <= 32, and you can still have BB and Num Levels = total MAs, without any compromises
2. 5(4+1)x8, 6(5+1)x6, 4(3+1)x10 - you can use the Current Symbol/Timeframe as an extra (+1) fixed TF with the same number of MTF MAs
- you don't need to call security to display MAs on the Current Symbol/Timeframe, so the total number of MTF MAs remains the same and is still <= 32
- to fit that many MAs into the max 64 plot outputs limit you need to reduce the number of levels (not every MA Group will have corresponding levels)
Features:
- 4x7 = 28 MAs of any type
- 4x MTF groups with XY step line smoothing
- +1 extra TF/type for BB MAs
- 2 MA subtypes within each group/TF
- 4x7 = 28 MA levels with adjustable group offsets, indents and shift
- supports any existing type of MA: SMA, EMA, WMA, Hull Moving Average (HMA)
- custom tickers/symbols for each group
- show max bars back option
- show/hide both groups of MAs/levels/BB and individual MAs
- timeframe filter: show only MAs/Levels with TFs <>= Current TF
- hide MAs/Levels with duplicate TFs
- support for custom TFs that are not available in free accounts: 2D, 3D etc
- support for timeframes in H: H, 2H, 4H etc
Notes:
- Uses timeframe textbox instead of input resolution dropdown to allow for 240 120 and other custom TFs
- Uses symbol textbox instead of input symbol to avoid establishing multiple dummy security connections to the current ticker - otherwise empty symbols will prevent script from running
- Possible reasons for missing MAs on a chart:
- there may not be enough bars in history to start plotting it. For example, W1 EMA200 needs at least 200 bars on a weekly chart.
- for charts with low/fractional prices i.e. 0.00002 << 0.001 (default Y smoothing step) decrease Y smoothing as needed (set Y = 0.0000001) or disable it completely (set X,Y to 0,0)
- for charts with high price values i.e. 20000 >> 0.001 increase Y smoothing as needed (set Y = 10-20). Higher values exceeding MAs point density will cause it to disappear as there will be no points to plot. Different TFs may require diff adjustments
- TradingView Replay Mode UI and Pinescript security calls are limited to TFs >= D (D,2D,W,MN...) for free accounts
- attempting to plot any TF < D1 in Replay Mode will only result in straight lines, but all TFs will work properly in history and real-time modes. This is not a bug.
- Max Bars Back (num_bars) is limited to 5000 for free accounts (10000 for paid), will show error when exceeded. To plot on all available history set to 0 (default)
- Slow load/redraw times. This indicator becomes slower, its UI less responsive when:
- Pinescript Node.js graphics library is too slow and inefficient at plotting bars/objects in a browser window. Code optimization doesn't help much - the graphics engine is the main reason for general slowness.
- the chart has a long history (10000+ bars) in a browser's cache (you have scrolled back a couple of screens in a max zoom mode).
- Reload the page/Load a fresh chart and then apply the indicator or
- Switch to another Timeframe (old TF history will still remain in cache and that TF will be slow)
- in max possible zoom mode around 4500 bars can fit on 1 screen - this also slows down responsiveness. Reset Zoom level
- initial load and redraw times after a param change in UI also depend on TF. For example: D1/W1 - 2 sec, H1/H4 - 5-6 sec, M30 - 10 sec, M15/M5 - 4 sec, M1 - 5 sec. M30 usually has the longest history (up to 16000 bars) and W1 - the shortest (1000 bars).
- when indicator uses more MAs (plots) and timeframes it will redraw slower. Seems that up to 5 Timeframes is acceptable, but 6+ Timeframes can become very slow.
- show_last=last_bars plot limit doesn't affect load/redraw times, so it was removed from MA plot
- Max Bars Back (num_bars) default/custom set UI value doesn't seem to affect load/redraw times
- In max zoom mode all dynamic levels disappear (they behave like text)
- Dupe check includes symbol: symbol, tf, both subtypes - all must match for a duplicate group
- For the dupe check to work correctly a custom symbol must always include an exchange prefix. BB is not checked for dupes
Good Luck! Feel free to learn from/reuse the code to build your own indicators.
Dickinson Moving Average (DMA)Implementation of the "Dickinson Moving Average" from the r/algotrading post by Nathan Dickinson
Quoted from the author of the Dickinson Moving Average:
"I was experimenting with the “zero lag” code from John Ehlers and the Hull Moving Average and noticed that they seemed to respond in complementary ways when properly set up. With the right starting values, they blend together to make a moving average which responds with one (or maybe even half a bar) of lag. To my eye, it looks to be almost as good as the Jurik Moving Average."
Optional parameter input available to use Exponential Hull Moving Average (EHMA) instead of WMA for the Hull MA is available.
Acknowledgements/Credits:
Nathan Dickinson, Dickinson Moving Average
@RicardoSantos, Function for Hull Moving Average
Exponential Hull Moving Average sourced from:
// Raudys, Aistis & Lenčiauskas, Vaidotas & Malčius, Edmundas. (2013). Moving Averages for Financial Data Smoothing.
// Communications in Computer and Information Science. 403. 34-45. 10.1007/978-3-642-41947-8_4.
@Everget, Jurik Moving Average
Exponential Hull Moving Average (EHMA)Source for Exponential Hull Moving Average (EHMA) formula:
Raudys, Aistis & Lenčiauskas, Vaidotas & Malčius, Edmundas. (2013). Moving Averages for Financial Data Smoothing. Communications in Computer and Information Science. 403. 34-45. 10.1007/978-3-642-41947-8_4.
The Exponential Hull Moving Average is nearly identical to the Hull MA, but EMA used instead of WMA.
Credit to @RicardoSantos for the existing implementation of the Hull Moving Average in pinescript:
Hull MA BarsThis indicator fill bars with color of HullMA + warning yellow bars, then trend reversing
HullMA Strategy--HULL 20 Hisse senedinin hull moving average gibi hızlı bir hareketli ortalamada 20 li paremetrege performansını göstermektedir. Kodu trdingwiewswn alınmıştır.