Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Inside-Bar Outcome Tracker: Breakout Direction, Failure Rate and Time to Resolve - indicator for MetaTrader 5

Views:
23
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Inside-Bar Outcome Tracker: Breakout Direction, Failure Rate and Time to Resolve

OVERVIEW

The inside bar is one of the most common patterns on a chart, and it comes with a lot of folklore: "the market is coiling and will break out", "trade the side that breaks first", "two inside bars are better than one", "the first breakout is usually a trap". Each of these statements can be checked against the history of a symbol, and the check needs no model, only counting. The indicator does the counting and shows the result on your own symbol, timeframe and broker data.

The definitions are short:

  • Mother bar. The bar whose range holds the next bars. After a breakout, the breakout bar becomes the next mother bar.
  • Inside bar. A closed bar whose high is not above the mother high and whose low is not below the mother low. A difference of less than half a point counts as equal, so a bar that touches the edge of the mother bar is still inside.
  • Pattern. A mother bar followed by one or more inside bars and then a bar that leaves the mother range. That bar is the breakout bar. The number of inside bars before it is the time to resolve, counted in bars.
  • Direction. The breakout bar went above the mother high (up), below the mother low (down), or broke both sides in one bar (both sides, an outside bar). A breakout of both sides has no direction and has its own column.
  • Hold window. The first InpHoldBars closes starting with the close of the breakout bar. If any of these closes is back inside the mother range, the breakout failed. If all of them stay beyond the broken side, it held. Until the window is over the pattern is pending, and pending patterns are left out of the failure rate.
  • Minimum mother size. The range of the mother bar is measured in ATR (Wilder, taken at the bar before the mother bar). A mother bar smaller than InpMinMotherAtr is not counted, because a tiny mother bar is easy to leave.

The statistics are kept for all patterns together and for six groups that do not overlap inside their own split: 1, 2 and 3 or more inside bars, and mother bars smaller than InpBucket1 ATR, between the two borders, and larger than InpBucket2 ATR. Every pattern is in the first row, in one length row and in one size row.

There is no look-ahead. A bar is judged only after it has closed. The bar that is still forming is shown with the state of the closed bars and is never counted, because its high and low can still move. The calculation is incremental: on every call only the new bars and the bar that was still forming are processed, the counts live in small fixed tables, and the pending breakouts are kept in a short list, so the history is never rescanned.

How to interpret it

  • Histogram (indicator window). One bar at every breakout bar of a counted pattern. Its height is the number of inside bars before the breakout, positive for a break up and negative for a break down. The color is the state of the pattern: white while the hold window is open, gray when the breakout held, dark gray when it failed. A pending breakout changes color within a few bars.
  • Dot on the zero line. A breakout bar that broke both sides of the mother bar.
  • Data Window.
    • "Inside bars before the break (+ up, - down)": the histogram value.
    • "Both sides broken": 0 at an outside breakout.
    • "Inside bars in the open pattern": the number of inside bars of the mother bar that is open after this bar.
    • "Mother range at the break (ATR)": the size of the mother bar in ATR, shown at the breakout bar.
  • Boxes (main chart). One box for every counted pattern, from the mother bar to the breakout bar and from the mother low to the mother high. White solid: pending. Gray solid: held. Dotted: failed. Dashed: both sides broken. A dash-dot box runs to the newest bar and shows the mother bar that has at least one inside bar right now. Only the newest InpMaxShown patterns keep their box.
  • Panel (top left of the chart).
    • Line 1: symbol, timeframe, number of closed bars analysed, the hold window and the minimum mother size.
    • Line 2: number of patterns, how many are pending, and the shares of up, down and both-sides breakouts.
    • Line 3: held, failed and the failure rate (failed divided by held plus failed).
    • Line 4: the number of inside bars before the break: median, the value that covers 90% of the patterns, and the longest (more than 20 is counted as 20).
    • Line 5 to 11: the column names and the six groups, each with the number of patterns, up, down, both sides and the failure rate with the number of decided patterns in brackets. Percentages show "--" when a row has fewer than InpMinCases patterns.
    • "now" line: the mother bar of the open pattern, its inside bars so far and its size in ATR.
    • Last line: one line to copy, with symbol, timeframe, bars, patterns, the three direction shares, the failure rate and the median.


Fig. 1. The last 60 bars of a simulated H1 series. The boxes mark the patterns (solid: pending or held, dotted: failed, dashed: both sides broken, dash-dot: the mother bar that is open now). The histogram shows the inside bars before each breakout, positive for a break up and negative for a break down. The panel counts all 1,199 closed bars. The data is simulated, so the numbers say nothing about any real market. Black and white screenshot, per the Code Base image guidelines.

External variables (inputs)

