Inter-Exchanges Crypto Price Spread Deviation (Tartigradia)

tartigradia アップデート済   
Measures the deviation of price metrics between various exchanges. It's a kind of realized volatility indicator, as the idea is that in times of high volatility (high emotions, fear, uncertainty), it's more likely that market inefficiencies will appear for the same asset between different market makers, ie, the price can temporarily differ a lot. This indicator will catch these instants of high differences between exchanges, even if they lasted only an instant (because we use high and low values).

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.
* Fix small typos in comments and clarify what needs to be done to add one exchange
* Fix unintelligible sentence in description because of missing words. Here is the corrected version:

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.

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。