FX DispersionThis script calculates the dispersion of a basket of 5 FX pairs and then calculates the z-score the z-score is then made into a composite using the 30 and 60 ema of the z-score to smooth any noise. It must be used on one of the FX pairs in the basket and on the 1-minute timeframe as it has been hardcoded for 1 min use below.
Interpretation - Dispersion is a component of volatility - the dispersion of the underlying basket increases above 0.5 and decreases below 0.5.
Although increased dispersion is beneficial to momentum and trend-following strategies on the monthly and weekly timeframes. Observe this on the 1-minute timeframe and how dispersion crossing above/ below 0.5 it can signal reversion or momentum for the next period.
Dispersion
Asymmetric Dispersion High Lowdear fellows,
this indicator is an effort to determine the range where the prices are likely to fall within in the current candle.
how it is calculated
1. obtain
a. gain from the open to the high
b. loss from the open to the low
in the last 20 (by default) candles and
in the last 200 (10*20 by default) candles
2. perform
a. the geometric average (sma of the log returns) over these gains and losses
b. their respective standard deviation
3. plot from the open of each candle
a. the average + 2 standard deviations (2 by default) of the short window size
b. same for the long window size (which is overlapped)
what it shows
1. where the current candle is likely to move with 95% likelyhood
how it can be interpreted
1. a gauge for volatility in the short and long term
2. a visual inbalance between likelyhood to go up or down according to dispersion in relation to current prices or candle open.
3. a confirmation of crossings of, for instance, support and resistances once the cloud is completely above or below.
in regard to bollinger bands (which are and excellent well proven indicator)
1. it segregates upward moves from the downward ones.
2. it is hardly crossed by prices
3. it is centered on the current candle open, instead of the moving average.
we welcome feedback and critic.
best regards and success wishes.
SMADIF4 IndicatorIt shows a percentage difference between close and 4-SMA, 20, 50, 100 and 200. As it turns greener, the stock is more expensive, and vice versa, it turns redder when it becomes cheaper relative to the SMA. It will print the green backgraound as long as the bar closes above the 200 SMA and red as long as the bar closes below the 200 SMA. It uses by default 1.3 sigma to discriminate non-representative values and 100 bars in the past.
The dispersion of volatility indicesThe script is my implementation of "Forecasting a Volatility Tsunami" by Andrew Thrasher (Thrasher Analytics). You can find the paper here: www.researchgate.net
I've changed a bit the approach - instead of two volatility indices (VIX & VVIX), I used two more: VXN and VXD. Additionally, I average the percentiles, but there is an option to swtich it to the original approach.
Price Action IndexI've created a simple oscillator which I think does a good job of easily showing you when price is worth watching or not. I think all too often you get stuck looking at something like an RSI and end up trading noise.
From my observations and experiences, I've found that there are 2 major catalysts for price movement--
Price is either trending and reaches a top or bottom, or
Price is consolidating and ready to make a move in some direction
These movements can be seen quite well from a Bollinger Band, which is what mostly gave me the inspiration. When I watch a chart with a BB on it I see that either you're looking to trade price moving out of a squeeze or riding price up/down the band until it crosses over and makes a move to the moving average.
My solution was to multiply the direction of price by the strength of its deviation.
Price gets converted into a signal between -1.0 (bottom of the range) and 1.0 (top of the range)
Standard Deviation gets converted into a stochastic signal between 0 (next to no deviation from mean) and 100 (highest deviation in lookback)
These 2 get multiplied by each other
The result tells you if price action is trending bullish and if its approaching max strength (perhaps Overbought), example: Price is hitting highs (1.0) and deviation is also at its highest (100) = 100, opposite for bearish
Result can also tell you if price is at the top of the range but the deviation is so tiny and we're mostly pinned to the mean (1.0 * 5 = only 5)
How to Trade this Indicator--
If the indicator is stuck near the middle and purple:
- Don't make directional trades or you'll be eaten alive by the chop
- Good idea to sell options, Iron Condors/Butterflies, etc
- Wait for a move to breakout --> the purple will fade away and give way to a direction
--- As in all trading scenarios, be mindful of fakeouts/short moves to one direction that very quickly get reversed
If the indicator is heading higher:
- This would indicate there is a bull trend going on, get long
- If we are reaching the overbought area, this is an ideal place to take profits or look at spreads like Bearish Call Spreads (sell calls)
- I think you can make your own determination of when to sell by either selling when we're in the overbought area (if it reaches there) or staying bullish so long as it is above the zone
If the indicator is heading lower:
- Bear trend, shorting is possible
- Can use this as a contrarian signal to buy lows
A couple of charts with the indicator and a purple squeeze box I've drawn (can sometimes get noisy in real-time, but hindsight is 20/20)--
Bitcoin on Daily with default 20 length
Gamestop on 30 minute time frame with 100 length
Please feel free to use this indicator for your trading or your own indicators. This particular script is very stripped down/bare bones from what I have been working on as an ongoing project. If TradingView ever returns scripts you can sell, I would probably open that up for a small premium.
Standard Deviation - Sum Of The Squares Minus Square Of The SumsIntroduction
The standard deviation measure the dispersion of a data set, in short this metric will tell you if your data is on average closer or farther away from the mean. Its one of the most important tools in statistics and living without it is pretty much impossible, without it you can forget about Bollinger-bands, CCI, and even the LSMA (ouch this hurt) .
Now i don't want to extend myself about the standard deviation since that would require a huge post but i want to show you how to calculate the standard deviation from the stdev pinescript function.
Sum Of The Squares Minus Square Of The Sums
Any metric calculated from a moving average can be classified as "running", this mean that the metric constantly update itself and is not constant, this is why it is better to say "running standard deviation" but its okay. If we use the standard calculation for the standard deviation which would be sqrt(sma(pow(close - sma,2))) we might get something totally different from the stdev function :
In white the pine stdev function and in red the standard calculation of both period 4, its clear that both are not the same, one might try to use the Bessel's correction but that won't do either, this is because most technical analysis tools will calculate the square root of the "Sum Of The Squares Minus Square Of The Sums" method to estimate the standard deviation
Another way is to use :
a = sqrt(sma(pow(close,2),length) - pow(sma(close,length),2))
By returning the difference we might still see some errors :
Nothing relevant of course.
Conclusion
Some of you might already be aware of this but a reminder is always good since it can be confusing to make what can be considered the good standard deviation formula and then have something totally different from the pine function, i hope this post will be useful and that you learned something from it.
Thanks for reading :)
QMA/SMA DifferenceIntroduction
The quadratic moving average (QMA) or quadratic weighted moving average (QWMA) is a type of moving average who is closer to the price when price is up trending. This moving average is defined as the square root of the moving average of the squared price. The QMA-SMA difference use this moving average to provide a new volatility indicator who aim to be reactive and filter noisy volatility in order to only provide essential information.
QMA - SMA
This indicator is defined as the difference between a quadratic moving average and a simple moving average of same period. Since the QMA emphasize up movements and tend to be away from down movements she is always greater than the simple moving average, so a simple difference between those moving average provide our volatility indicator. Below is a comparison with a standard deviation and the indicator of both period 100.
Since its a difference between two moving average it can be interesting to use a simple moving as source for the standard deviation to provide another comparison
The standard deviation is smoother but still contain more information as well as having less reactivity.
Conclusion
I have a presented a new volatility indicator based on the quadratic moving average and compared it with a classic standard deviation. It is possible to change the power order of the QMA in order to provide different results, in order to do so you must also change the root, this is done in pine with : pow(sma(pow(close,w),length),1/w) where w is the power order, notice that an high power order can provide non attributed values.
Closed Form Distance VolatilityIntroduction
Calculating distances in signal processing/statistics/time-series analysis imply measuring the distance between two probability distribution, i am not really familiar with distances but since some formulas are in closed form they can be easily used for volatility estimation. This volatility indicator will use three methods originally made to measure the distance of gaussian copulas, using those methods for volatility estimation is fairly easy and provide a different approach to statistical dispersion.
The indicator have a length parameter and a method parameter to select the method used for volatility estimation, i describe each methods below.
Hellinger Method
Each method will use the rolling sum of the low price and the rolling sum of the high price instead of probability distributions. The Hellinger method have many application from the measurement of distances to the use as a cost function for neural networks.
Its closed form is defined as the square root of 1 - a^0.25b^0.25/(0.5a + 0.5b)^0.5 where a and b are both positive series. In our indicator a is the rolling sum of the high price and b the rolling sum of the low price. This method give a classic estimation of volatility.
Bhattacharyya Method
The Bhattacharyya method is another method who use a natural logarithm, this method can visually filter small volatility variation. It is defined as 0.5 * log((0.5a+0.5b)/√(ab)) .
Wasserstein Method
This method was originally using a trimmed mean for its calculation. The original method is defined as the square of the trimmed mean of a + b - 2√(a^0.5ba^0.5) , a median has been used instead of a trimmed mean for efficiency sake, both central tendency estimators are robust to outliers.
Conclusion
I showed that closed form formulas for distance calculation could be derived into volatility estimators with different properties. They could be used with series in a range of (0,1) to provide a smoothing variable for exponential smoothing.