Intrabar Run Count Indicator [tbiktag]


Introducing the Intrabar Run Count Indicator, a tool designed to detect potential non-randomness in intrabar price data. It utilizes the statistical runs test to examine the number of sequences (runs) of positive and negative returns in the analyzed price series. As deviations from random-walk behavior of returns may indicate market inefficiencies, the Intrabar Run Count Indicator can help traders gain a better understanding of the price dynamics inside each chart bar and make more informed trading decisions.


The indicator line expresses​ the deviation between the number of runs observed in the dataset and the expected number of runs under the hypothesis of randomness​. Thus, it gauges the degree of deviation from random-walk behavior. If, for a given chart bar, it crosses above the critical value or crosses below the negative critical value, this may indicate non-randomness in the underlying intrabar returns. These instances are highlighted by on-chart signals and bar coloring. The confidence level that defines the critical value, as well as the number of intrabars used for analysis, are selected in the input settings.

It is important to note that the readings of the Intrabar Run Count Indicator do not convey directional information and cannot predict future asset performance. Rather, they help distinguish between random and potentially tradable price movements, such as breakouts, reversals, and gap fillings.


The efficient-market hypothesis implies that the distribution of returns should be random, reflecting the idea that all available information is already priced into the asset. However, in practice, financial markets may not always be perfectly efficient due to factors such as market frictions, information asymmetry, and irrational behavior of market participants. As a result, inefficiency (non-randomness) can occur, potentially creating opportunities for trading strategies.

To search for potential inefficiencies, the Intrabar Run Count Indicator analyzes the distribution of the signs of returns. The central assumption underlying the indicator's logic is that if the asset price follows a random-walk pattern, then the probability of the next return being positive or negative (i.e., the next price value being larger or smaller than the current value) follows a binomial distribution. In this case, the number of runs is also a random variable, and, for a large sample, its conditional distribution is approximately normal with a well-defined mean and variance (see this link for the exact expressions). Thus, the observed number of runs in the price series is indicative of whether or not the time series can be regarded as random. In simple words, if there are too few runs or too many runs, it is unlikely a random time series. A trivial example is a series with all returns of the same sign.

Quantitatively, the deviation from randomness can be gauged by calculating the test statistic of the runs test (that serves as an indicator line). It is defined as the absolute difference between the observed number of runs and the expected number of runs under the null hypothesis of randomness, divided by the standard deviation of the expected number of runs. If the test statistic is negative and exceeds the negative critical value (at a given confidence level), it suggests that there are fewer runs than expected for a random-walking time series. Likewise, if the test statistic exceeds the positive critical value, it is indicative of more runs than expected for a random series. The sign of the test statistic can also be informative, as too few runs can be sometimes indicative of mean-reverting behavior.


The Intrabar Run Count Indicator can be a useful tool for traders seeking to exploit market inefficiencies and gain a better understanding of price action within each chart bar. However, it is important to note that the runs test only evaluates the distributional properties of the data and does not provide any information on the underlying causes of the non-randomness detected. Additionally, like any statistical test, it can sometimes produce false-positive signals. Therefore, this indicator should be used in conjunction with other analytical techniques as part of a trading strategy.

DISCLAIMER: I am not a financial advisor, and my scripts are for educational purposes only. Any trades you make are at your own risk.
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.


이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?