LibBrStLibrary   "LibBrSt" 
This is a library for quantitative analysis, designed to estimate
the statistical properties of price movements *within* a single
OHLC bar, without requiring access to tick data. It provides a
suite of estimators based on various statistical and econometric
models, allowing for analysis of intra-bar volatility and
price distribution.
Key Capabilities:
1.  **Price Distribution Models (`PriceEst`):** Provides a selection
of estimators that model intra-bar price action as a probability
distribution over the   range. This allows for the
calculation of the intra-bar mean (`priceMean`) and standard
deviation (`priceStdDev`) in absolute price units. Models include:
- **Symmetric Models:** `uniform`, `triangular`, `arcsine`,
`betaSym`, and `t4Sym` (Student-t with fat tails).
- **Skewed Models:** `betaSkew` and `t4Skew`, which adjust
their shape based on the Open/Close position.
- **Model Assumptions:** The skewed models rely on specific
internal constants. `betaSkew` uses a fixed concentration
parameter (`BETA_SKEW_CONCENTRATION = 4.0`), and `t4Sym`/`t4Skew`
use a heuristic scaling factor (`T4_SHAPE_FACTOR`)
to map the distribution.
2.  **Econometric Log-Return Estimators (`LogEst`):** Includes a set of
econometric estimators for calculating the volatility (`logStdDev`)
and drift (`logMean`) of logarithmic returns within a single bar.
These are unit-less measures. Models include:
- **Parkinson (1980):** A High-Low range estimator.
- **Garman-Klass (1980):** An OHLC-based estimator.
- **Rogers-Satchell (1991):** An OHLC estimator that accounts
for non-zero drift.
3.  **Distribution Analysis (PDF/CDF):** Provides functions to work
with the Probability Density Function (`pricePdf`) and
Cumulative Distribution Function (`priceCdf`) of the
chosen price model.
- **Note on `priceCdf`:** This function uses analytical (exact)
calculations for the `uniform`, `triangular`, and `arcsine`
models. For all other models (e.g., `betaSkew`, `t4Skew`),
it uses **numerical integration (Simpson's rule)** as
an approximation of the cumulative probability.
4.  **Mathematical Functions:** The library's Beta distribution
models (`betaSym`, `betaSkew`) are supported by an internal
implementation of the natural log-gamma function, which is
based on the Lanczos approximation.
---
**DISCLAIMER**
This library is provided "AS IS" and for informational and
educational purposes only. It does not constitute financial,
investment, or trading advice.
The author assumes no liability for any errors, inaccuracies,
or omissions in the code. Using this library to build
trading indicators or strategies is entirely at your own risk.
As a developer using this library, you are solely responsible
for the rigorous testing, validation, and performance of any
scripts you create based on these functions. The author shall
not be held liable for any financial losses incurred directly
or indirectly from the use of this library or any scripts
derived from it.
 priceStdDev(estimator, offset) 
  Estimates **σ̂** (standard deviation) *in price units* for the current
bar, according to the chosen `PriceEst` distribution assumption.
  Parameters:
     estimator (series PriceEst) : series PriceEst  Distribution assumption (see enum).
     offset (int) : series int       To offset the calculated bar
  Returns: series float     σ̂ ≥ 0 ; `na` if undefined (e.g. zero range).
 priceMean(estimator, offset) 
  Estimates **μ̂** (mean price) for the chosen `PriceEst` within the
current bar.
  Parameters:
     estimator (series PriceEst) : series PriceEst Distribution assumption (see enum).
     offset (int) : series int    To offset the calculated bar
  Returns: series float  μ̂ in price units.
 pricePdf(estimator, price, offset) 
  Probability-density under the chosen `PriceEst` model.
**Returns 0** when `p` is outside the current bar’s  .
  Parameters:
     estimator (series PriceEst) : series PriceEst  Distribution assumption (see enum).
     price (float) : series float  Price level to evaluate.
     offset (int) : series int    To offset the calculated bar
  Returns: series float  Density value.
 priceCdf(estimator, upper, lower, steps, offset) 
  Cumulative probability **between** `upper` and `lower` under
the chosen `PriceEst` model. Outside-bar regions contribute zero.
Uses a fast, analytical calculation for Uniform, Triangular, and
Arcsine distributions, and defaults to numerical integration
(Simpson's rule) for more complex models.
  Parameters:
     estimator (series PriceEst) : series PriceEst Distribution assumption (see enum).
     upper (float) : series float  Upper Integration Boundary.
     lower (float) : series float  Lower Integration Boundary.
     steps (int) : series int    # of sub-intervals for numerical integration (if used).
     offset (int) : series int    To offset the calculated bar.
  Returns: series float  Probability mass ∈  .
 logStdDev(estimator, offset) 
  Estimates **σ̂** (standard deviation) of *log-returns* for the current bar.
  Parameters:
     estimator (series LogEst) : series LogEst  Distribution assumption (see enum).
     offset (int) : series int     To offset the calculated bar
  Returns: series float   σ̂ (unit-less); `na` if undefined.
 logMean(estimator, offset) 
  Estimates μ̂ (mean log-return / drift) for the chosen `LogEst`.
The returned value is consistent with the assumptions of the
selected volatility estimator.
  Parameters:
     estimator (series LogEst) : series LogEst  Distribution assumption (see enum).
     offset (int) : series int     To offset the calculated bar
  Returns: series float   μ̂ (unit-less log-return).
Cdf
norminvLibrary   "norminv" 
 Description: 
An inverse normal distribution is a way to work backwards 
from a known probability to find an x-value. It is an informal term and 
doesn't refer to a particular probability distribution. Returns the 
value of the inverse normal distribution function for a specified value, 
mean, and standard deviation.
 Reference: 
 github.com 
 support.microsoft.com 
 norminv(x, mean, stdev) 
  Returns the value of the inverse normal distribution function for a specified value, mean, and standard deviation.
  Parameters:
     x : float, The input to the normal distribution function.
     mean : float, The mean (mu) of the normal distribution function
     stdev : float, The standard deviation (sigma) of the normal distribution function.
  Returns: float.
Probability Distribution HistogramProbability Distribution Histogram 
During data exploration it is often useful to plot the distribution of the data one is exploring. This indicator plots the distribution of data between different bins. 
Essentially, what we do is we look at the min and max of the entire data set to determine its range. When we have the range of the data, we decide how many bins we want to divide this range into, so that the more bins we get, the smaller the range (a.k.a. width) for each bin becomes. We then place each data point in its corresponding bin, to see how many of the data points end up in each bin. For instance, if we have a data set where the smallest number is 5 and the biggest number is 105, we get a range of 100. If we then decide on 20 bins, each bin will have a width of 5. So the left-most bin would therefore correspond to values between 5 and 10, and the bin to the right would correspond to values between 10 and 15, and so on.
Once we have distributed all the data points into their corresponding bins, we compare the count in each bin to the total number of data points, to get a percentage of the total for each bin. So if we have 100 data points, and the left-most bin has 2 data points in it, that would equal 2%. This is also known as probability mass (or well, an approximation of it at least, since we're dealing with a bin, and not an exact number).
 Usage 
This is not an indicator that will give you any trading signals. This indicator is made to help you examine data. It can take any input you give it and plot how that data is distributed.
The indicator can transform the data in a few ways to help you get the most out of your data exploration. For instance, it is usually more accurate to use logarithmic data than raw data, so there is an option to transform the data using the natural logarithmic function. There is also an option to transform the data into %-Change form or by using data differencing.
Another option that the indicator has is the ability to trim data from the data set before plotting the distribution. This can help if you know there are outliers that are made up of corrupted data or data that is not relevant to your research.
I also included the option to plot the normal distribution as well, for comparison. This can be useful when the data is made up of residuals from a prediction model, to see if the residuals seem to be normally distributed or not.
Cumulative distribution function - Probability Cumulative distribution function (tScore and zScore)
This script provides the calculation of the cumulative distribution function (i.e., probability). The measure allows you to calculate the chances of a value of interest being above or below a hypothesized value over the measurement period—nothing fancy here, just good old statistics and mathematics. The closer you are to 0 or 1, the more significant your measurement. We’ve included a significance level highlighting feature. The ability to turn price and/or volume off.
We have included both the Z and T statistics. Where the ‘Z’ is looking at the difference of the current value, minus the mean, and divided by the standard deviation. This is usually pretty noisy on a single value, so a smoother is included. Nice shoutout to the  Pinecoders Github Page  with this function also. The t-statistic is measuring the difference between a short measurement, an extended measurement, and divided by the standard error (sigma/sqrt(n)). Both of these are neatly wrapped into a function, so please feel free to use them in your code. Add a bit of science to your guessing game. For the purists out there, we have chosen to use sigma in the t-statistic because we know the population's behavior (as opposed to the s-measure). We’ve also included two levels of the t-statistic cumulative distribution function if you are using a short sample period below 6.
Finally, because everyone loves choices, we’ve included the ability to measure the probability of:
 
 the current value (Price and volume)
 change
 percent change
 momentum (change over a period of time)
 Acceleration (change of the change)
 contribution (amount of the current bar over the sum)
 volatility (natural log ratio of today and the previous bar)
 
Here is a chart example explaining some of the data for the function.
Here are the various options you have the print the different measurements
A comparison of the t-statistic and z-statistic (t-score and z-score)
And the coloring options



