Both standard deviation and median absolute deviation (more robust to outliers, ie, exchanges with a very different price from others won't influence the median absolute deviation, but the standard deviation yes).
Compared to other inter-exchanges spread indicators, this one offers two major features:
* The symbol automatically adapts to the symbol currently selected in user's chart. Hence, switching between tickers does not require the user to modify any option, everything is dynamically updated behind the scenes.
* It's easy to add more exchanges (requires some code editing because PineScript v5 does not allow dynamical request.security() calls).
Limitations/things to know:
* History is limited to what the ticker itself display. Ie, even if the exchanges specified in this indicator have more data than the ticker currently displayed in the user's chart, the indicator will show only a timeperiod as long as the chart.
* The indicator can manage multiple exchanges of different historical length (ie, some exchanges having more data going way earlier in the past than others), in which case they will simply be ignored from calculations when far back in the past. Hence, you should be aware that the further you go in the past, the less exchanges will have such data, and hence the less accurate the measures will be (because the deviation will be calculated from less sources than more recent bars). This is thanks to how the array.* math functions behave in case of na values, they simply skip them from calculations, contrary to math.* functions.
Two methods of calculation of deviation are offered: standard deviation and median absolute deviation (more robust to outliers, ie, exchanges with a very different price from others won't influence the median absolute deviation, but the standard deviation yes).
* Also, here is the list of currently implemented exchanges:
INDEX (tradingview historical data)
* Deduplicated code between different ways of calculating deviations.
* Added option to bicolor cloud, so that we can infer buying and selling pressures from volatility.
* Added threshold to standardize sizing across timescales.
* Added background highlight depending on whether high and/or low are beyond threshold.
How to use:
- If cloud is bicolor, colorize the cloud in green for the high deviation, and red for the low deviation, which can be seen as representing buying pressure vs selling pressure respectively.
- If cloud is monocolor (or if you look at bicolor cloud's entire size), this can be seen as a quantification of overall volatility across market makers, and hence a sign of a potential upcoming big move.
- Background is highlighted depending on if high and/or low are beyond threshold: yellow if both are (meaning potential upcoming big move, stronger than either green or red highlight because both buying and selling pressure are through the roof, but not indication about the direction), green if high only (buying pressure may be more important), red if only low is beyond threshold (selling pressure may be more important), no color otherwise.
* Replace label with a table, so that the chart is maximally rescaled to the content (the calculated metrics) rather than the label.
* Add a high-low deviations histogram plot, which answers the question: are highs (green cloud) more volatile (bigger) than lows (red cloud)?
* Increase opacity of background highlight.
How to use the histogram (this is in addition to the other "How to use" instructions above):
* The histogram/columns plot answers the simple question: are highs more volatile or are lows? By simply subtracting high deviation - low deviation, we obtain the answer, as a histogram plot, where bars can only appear one side: above zero and green means that highs are more volatile than lows and presumably this indicates more buying pressure; below zero and red means lows are more volatile and may indicate more selling pressure; around zero below the user-defined margin will be gray and means that the value is not significantly deviating from zero so there is no direction - this does not mean that there is no pressure, but the pressure may be there but balanced (about as much high volatility as low volatility, in some cases the background can be highlighted in yellow simultaneously to a 0 histogram value which means that there is high pressure on both sides).
* Note that there is absolutely zero smoothing of data over time, so the clouds and histograms really reflect per-bar resolution data, with no influence of past bars. There is however an aggregation done between exchanges data feeds, as part of the deviation calculation, so there is some loss of accuracy in terms of values that is unavoidable.
* Modularize (ie, reuse updated library to deduplicate code and ease maintenance). No change in functionalities compared to previous release.
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.