Jilly's Consolidation Breakout

713
**What it does**

This indicator finds consolidations: stretches where price makes no *appreciable* new high or low. It draws the range and signals when a bar closes outside it.

A strict "no new high, no new low" rule breaks on a one-tick poke, so the script measures from a fixed anchor bar with a tolerance:

1. **Anchor.** A run starts on an anchor bar. Its high and low are the reference, and ATR is frozen at that bar.
2. **No appreciable extremes.** Each new bar joins the run unless it trades more than **m × ATR** beyond the anchor's high or low. If it does, that bar becomes the new anchor.
3. **Width cap.** Before confirmation, the run is also abandoned if its total high-to-low range grows past **Max Width × ATR**. This keeps wide, drifting ranges from counting as consolidation.
4. **Confirmation.** Once the run reaches **N bars**, the box is drawn. Its top and bottom lock at the run's high and low on bar N. From then on, wicks beyond the box are absorbed: the side turns dotted, but the box stays alive.
5. **Breakout.** A confirmed box ends only when a bar **closes** beyond a trigger line. The triggers sit at anchor high + m × ATR and anchor low − m × ATR, drawn as dotted lines. That close is the signal. Signals use confirmed bars only and do not repaint.

**Trend filter (optional)**

Longs are taken only when the close is above the trend line, shorts only when below. The line is either:
- a monthly anchored VWAP (hlc3), which is the default, or
- an EMA.

A blocked breakout does nothing and is marked with a grey ✕ label.

**Simulated position and stop**

The script tracks one simulated position:
- **Entry.** A signal opens a trade at the signal bar's close. The stop is Stop × ATR away.
- **Repeat signal.** A further signal in the same direction tightens the stop to that bar's close ± "Tighten to" × ATR, only if that is tighter.
- **Opposite signal.** An opposite signal reverses the position.
- **Stop exit.** The trade exits intrabar when the stop trades. It fills at the stop, or at the bar's open if price gaps through.

On the chart:
- **Stop line:** the stop, stepping when it is tightened.
- **Open trade:** a red dashed risk box.
- **Closed trade:** a green or red result box with the net result.

**Performance table: hypothetical**

The table summarises the simulated trades on the loaded chart history:
- trades, win rate, profit factor, expectancy, net P&L and max drawdown;
- the open trade;
- a buy-and-hold comparison from the first entry.

These are **hypothetical results**. Fills are idealised (signal close and stop price), there are no partial fills or queue effects, and only the cost you enter is deducted (default 0). The figures depend on how much history the chart loads. They are not a strategy backtest and do not predict future results.

**Futures roll**

On futures, the script reads the current contract's last trading day:
- **Single-contract chart:** directly from the symbol.
- **Continuous chart (e.g. MNQ1!):** from the underlying contract.

It marks a roll date a set number of days before expiry. The default is 8, the usual CME equity index roll. The marker is a dashed vertical line, and the table shows it as "Next roll". The **Contract Roll** alert fires on the first bar on or after that date.

Only the current contract's date is available, so earlier rolls in the history are not marked. The simulated position is **not** closed at a roll.

On a continuous chart, enable **back-adjustment (B-ADJ)**. Without it, the price gap at each roll:
- shows up as false profit or loss in any simulated trade held across it, and
- distorts the monthly VWAP for the rest of that month.

**Alerts**

- **Long Breakout / Short Breakout.** A filtered signal at bar close: an entry, a reversal or a repeat signal.
- **Stop Exit.** The simulated stop was hit.
- **Contract Roll.** The roll date was reached.

Display options cover:
- trigger lines, signals, the stop line, trade labels and boxes;
- the table and its position;
- the roll marker and colours.

**Limitations**

- Low win rate by design: many small stop-outs and fewer large trend moves. Long losing streaks happen.
- Results vary a lot by symbol and timeframe. The defaults were chosen on an hourly index-futures chart and are not universal.
- Signals form at bar close. Real fills will differ from the close and from the stop price, especially on gaps and in fast markets.
- The roll date relies on the contract's expiry data. If TradingView does not provide it for a symbol, the roll features stay blank.

This script is for education and research. It is not financial advice and places no orders.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.