Returns Stationarity Analysis (YavuzAkbay)This indicator analyzes the stationarity of a stock's price returns over time. Stationarity is an important property of time series data, as it determines the validity of statistical analysis and forecasting methods.
The indicator provides several visual cues to help assess the stationarity of the price returns:
Price Returns: Displays the daily percentage change in the stock's closing price.
Moving Average: Shows the smoothed trend of the price returns using a simple moving average.
Z-Score: Calculates the standardized z-score of the price returns, highlighting periods of significant deviation from the mean.
Autocorrelation: Plots the autocorrelation of the price returns, which measures the persistence or "memory" in the time series. High autocorrelation suggests non-stationarity.
The indicator also includes the following features:
Customizable lookback period and smoothing window for the moving statistics.
Lag parameter for the autocorrelation calculation.
Shaded bands to indicate the significance levels for the z-score and autocorrelation.
Visual signals (red dots) to highlight periods that are potentially non-stationary, based on a combination of high z-score and autocorrelation.
Informative labels to guide the interpretation of the results.
This indicator can be a useful tool for stock market analysts and traders to identify potential changes in the underlying dynamics of a stock's price behavior, which may have implications for forecasting, risk management, and investment strategies.
Stationary
level_statsThis script tells you the percentage of time an instrument's closing value is above and below a level of your choosing. The background color visually indicates periods where the instrument closed at or above the level (red) and below it (blue). For "stationary-ish" processes, you can get a loose feel for the mean, high, and low values. The historical information conveyed through the background coloring can help you plan derivatives trades. Try with your favorite pairs, commodities, or volatility indices.
Usage: pick a level of interest using the input.
Augmented Dickey–Fuller (ADF) mean reversion testThe augmented Dickey-Fuller test (ADF) is a statistical test for the tendency of a price series sample to mean revert .
The current price of a mean-reverting series may tell us something about the next move (as opposed, for example, to a geometric Brownian motion). Thus, the ADF test allows us to spot market inefficiencies and potentially exploit this information in a trading strategy.
Mathematically, the mean reversion property means that the price change in the next time period is proportional to the difference between the average price and the current price. The purpose of the ADF test is to check if this proportionality constant is zero. Accordingly, the ADF test statistic is defined as the estimated proportionality constant divided by the corresponding standard error.
In this script, the ADF test is applied in a rolling window with a user-defined lookback length. The calculated values of the ADF test statistic are plotted as a time series. The more negative the test statistic, the stronger the rejection of the hypothesis that there is no mean reversion. If the calculated test statistic is less than the critical value calculated at a certain confidence level (90%, 95%, or 99%), then the hypothesis of a mean reversion is accepted (strictly speaking, the opposite hypothesis is rejected).
Input parameters:
Source - The source of the time series being tested.
Length - The number of points in the rolling lookback window. The larger sample length makes the ADF test results more reliable.
Maximum lag - The maximum lag included in the test, that defines the order of an autoregressive process being implied in the model. Generally, a non-zero lag allows taking into account the serial correlation of price changes. When dealing with price data, a good starting point is lag 0 or lag 1.
Confidence level - The probability level at which the critical value of the ADF test statistic is calculated. If the test statistic is below the critical value, it is concluded that the sample of the price series is mean-reverting. Confidence level is calculated based on MacKinnon (2010) .
Show Infobox - If True, the results calculated for the last price bar are displayed in a table on the left.
More formal background:
Formally, the ADF test is a test for a unit root in an autoregressive process. The model implemented in this script involves a non-zero constant and zero time trend. The zero lag corresponds to the simple case of the AR(1) process, while higher order autoregressive processes AR(p) can be approached by setting the maximum lag of p. The null hypothesis is that there is a unit root, with the alternative that there is no unit root. The presence of unit roots in an autoregressive time series is characteristic for a non-stationary process. Thus, if there is no unit root, the time series sample can be concluded to be stationary, i.e., manifesting the mean-reverting property.
A few more comments:
It should be noted that the ADF test tells us only about the properties of the price series now and in the past. It does not directly say whether the mean-reverting behavior will retain in the future.
The ADF test results don't directly reveal the direction of the next price move. It only tells wether or not a mean-reverting trading strategy can be potentially applicable at the given moment of time.
The ADF test is related to another statistical test, the Hurst exponent. The latter is available on TradingView as implemented by balipour , QuantNomad and DonovanWall .
The ADF test statistics is a negative number. However, it can take positive values, which usually corresponds to trending markets (even though there is no statistical test for this case).
Rigorously, the hypothesis about the mean reversion is accepted at a given confidence level when the value of the test statistic is below the critical value. However, for practical trading applications, the values which are low enough - but still a bit higher than the critical one - can be still used in making decisions.
Examples:
The VIX volatility index is known to exhibit mean reversion properties (volatility spikes tend to fade out quickly). Accordingly, the statistics of the ADF test tend to stay below the critical value of 90% for long time periods.
The opposite case is presented by BTCUSD. During the same time range, the bitcoin price showed strong momentum - the moves away from the mean did not follow by the counter-move immediately, even vice versa. This is reflected by the ADF test statistic that consistently stayed above the critical value (and even above 0). Thus, using a mean reversion strategy would likely lead to losses.
Dependent Variable Odd Generator Risk Detector
In fact, I wrote this script for detect Bollinger and Linear Regression Bands squeeze.
It's a side script.
Logic works like this:
Only the stagnant market probability is drawn from the Bollinger bandwidth by Dependent Variable Odd Generator and MFI index is calculated taking into account the volume.
This value ranges from 0 to 100.
To be sure, this value is averaged over a small period.
If you break the average and exceed 50, the bollinger band is too narrow and the risk is too high.
This means more commissions, more transactions, and vain work.
Or, when in position, the warning is not ignored due to unnecessary signals.
This code is open source under the MIT license. If you have any improvements or corrections to suggest, please send me a pull request via the github repository github.com
Stay tuned , best regards.
Dependent Variable Odd Generator For Machine Learning TechniquesCAUTION : Not suitable for strategy, open to development.
If can we separate the stagnant market from other markets, can we be so much more accurate?
This project was written to research it. It is just the tiny part of the begining.
And this is a very necessary but very small side function in the main function. Lets start :
Hi users, I had this idea in my mind for a long time but I had a hard time finding the parameters that would make the market stagnant. This idea is my first original command system. Although it is very difficult to make sense of the stagnant market, I think that this command system can achieve realistic proportions. With 's money flow index, I opened the track to determine the level. On the other hand, the prices were also using a money flow index, and it forced me to make the limitations between the levels in a logical way. But the good thing is that since the bollinger bandwidth uses a larger period, we are able to print normal values at extreme buy and sell values.
In terms of price, we can define excessive purchase and sale values as the period is smaller. I have repeatedly looked at the limit values that determine the bull, bear, and bollinger bandwidth (mfi), and I think this is the right one. Then I have included these values in the probability set.
The bull and bear market did not form the intersection of the cluster, and because there are connected events, the stagnant market, which is the intersection, will be added to the other markets with the same venn diagram logic and the sum of the probability set will be 1. is equal to. I hope that we can renew the number generators in the very important parameters of machine learning such as Markov Process with generators dependent on dependent variables, which bring us closer to reality. This function is open to development and can be made of various ideas on machine learning. Best wishes.
This code is open source under the MIT license. If you have any improvements or corrections to suggest, please send me a pull request via the github repository github.com