Candle Streak Statistics: Analysis of Consecutive Same-Color Bars
Info
The Candle Streak Statistics: Analysis of Consecutive Same-Color Bars is a Indicator for MetaTrader 5 that candle streak statistics: analysis of consecutive same-color barsthe idea behind itmany traders have opinions about consecutive runs of candles. For instance, after five green bars in a row, some believe it's overextended and must turn, while others think it has momentum and will continue.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Indicator works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Indicators folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Candle Streak Statistics: Analysis of Consecutive Same-Color Bars
1. Installation: Place your file in the MQL/Indicators folder via "Open Data Folder" and restart your terminal.
2. Loading: Find the indicator in the Navigator, drag it onto your chart, and configure the input parameters in the popup window.
3. Customization: Press Ctrl+I to open the indicator list, select your tool, and click "Properties" to change colors, levels, or visual styles.
4. Updating: Replace the old file in the Indicators folder with the new version and restart the platform to apply changes.
Frequently Asked Questions
Q: Why is my indicator not showing? A: Verify the file is in the MQL/Indicators folder, or try right-clicking the "Indicators" tree in the Navigator and clicking "Refresh."
Q: Do custom indicators slow down the platform? A: Too many complex indicators can impact performance; remove unused ones via the "Indicator List" (Ctrl+I).
Q: Can I use MT4 indicators on MT5? A: No, MQL4 and MQL5 are distinct languages; ensure the indicator is compiled specifically for your platform version.
What this tool does
Candle Streak Statistics: Analysis of Consecutive Same-Color BarsThe Idea Behind ItMany traders have opinions about consecutive runs of candles.
Typical Use Case
This Indicator excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Indicator works on MetaTrader 5. Place the file in the MQL5/Indicators folder and restart the terminal.
Description & Settings
Related: Candle Timer and Spread Indicator - another powerful indicator for MetaTrader 5 traders.
Candle Streak Statistics: Analysis of Consecutive Same-Color BarsAlso recommended: Ezo Candle Timer: Real-time Candle Expiry, Spread, and Daily Range - similar indicator with strong performance on MetaTrader 5.
The Idea Behind ItMany traders have opinions about consecutive runs of candles. For instance, after five green bars in a row, some believe it's overextended and must turn, while others think it has momentum and will continue. Both opinions can be rigorously tested by examining historical data. The test involves identifying every instance where a run of N bars of the same color has just ended, and then observing the behavior of the subsequent bar. Unlike most streak indicators that only count the bars within the current run, this tool analyzes what happened *after* the run concludes, tailored to your specific symbol, timeframe, and broker's data.
Definitions:
Bar Color: A bar is considered 'up' if its close is higher than its open, and 'down' if its close is lower than its open. A bar with a body of at most InpDojiPoints points (defaulting to 0, meaning only bars with an equal open and close price) is classified as a doji. A doji has no color and signifies the end of a run.
Run: The number of consecutive bars of the same color, ending at a specific bar. A run is positive for up bars and negative for down bars.
Row N: Represents the moments when the run ending at a given bar is exactly N bars long. The last row, denoted as '7+', captures all runs of 7 bars or more. Each bar belongs to only one row, ensuring that rows do not overlap. For example, a run of five bars progresses through rows 1, 2, 3, 4, and 5 sequentially.
Outcome: The bar immediately following a run either continues the streak (same color), reverses it (opposite color), or is a doji. 'cont%' indicates the proportion of cases where the run continued, representing the probability that a run of length N extends to N+1 bars.
Baseline: In a scenario of independent bars, a run would continue with a frequency equivalent to the overall occurrence of bars of that color. Therefore, the baseline for up runs is the historical share of up bars, and for down runs, it's the share of down bars. A 'cont%' above the baseline suggests a tendency for runs to continue, while a 'cont%' below it indicates a tendency to reverse.
Next: This measures the average movement of the subsequent bar in the direction of the run, calculated from its open to its close. This movement is expressed in terms of the ATR (Average True Range) of the preceding bar. A positive value indicates that, on average, the next bar moved in sync with the run; a negative value suggests it moved against the run.
Z: This quantifies how many standard errors the 'cont%' is from the baseline. A row is marked with an asterisk (*) if it has at least InpMinCases and its z-score meets or exceeds InpZFlag. Rows with fewer cases are marked with '--' as percentages derived from very small sample sizes are not statistically significant.
There is no look-ahead bias in this indicator. Each bar is displayed with statistics based on completed preceding bars. Its own outcome is added to the table only after it has been fully processed. A bar that is still forming is shown with statistics from closed bars, but it is not included in the calculations because its color can still change. The calculation is incremental; on each update, only the new bars and the bar currently forming are processed. Counts are maintained in small, fixed-size tables, eliminating the need to rescan historical data.
How to Interpret the Data
Histogram (Indicator Window):
Each bar in the histogram represents a bar on the chart. Its height indicates the length of the run ending with that bar: white bars above zero signify up runs, while gray bars below zero denote down runs. Doji bars do not generate a histogram bar. The dotted line represents zero.
Data Window:
'Continued before, same streak (%)': Displays the historical frequency of a run of a specific length continuing prior to the current bar.
'Cases before, same streak': Shows the number of instances that form the basis for the 'Continued before, same streak (%)' calculation.
'Next bar before, in streak direction (ATR)': Indicates the average movement of the subsequent bar in the direction of the run, measured in ATR, based on historical data preceding the current bar.
Panel (Top-Left of the Chart):
Line 1: Displays the symbol, timeframe, and the total number of closed bars analyzed.
Line 2: Lists the column headers. 'UP n' and 'DN n' denote the number of cases following up runs and down runs, respectively.
Subsequent lines: Present data for each run length up to InpMaxLen. For each length, four figures are shown for both up and down runs: number of cases, continuation rate (cont%), average next bar movement (in ATR), and the asterisk (*) mark for statistically significant deviations from the baseline.
Baseline line: Shows the historical proportions of up bars, down bars, and dojis, along with the settings used for the asterisk marking.
Now line: Displays the run of the most recent bar and the historical statistics relevant to runs of that length.
Last line: Contains the symbol, timeframe, number of bars analyzed, the proportion of up bars, and the continuation rate after a run of InpReportLength bars (both up and down). This line is formatted for easy copying into a comment.
Fig. 1. An example of a simulated H1 series where runs tend to continue, illustrating the indicator's output. The histogram displays run lengths for the last 90 bars (white for up, gray for down, zero line dotted). The panel presents a table for 2,999 closed bars, showing cases, continuation rate, average next bar movement in ATR, and significance marks. Data is simulated and does not reflect real market conditions. This is a black and white screenshot adhering to Code Base image guidelines.
External Variables (Inputs):
Input
Default
Purpose
InpMaxLen
7
Defines the longest run with its own dedicated row (range: 2-12). Longer runs are grouped into the last row.
InpDojiPoints
0
A bar with a body size up to this many points is considered a doji (range: 0-100). Increase for symbols with many small-bodied bars.
InpAtrPeriod
14
The period for the Wilder's ATR calculation, used to measure the next bar's movement (range: 2-100). The initial bars used for ATR calculation are not included in the 'next' bar analysis.
InpHistoryBars
20000
The number of newest bars to analyze upon indicator load or full recalculation. A setting of 0 analyzes all available bars. New bars are added automatically as they arrive.
InpMinCases
30
The minimum number of cases required before a row displays percentages (range: 5-1000). This also influences the asterisk marking.
InpZFlag
2.0
The minimum z-score size for a row to receive an asterisk mark (range: 1-5).
InpReportLength
3
The run length used in the final line of the panel (range: 1-12). This value is capped at or below InpMaxLen.
InpShowPanel
true
Toggles the display of the statistics panel.
InpTextColor
clrSilver
Sets the color for the text within the panel.
InpFontSize
8
Sets the font size for the panel text (uses Consolas font). Line height adjusts accordingly.
InpPanelX , InpPanelY
8, 14
The offset in pixels from the upper-left corner of the chart for the panel's position.
Recommended Usage
Symbols and Timeframes:
This indicator is suitable for any symbol and timeframe. The statistics are specific to the symbol and timeframe they are applied to; therefore, H1 results will differ from M15. Apply it to the symbols you actively trade and compare the generated tables.
Number of Cases:
Longer runs are statistically rare. With only a few thousand bars of history, rows for runs of six or more bars may have only a few dozen cases, leading to volatile percentage figures. Prioritize examining the 'n' (cases) columns first. Ensure sufficient historical data is loaded via InpHistoryBars. Exercise caution when interpreting percentages from rows with fewer than 100 cases.
Interpreting Significance Marks (*):
A table can have up to 24 rows. With a z-score of 2, approximately 1 in 20 rows might be marked by chance alone; thus, one or two marks in an otherwise unremarkable table may not be significant. Rows representing consecutive run lengths are related because the same run progresses through them. A row with few cases does not constitute strong evidence, and the z-score calculation assumes case independence, which is not always true, especially during periods of volatile price action. Multiple marks in a row with the same sign might be more indicative than isolated ones.
Look for Consistency:
Adjust InpHistoryBars to analyze older and newer historical data segments independently. A pattern observed in one segment but absent in the other may not be a robust pattern.
Edge vs. Profit:
A continuation percentage (cont%) of 52% combined with an average next bar movement of +0.02 ATR might be smaller than the spread of many trading instruments. This indicator does not account for spread, swap, or slippage.
Bar Color Determination:
Bar color is determined by the relationship between the open and close prices (the body of the bar), not by the close price relative to the previous close. On symbols that exhibit opening gaps, a bar might be colored downwards even if its closing price is higher than the preceding bar's close. A run is counted across consecutive bars on the chart, thus continuing across weekends or session breaks.
Broker Data Dependency:
The open and close prices of a bar are influenced by the broker's data feed and its timezone. Consequently, the same symbol may yield slightly different results on different brokers.
Past Performance:
The statistics generated by this table reflect historical patterns observed in the loaded data. They do not provide predictive capabilities for future price movements.
Performance and Memory Usage:
The indicator utilizes tables containing a few dozen numerical values and employs six buffers. Subsequent tick updates primarily involve processing the newest bar and refreshing the panel. This design ensures efficient performance and minimal memory consumption.
Chart Objects:
The only graphical objects created are the panel lines displayed in the main chart window, prefixed with 'CS_'. These objects are automatically removed during the OnDeinit() function call.
Account Types:
This indicator is purely analytical; it does not engage in trading and is therefore compatible with both netting and hedging account types.
Share Your Findings:
Attach the indicator to a chart you actively trade. Copy the last line from the panel and post it in the comments, including your broker's name. The provided format is a template: EURUSD H1 | 20000 bars | up bars 50.1% | after 3 up: cont 49.4% (n=1450) | after 3 down: cont 50.2% (n=1432). By sharing your results, you can help identify which symbols exhibit trending runs and which tend to reverse. Compare observations on run lengths, such as a run of three versus a run of six, for your specific symbol.
You may also like: Ezo Smart Fibo: Intuitive Two-Click Fibonacci Tool with Candle Snap - excellent alternative for indicator users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 4
#property indicator_level1 0.0
#property indicator_levelcolor clrDimGray
#property indicator_levelstyle STYLE_DOT
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.