# Distribution shift

> Distribution shift is an alert that checks every 1 hour and fires at most once per bar.

Source: https://algobarsx.com/docs/ex-50-distribution-shift-alert/

```algobarsx
alert "Distribution shift"
    check: every 1h
    repeat: once per bar
    warmup: 300

r = returns(close)
skewness = skew(r, 100)
tails = kurtosis(r, 100)
memory = autocorrelation(r, 100, lag: 1)

when abs(skewness) > 1 and tails > 5:
    notify "Fat-tailed, skewed returns: skew {skewness:0.00}, kurtosis {tails:0.0}, lag-1 autocorrelation {memory:0.00}"
```
What this script says

Distribution shift is an alert that checks every 1 hour and fires at most once per bar.

It calculates `r` as the returns of the close, `skewness` as the skew (source `r`, length 100), `tails` as the kurtosis (source `r`, length 100) and `memory` as the autocorrelation (source `r`, length 100, lag 1).

When the absolute value of `skewness` is above 1 and `tails` is above 5, it sends the notification "Fat-tailed, skewed returns: skew {skewness:0.00}, kurtosis {tails:0.0}, lag-1 autocorrelation {memory:0.00}".
