alexgrover

Z-Histogram

It is possible to approximate the underlying distribution of a random variable by using what is called an "Histogram". In order to construct an histogram one must first split the data into several intervals (also called bins) often of the same size and count the number of values falling within each intervals, the histogram plot is then constructed with the X axis representing the measured variable and the Y axis representing the frequency.

The proposed script aim to estimate the underlying distribution of a rolling z-score by constructing its histogram, here the histogram consist of 13 bins of width 0.5 rolling standard deviations. The length setting define the rolling z-score period, the window setting define the number of past data to be counted, finally using the "Total" option (true by default) will count all the rolling z-scores values since the first bar, in order to use the window setting make sure to uncheck the "Total" option.


DISPLAY

In order to see the entirety of the histogram make sure to double click on the indicator window and to have all the lower panels (text notes, pine editor...etc) hidden, finally make sure to zoom-in in order to see the frequency numbers displayed.


Z-Histogram on BTCUSD 15 min TF, the blue bins represent intervals situated over 0 while red bins represent intervals situated under 0. Here σ represent the X-axis in standard deviations, the histogram start with a bin situated at σ = -3 which count the number of times the rolling z-score was within -3 and -2.5, the histogram end with the bin situated at σ = 3 which count the number of time the rolling z-score was within 3 and 3.5.

It is also possible to look at the shape of the histogram without having the indicator window at full size.



INTERPREATION

An histogram can give really interesting information such as overall trend direction and strength. The direction can be measured by looking at the skewness of the histogram, with a negative skewness (the peak of the histogram situated at the right from the center) representing down-trending variations and positive skewness (the peak of the histogram situated at the left from the center) representing up-trending variations, while a symmetrical histogram could represent a ranging market. The farther away the peak of the histogram is situated from the center, the stronger the trend.

Another interesting characteristic is the tailedness of the histogram, which can give information about the cleanliness of the trend, for example a positive skew and high tailedness would represent a clean up-trend, as it could suggest less variations contrary to the main trend.

An histogram applied to the rolling z-score can give various useful information. As a recall the rolling z-score of the price measure the distance between the closing price and its moving average in term of rolling standard deviations, for example if the rolling z-score is equal to 2 it means that the closing price is currently 2 rolling standard deviations over its moving average.

Lets for example analyze the histogram using INTC 15 min tf with a window of 456 bars and rolling z-score of length = 100 in order to review longer term variations.



We can see from the histogram that the uptrend visible on the chart is represented by the bins situated over 0 having an overall higher frequency than the bins under 0, we can see that the closing price tended to stay between 1 and 1.5 rolling standard deviations over its period 100 moving average. Here bins under 0 accounts for retracements in the trend.


IN SUMMARY

An histogram can give various information regarding the price evolution of a security, the proposed script aim to plot the histogram of a rolling z-score. Now this script might not be too useful but it was fun to make, also it does not mean that an histogram is not an useful tool in the context of trading, the only thing required is a god implementation of it (like volume profiles for example)

In this post we have also reviewed some important statistical concepts such as distributions, z-score, skewness and tailedness, each being extremely important in the quantitative trading field.

Thx for reading !


Eliminar de Scripts favoritos. Añadir a Scripts favoritos.
Patreon: https://www.patreon.com/alexgrover

Become a Patreon and get access to exclusive technical indicators!

You can also check out some of the indicators I made for luxalgo : https://www.tradingview.com/u/LuxAlgo/#published-scripts

Comentarios

thanks for your amazing work.
+2 Responder
Fantastic work
+2 Responder
Absolutely brilliant and refreshingly different approach!

I thought at first, woohoo Alex will finally need a lot of lines of code to write something,...
and then I scrolled down...!! ;-)

you are a master of efficiency .

Gr, JD.
+2 Responder
@Duyck, Those where exactly my thoughts! Master of efficiency indeed.
+1 Responder
@Duyck, Thx, i guess it could be further improved, not by me tho, i believe that Ricardo could shorten the code even further ^^
Responder
OMG, you are an amazing person. A bright mind! Thank you for the light you put through the universe.
+2 Responder
alexgrover MohamedAlfar
@MohamedAlfar, More like a candle in a room that is already bright xD but thx a lot for your praise :3
+1 Responder
In the "INTERPRETATION" section i made a mistake, it should be as follows:

"with a negative skewness (the peak of the histogram situated at the LEFT from the center) representing down-trending variations and positive skewness (the peak of the histogram situated at the RIGHT from the center)"

I kinda rushed out the post description, i apologize.
+1 Responder
i cant undertstand ...
+1 Responder
alexgrover dsaidasi
@dsaidasi, srry to hear it :( I'll do a better description next time.
Responder
Inicio Analizador de acciones Analizador de Forex Crypto Screener Calendario económico Cómo funciona Funcionalidades del gráfico Precios Recomendar a un amigo Normas Centro de ayuda Soluciones broker y sitio web Widgets Soluciones gráficas Biblioteca de gráficos ligeros Blog y Noticias Twitter
Perfil Opciones de configuración del perfil Cuenta y facturación Amigos referidos Monedas Mis solicitudes de asistencia Centro de ayuda Ideas publicadas Seguidores Siguiendo Mensajes privados Chat Cerrar sesión