OPEN-SOURCE SCRIPT
Streak Reality Check - was that losing run actually unusual?

Most people abandon a working strategy during a losing run rather than because of anything in the numbers. The run feels like new information. Usually it is not, and roughly how long a run you should expect is calculable before it happens.
For n trades at a win rate w, the expected longest run of losses is about:
log(n × w) / log(1 / (1 − w))
That is the standard result for the longest run of failures in n Bernoulli trials. It has one property worth sitting with: n is inside it. More trades means more chances for a long run, so the run you should expect grows as you collect data. Slowly, because it is logarithmic, but it grows.
Which is why a fixed limit — "abandon anything with a run above 10" — gets stricter the more data you have. The same strategy passes early and fails later, having done nothing different in between. This script reports the ratio of observed to expected instead, because that is the number which means the same thing at every sample size.
What the table shows
Trades (non-overlapping). How many complete trades the sample produced, and how many timed out rather than resolving.
Win rate. Measured, not assumed. The expected run depends on it heavily.
Worst losing run. The longest consecutive run of losses in the sequence.
Expected at this sample. What that trade count and win rate should produce by chance.
Observed / expected. The number you came for. Around 1.0 means the worst thing that happened was typical. Below about 1.3 a long run is a long run and not a signal. Well above it, something in that stretch is worth understanding.
Sample covers. The period measured. A run length with no period attached invites more confidence than it has earned — 3,000 bars is six weeks on a 15m chart and twelve years on a daily one.
Non-overlapping trades, and why that matters
This measures differently from its two companions, deliberately.
Edge Reality Check and Filter Reality Check resolve from every bar. That is correct for measuring a hit rate: it uses the whole sample, and the overlap does not bias an average.
It would wreck a streak measurement. Samples opened on consecutive bars share almost all of their holding window, so their outcomes are strongly correlated, and one bad stretch of price would show up as a single enormous run of losses. Compared against a formula that assumes independent trades, that returns a ratio of three or four and a verdict of catastrophe on perfectly ordinary history.
So this one opens a trade, resolves it, and only then looks for the next entry. Fewer trades from the same history, and a sequence whose runs mean something. Expect a much lower trade count than the other two give on the same chart — that is the rule working, and the table labels the row so the difference is visible rather than mysterious.
Method, and its limits
A bar spanning both stop and target counts as a loss. There is no way to know which came first from bar data, and being wrong pessimistically is the only honest resolution. It matters more here than in the companion scripts: resolving those ties optimistically would break up runs and flatter every streak on the chart.
Distances can scale with each historical bar's own ATR, so the test uses the volatility of the time rather than today's.
Trades reaching neither level within the holding window are reported as timed out, not counted as losses. Counting them as losses would manufacture runs that never happened.
Fifty resolved trades is the floor. Below that the script refuses to compare, and says so. A streak is a tail statistic and needs more sample than an average does — a hit rate stabilises long before the longest run does.
The formula assumes independent trades. If your own trades overlap in time, or fire on correlated instruments, your effective sample is smaller than your trade count, the expected run is correspondingly smaller, and your real run is worse than the ratio suggests. The non-overlapping rule handles this inside the script; it cannot handle it for the strategy you are comparing against.
It is an expectation, not a bound. Runs longer than it are ordinary. The distribution has a tail on both sides, and a single measurement on one window settles nothing — run it across several.
What it is not
It places no trades, gives no signals and predicts nothing. It cannot tell you a strategy is broken. It tells you whether a losing run is evidence of anything, which is a smaller and more useful question, and the answer is usually no.
Open source. Companion to Edge Reality Check, which measures the hit rate entering at random would have produced at your reward-to-risk, and Filter Reality Check, which tells you whether a condition you are using beats that baseline.
For n trades at a win rate w, the expected longest run of losses is about:
log(n × w) / log(1 / (1 − w))
That is the standard result for the longest run of failures in n Bernoulli trials. It has one property worth sitting with: n is inside it. More trades means more chances for a long run, so the run you should expect grows as you collect data. Slowly, because it is logarithmic, but it grows.
Which is why a fixed limit — "abandon anything with a run above 10" — gets stricter the more data you have. The same strategy passes early and fails later, having done nothing different in between. This script reports the ratio of observed to expected instead, because that is the number which means the same thing at every sample size.
What the table shows
Trades (non-overlapping). How many complete trades the sample produced, and how many timed out rather than resolving.
Win rate. Measured, not assumed. The expected run depends on it heavily.
Worst losing run. The longest consecutive run of losses in the sequence.
Expected at this sample. What that trade count and win rate should produce by chance.
Observed / expected. The number you came for. Around 1.0 means the worst thing that happened was typical. Below about 1.3 a long run is a long run and not a signal. Well above it, something in that stretch is worth understanding.
Sample covers. The period measured. A run length with no period attached invites more confidence than it has earned — 3,000 bars is six weeks on a 15m chart and twelve years on a daily one.
Non-overlapping trades, and why that matters
This measures differently from its two companions, deliberately.
Edge Reality Check and Filter Reality Check resolve from every bar. That is correct for measuring a hit rate: it uses the whole sample, and the overlap does not bias an average.
It would wreck a streak measurement. Samples opened on consecutive bars share almost all of their holding window, so their outcomes are strongly correlated, and one bad stretch of price would show up as a single enormous run of losses. Compared against a formula that assumes independent trades, that returns a ratio of three or four and a verdict of catastrophe on perfectly ordinary history.
So this one opens a trade, resolves it, and only then looks for the next entry. Fewer trades from the same history, and a sequence whose runs mean something. Expect a much lower trade count than the other two give on the same chart — that is the rule working, and the table labels the row so the difference is visible rather than mysterious.
Method, and its limits
A bar spanning both stop and target counts as a loss. There is no way to know which came first from bar data, and being wrong pessimistically is the only honest resolution. It matters more here than in the companion scripts: resolving those ties optimistically would break up runs and flatter every streak on the chart.
Distances can scale with each historical bar's own ATR, so the test uses the volatility of the time rather than today's.
Trades reaching neither level within the holding window are reported as timed out, not counted as losses. Counting them as losses would manufacture runs that never happened.
Fifty resolved trades is the floor. Below that the script refuses to compare, and says so. A streak is a tail statistic and needs more sample than an average does — a hit rate stabilises long before the longest run does.
The formula assumes independent trades. If your own trades overlap in time, or fire on correlated instruments, your effective sample is smaller than your trade count, the expected run is correspondingly smaller, and your real run is worse than the ratio suggests. The non-overlapping rule handles this inside the script; it cannot handle it for the strategy you are comparing against.
It is an expectation, not a bound. Runs longer than it are ordinary. The distribution has a tail on both sides, and a single measurement on one window settles nothing — run it across several.
What it is not
It places no trades, gives no signals and predicts nothing. It cannot tell you a strategy is broken. It tells you whether a losing run is evidence of anything, which is a smaller and more useful question, and the answer is usually no.
Open source. Companion to Edge Reality Check, which measures the hit rate entering at random would have produced at your reward-to-risk, and Filter Reality Check, which tells you whether a condition you are using beats that baseline.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.