Input Default Purpose
InpMinMotherAtr 0.5 Smallest mother bar range that counts, in ATR (0-10). 0 counts every pattern.
InpHoldBars 3 Number of closes in the hold window; the close of the breakout bar is the first (1-10).
InpAtrPeriod 14 Period of the Wilder ATR that measures the mother bar (2-100). The first InpAtrPeriod analysed bars only build the ATR, so no pattern can start in them.
InpHistoryBars 20000 Newest bars analysed when the indicator loads or is fully recalculated. 0 analyses all bars. New bars are added as they arrive.
InpBucket1 1.0 Upper border of the small mother bars, in ATR.
InpBucket2 1.5 Upper border of the medium mother bars, in ATR. It is kept above InpBucket1 .
InpMinCases 20 Fewest patterns before a row shows percentages (5-500).
InpShowBoxes true Draw a box for every pattern.
InpMaxShown 40 Newest patterns that keep their box (0-500). The statistics always use all patterns.
InpShowPanel true Show the statistics panel.
InpHeldColor clrGray Color of a breakout that held (histogram and box).
InpFailedColor clrDimGray Color of a breakout that failed.
InpPendingColor clrWhite Color of a breakout in its hold window and of the open pattern.
InpOutsideColor clrSilver Color of a breakout of both sides (dot and box).
InpTextColor clrSilver Panel text color.
InpFontSize 8 Panel font size (Consolas). The line height follows the size.
InpPanelX , InpPanelY 8, 14 Panel offset from the upper left corner of the chart, in pixels.

Recommended use

  • Symbols and timeframes. Any symbol and any timeframe. On higher timeframes patterns are few, and a row needs InpMinCases patterns before it shows percentages. On D1 a few thousand bars give only a few hundred patterns, so load enough history through InpHistoryBars .
  • Number of patterns. Fewer than about 100 patterns in a row means that its percentages move by many points when one pattern is added. Look at the "n" column before the percentages.
  • Direction shares. If bars were random, up and down would be close to equal. A clear difference is worth checking on another part of the history by changing InpHistoryBars . Both-sides breakouts are not a failure and not a direction, and they are the reason why the up and down shares do not add up to 100%.
  • The failure rate depends on the hold window. A window of one bar only asks whether the breakout bar itself closed beyond the mother range. A longer window is stricter, so the failure rate grows with InpHoldBars . Compare symbols only with the same inputs.
  • The mother-size filter changes the picture. Small mother bars are broken by almost anything, large mother bars are broken less often. Use the size rows of the panel to see this on your symbol, and raise InpMinMotherAtr to leave the smallest patterns out.
  • How a pattern is counted. A bar that leaves the mother range always becomes the next mother bar, also when it ends a pattern that is too small to count. Several inside bars in a row belong to one pattern. A breakout without an inside bar before it is not a pattern.
  • Failure is measured on closes. A breakout whose bar closed beyond the mother range and then closed back inside within the window is a failure, also when the bar was a strong one. The indicator does not look at wicks, and it does not include spread, swap or slippage. Statistics like these are not a trading result.
  • The data is the broker's data. Highs, lows and the time of the bars depend on the broker's feed and time zone. The same symbol can give a slightly different table on another broker.
  • It describes the past. The table shows what was usual in the loaded history. It does not predict the next pattern.
  • Performance and memory. Each bar is processed once, and later ticks only handle the newest bar, the pending breakouts and the panel. A pattern takes about 80 bytes, the indicator has six buffers, and the boxes are limited by InpMaxShown .
  • Chart objects. The boxes and the panel lines are objects in the main chart window, named with the prefix IB_ . They are removed in OnDeinit() and when the history is recalculated.
  • Account types. The indicator does not trade and does not depend on netting or hedging accounts.
  • Your turn: post your numbers. Attach the indicator to a chart you trade, copy the last line of the panel and post it in the comments with the name of your broker. This is only the format, and its numbers are made up: EURUSD H1 | 20000 bars | patterns 1480 | up 44% dn 43% both 13% | failure 61% | median 1 . Which symbols break up more often than down? On which timeframe do inside-bar breakouts fail least? Does a second inside bar change the failure rate on your symbol?
Daily Loss Limit Guard - close all and stay flat after the daily limit Daily Loss Limit Guard - close all and stay flat after the daily limit

A simple account guard: once the day's loss (equity against the balance at the start of the day) reaches your limit, it closes all positions, deletes pending orders and keeps the account flat until the next day. Works on manual trades and on any EA. Never opens trades.

Break-Even Stop Mover with Locked Profit Break-Even Stop Mover with Locked Profit

Moves the stop loss of open positions to break-even plus a small locked profit once they reach a profit trigger. Works on manual trades and on trades from any other EA (magic filter). Never opens or closes trades and never moves a stop backwards.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.