TradingView
jason5480
20 Mar 2023 pukul 19.31

Ladder StDev 

Bitcoin / TetherUSBinance

Deskripsi

This indicator shows the upwards (green) and downward (red) volatility of the market. It is a standard deviation of the price but with a twist! For the upwards volatility , only the green candles are taken into account, and for the downwards only the red candles are.
Compared to my previous "Ladder ATR" indicator this a different approach to measure the the upwards and downwards volatility of the market by utilizing the standard deviation instead of the ATR. When both measure the volatility they have different "dynamics". Standard deviation increases the weight of larger values over smaller values. The ATR indicator is based on the average of absolute changes. So, if we apply the indicators on a daily chart , ATR considers intraday and between-day data, while the standard deviation calculation includes only daily returns (source price).

Catatan Rilis

  • Added RETURN mode that calculate the standard deviation of the log returns.


Many thanks to @lejmer for his idea of log return mode and for pointing out to me the (un)biased variable option in the standard deviation calculations.
Komentar
lejmer
Good idea to look at volatility of separate directions since the distribution is not symmetrical. I would probably not look at price directly though, but transform it into log returns first, measure volatility, and then transform that back to the same unit as price. Btw, you're array.stdev() function call is incorrect. The second parameter of the array.stdev() function is not a lookback period. It's used to determine if the calculation uses the population (biased) or sample (unbiased) calculation for standard deviation. You need to shift data from the array when it goes over the lookback period if you want a lookback window for the calculation, and you should set the biased parameter to false (since the population isn't known).
jason5480
Hello @lejmer, thank you for the feedback! The shift of the array is done internally in the push method of the "arraymethods" library I use for that operation. I know that the editor doesn't point to the correct method and this might confuse you a little bit. You are right about the biased argument of the stddev function though. I will fix it soon. I still investigate your idea about the logarithmic return instead of the close and looks interesting. However this will make it a different indicator.
jason5480
If I understood your idea correctly @lejmer. Could you compose this indicator with "Log Returns" indicator by RotsnerTrades to achieve what you have in mind? For example, by adding both indicators in the same chart you can select in the StDev Src combobox the 'Log Returns' instead of 'close'. Is that what you mean?
lejmer
@jason5480, Almost! Log returns are just
math.log(close) - math.log(prev_close)
so it's easy to achieve in your code if you want to add the option. But you need to transform that back to price after you have the stdev of the log returns. You do that by:
(math.exp(r_stdev) - 1) * close
lejmer
@lejmer, For some reason I cant do sqaure brackets in comments, so where it says prev_close, just use the close(1) thing but with square brackets, like you usually do.
metadimensional
@jason5480 can you help me understand what you mean by RETURNS in this indicator? Does this mean we are looking at the standard deviation of log(Price / Price[1]) over the stdevLength specified?

Could you or @lejmer please expand on why looking at the stdev of log returns is "better" (in otherwords, is a better descriptive statistic of volatility vs. stdev of price)?

Thank you!
lejmer
@metadimensional, There are a couple of reasons why stdev of log returns will be a better descriptive statistic of volatility than stdev of price. 1) Price is non-stationary and autocorrelated, so what distribution exactly is it describing, since it keeps changing with every bar? Log returns means you get a stable mean and while it doesn't make the data non-stationary, it makes it less non-stationary since the mode of the distribution converges to 0 (but volatility is still heteroscedastic, which is why you estimate it with a running lookback window to begin with). 2) price is multiplicative, so by using log returns, you remove the exponential property that comes with a multiplicative series. This results in a more symmetrical distribution and it also means it is easier to compare positive and negative volatility since their values will now be comparable (as in a positive 10 will be equal to an negative 10, which isn't the case otherwise).
Lebih lanjut