Weighted Least Squares Moving AverageLinearly Weighted Ordinary Least Squares Moving Regression
aka Weighted Least Squares Moving Average -> WLSMA
^^ called it this way just to for... damn, forgot the word
Totally pwns LSMA for some purposes here's why (just look up):
- 'realistically' the same smoothness;
- less lag;
- less overshoot;
- more or less same computationally intensive.
"Pretty cool, huh?", Bucky Roberts©, thenewboston
Now, would you please (just look down) and see the comparison of impulse & step responses:
Impulse responses
Step responses
Ain't it beautiful?
"Motivation behind the concept & rationale", by gorx1
Many been trippin' applying stats methods that require normally distributed data to time series, hence all these B*ll**** Bands and stuff don't really work as it should, while people blame themselves and buy snake oil seminars bout trading psychology, instead of using proper tools. Price... Neither population nor the samples are neither normally nor log-normally distributed. So we can't use all the stuff if we wanna get better results. I'm not talking bout passing each rolling window to a stat test in order to get the proper descriptor, that's the whole different story.
Instead we can leverage the fact that our data is time-series hence we can apply linear weighting, basically we extract another info component from the data and use it to get better results. Volume, range weighting don't make much sense (saying that based on both common sense and test results). Tick count per bar, that would be nice tho... this is the way to measure "intensity". But we don't have it on TV unfortunately.
Anyways, I'm both unhappy that no1 dropped it before me during all these years so I gotta do it myself, and happy that I can give smth cool to every1
Here is it, for you.
P.S.: the script contains standalone functions to calculate linearly weighted variance, linearly weighted standard deviation, linearly weighted covariance and linearly weighted correlation.
Good hunting
Weighted
AveragesLibrary "Averages"
Contains utilities for generating averages from arrays. Useful for manipulated or cleaned data.
triangular(src, startingWeight) Calculates the triangular weighted average of a set of values where the last value has the highest weight.
Parameters:
src : The array to derive the average from.
startingWeight : The weight to begin with when calculating the average. Higher numbers will decrease the bias.
weighted(src, weights, weightDefault) Calculates the weighted average of a set of values.
Parameters:
src : The array to derive the average from.
weights : The array containing the weights for the source.
weightDefault : The default value to use when a weight is NA.
triangularWeighted(src, weights, startingWeight) Calculates the weighted average of a set of values where the last value has the highest triangular multiple.
Parameters:
src : The array to derive the average from.
weights : The array containing the weights for the source.
startingWeight : The multiple to begin with when calculating the average. Higher numbers will decrease the bias.
exponential(src) Calculates the exponential average of a set of values where the last value has the highest weight.
Parameters:
src : The array to derive the average from.
arrayFrom(src, len, omitNA) Creates an array from the provided series (oldest to newest).
Parameters:
src : The array to derive from.
len : The target length of the array.
omitNA : If true, NA values will not be added to the array and the resultant array may be shorter than the target length.
Banknifty Weighted volume by AkramulBanknifty Weighted volume as per share ratio.
HDFC Bank – 27.56%
ICICI Bank – 22.91%
State Bank of India (SBI) – 12.42%
Kotak Mahindra Bank – 11.77%
Axis Bank – 11.49%
IndusInd Bank – 5.20%
AU Small Finance Bank Ltd. – 2.35%
Bandhan Bank – 1.73%
Federal Bank – 1.53%
IDFC First Bank Ltd. – 1.22%
Punjab National Bank (PNB)- 1.03%
RBL Bank – 0.79%
and moving average plotted on volume
Volume, Momentum and Volatility weighted moving averageMoving averages are filters on price data. This moving average creates a filter which factors in:
- the price RSI or it's Momentum
- the volume RSI
- the RVI or Volatility
Each factor is put through a least squares filter to smooth them first.
Then the factors are used to build a coefficient for an exponentially weighted average.
The chart above shows a comparison of standard average types with this script.
This is useful if you are looking for a moving average based trigger and do not wish to react to candle noise price action.
Crypto Top 25 Equal Weight IndexDraws an Equally Weighted Index of 25 securities. The inputs are pre-populated with the Top 25 cryptocurrencies by market cap at the time of publishing the script, but any 25 securities can be used.
Double click on this indicator's pane to view in full screen.
Note: Candle open is always equal to previous candle's close. I did this to avoid problems where sometimes candle open didn't make sense compared to close.
If you're into cryptocurrencies also have a look at these TradingView charts CRYPTOCAP:TOTAL, CRYPTOCAP:TOTAL2 and CRYPTOCAP:OTHERS.
Moving Average Weighted, Volume AdjustedVAWMA = VWMA and WMA combined.
Simply put, this attempts to determine the average price per share over time, weighted heavier for recent values.
Uses triangular algorithm to taper off values in the past (same as WMA does).
Why use this?
Let's say the earliest bar of the VWMA has a huge amount of volume. That means that when the next bar arrives, there will be an abrupt change in the moving average that doesn't represent the current value properly. VAWMA eliminates this problem by triangular weighting each bar.
Weighted derivatives premium BTCCan be extended with more derivative or spot pairs, see the comments in the code for instructions. Most importantly, the pairs need to be added to the respective arrays in the same order, so that the weights are applied to the correct pairs.
Delta Volume Weighted - IntradayResets at the start of the day's session (9:50 am on the ASX).
Takes the first candle and checks if its a green candle (close > open), and adds the volume to a total (which starts at 0 at the start of the day).
Subtracts it if the candles in red.
Continues to do this along with all the candles.
The volume is also multiplied by the difference between open and close so that large candles with large volume have more weight and move the indicator more.
Volume Weighted DeviationsVolume !weighted!
deviations.
Important: I don't really know how people generally compute deviations from VWAP/VWMA, but smth tells me generally it's just a Av Dev/St Dev based on mean, not on appropriate basis, like volume weighted mean in our case. This version is mathematically correct, it first calculates weighted mean, than utilizes this weighted in mean in AvDev & StDef functions modified to take into account weights.
Volume-Weighted Indicators VWMA/VWAP/EMA_by WWAs traders and investors now urge to console volume factors into their price action analysis. This script is an attempt to combine volume-weighted moving average (VWMA), volume-weighted average price (VWAP), along with the exponential moving average (EMA). I have found that this indicator works quite well with the stock market.
How to use the indicator:
Buy when the VWAP and EMA lines crossing up VWMA.
Sell when the VWAP and EMA crossing down each other OR both VWAP and EMA crossing down VWAP
Any modificatio is welcomed, but please let me know.
Stochastic Weights - Basic [BigBitsIO]This script is a compilation of several different stochastic indicators (and RSI) where the K value of each indicator is equally weighted. The purpose of the indicator is to combine many indicators together in a fashion that weights them easier. By default, the Stochastic and Stochastic RSI are both enabled - the idea is to speed up the relatively slower Stochastic and to slow down the relatively fast Stochastic RSI. Other Stochastics are also available, including some of my own custom calculations that can also be added to the weighted calculation. Only the K value is weighted, as the D value is just a moving average of the weighted K.
Explained:
- Calculates enabled indicators
- Calculates the weighted value of K for enabled indicators
- Calculates a D value from the weighted K
FAQ:
- Why is this script useful?
- To weight multiple indicators together so that you can attempt to find optimal values shared amongst the indicators. Ex: If Stochastic RSI is 100 and Stochastic is 50, K would be 75 and not particularly high. If you add in a 50 RSI, the K would be 67 in this example. If we weight indicators together that all have a high value they could potentially help find elements that align together to produce a stronger signal.
DISCLAIMER: For educational and entertainment purposes only. Nothing in this content should be interpreted as financial advice or a recommendation to buy or sell any sort of security or investment including all types of crypto. DYOR, TYOB.
LWMA: Linear Weighted Moving AverageCouldn't find searching for Linearly Weighted Moving Average (LWMA) in tradingview. Found one with the LWMA title, but it uses plain WMA calculation without the linearity which more heavily weights recent price data, which I need, so I try to made one.
LWMAs are also quicker to react to price changes than SMA and EMA. If you want a moving average with less lag than an SMA, try a LWMA.
It kind of also have a more clarity in defining the price trend and reversals. Trade signals usually based on crossovers, they can also indicate areas of potential support or resistance. But beware though, multiple false signals may also occur before a significant trend develops. Use a filter, some decent volatility oscillator might do the job.
--
The formula for this Linearly Weighted Moving Average is:
LWMA = (( P n∗ W 1)+( P n−1∗ W 2)+( P n−2∗ W 3)...) / ∑W
P = Price for the period
n = The most recent period, n-1 is the prior period, and n-2 is two periods prior
W = The assigned weight to each period, with the highest weight going first and then descending linearly based on the number of periods being used.
I hope I'm doing right translating it to Pine Script 4. Let me know if I miss something.
Weighted Close [CC]The weighted close isn't an option for an input yet on TV so here is my contribution. It gives more weight to the close prices and I have included a signal line to look for buy and sell signals. Buy when the indicator goes over its signal line and sell when it falls below it.
This was a special request so let me know what other scripts you would like to see me publish or if you want something custom done!
End Point Moving Average [CC]The End Point Moving Average was created by Patrick E. Lafferty (Stocks & Commodities V13 (413-417)) and it is essentially a variation of the weighted moving average but the weight system is different. Feel free to change the offset and length amounts to adjust to your needs but I'm using the default amounts in my script. This hugs the price very closely and I think you will enjoy this script as much as I had making it. As always buy when the indicator line is green and sell when it is red!
Let me know if you would like me to publish other scripts or if you want something custom done!
Note: I'm republishing this because the original script couldn't be found in searches so this will fix that.
CBG Swing HighLow MAThis indicator will show the swing high and lows for the number of bars back. It's very easy to use and shows good support and resistance levels.
I then took it a step further and added a moving average with all the standard types in my indicators:
SMA
EMA
Weighted
Hull
Symmetrical
Volume Weighted
Wilder
Linear Regression
I then added Bollinger Bands to show the standard deviation from the midline.
Finally, I added a simple bar coloring scheme: green if above the upper BB, Red if below and orange if in the middle.
I am just testing this out so please use with caution. If anyone in the community wants to run some backtests, that would be great and we would all appreciate it.
Of course you can keep it all simple and turn off all the moving averages and bollinger bands.
Enjoy! :-)
Cubed Weighted Moving AverageThis is another indicator that I have created that is my favorite script yet for a weighted moving average. This indicator is very similiar to a classic weighted moving average but in this version I'm cubing the weights. It hugs the price very closely as you can see and of course buy when the indicator line is green and sell when it is red.
Let me know if you would like me to publish other scripts or if you want something custom done!
Variable Power Weighted Moving AverageThe Variable Power Weighted Moving Average was created by RedKTrader so make sure you follow them! This is a very handy indicator where you can change the weights of the weighted moving average yourself!
For an easy guide here are common values to use to convert this indicator into other indicators:
Power = 0 = Simple Moving Average
Power = 0.5 = Square Root Weighted Moving Average
Power = 1 = Weighted Moving Average
Power = 2 = Squared Weighted Moving Average
Try it out and let me know what you think!
Let me know if you have other ideas for me or if you want something custom done!
Optimal Weighted Moving AverageThe Optimal Weighted Moving Average was created by Thomas Hutchinson and Peter G. Zhang, Ph.D. (Stocks & Commodities V. 11:12 (500-505)) and it is very similar to a classic weighted moving average but it uses the correlation between the input and the optimal weighted moving average output to use as the weights. Buy when the line turns green and sell when it turns red.
Let me know if you would like to see me publish any other scripts or if you want something custom done!
TA Basics: Creating a Fibonacci Weighted Moving AverageIn the previous 2 posts in this series, we played around with simple math concepts to create a zero-lag moving average that can deliver fast response and less lag - that we can use to enable better trend following, or as filter / signal.
here we take a step further - instead of using equal weight for the moving average (as in the Simple moving average) or linear weights (as in the weighted moving average), we get to pick THE MAGIC SEQUENCE, Fibonacci.
we will use the Fibonacci Sequence as weights to produce our moving average - so practically, we create a "Fibonacci Weighted Moving Average" (let's call it FiMA) - and compare the result with other commonly-used moving averages of the same length
in a Fibonacci moving average, the data will be weighted based on the Fibonacci Series starting from 1 (for the furthest data point)
so for example, if we use a length of 10, the weights will be 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 with the 55 being the weight applied to the most recent / current bar's selected value (close, hl2, hc3..etc) and moving backward
before i posted this script, i searched around to see if someone else has already wrote this - i found a couple, but the approach we use here in this code is different - i can't claim it to be more efficient - i honestly don't know - but the resulting code here, IMHO, is more compact and easier to integrate in other studies that you may like to put together to leverage this idea, to create your own indicators and strategies.
the reason the code here is more compact, is that it utilizes a shorter formula to calculate the FIb(n) - i included the source where i found that formula, and i tested it before using it in the code.
i also added an optional "extra smoothing" for the resulting MA, by simply calling the fima() function a second time (so like doing a 2-pass filter), with a smaller length on the result of the 1st pass. keep this smoothing small not to produce too much lag.
i like the outcome when compared to other moving averages - it has a fast response to data/trend change and less overshoot - but honesty i didn't see any real "Fibonacci Magic" :) .. but i'll leave the final judgement to those who use it - this is more of an experimental code in all cases - please feel free to use, change and share feedback.
Squared Weighted Moving AverageThe Squared Weighted Moving Average is similar to the classic Weighted Moving Average but the difference is that it squares the weights instead of the classic weight values. Buy if the indicator line is green and sell when it goes red.
Let me know if you would like to see any more scripts from me or if you want something custom done!