OPEN-SOURCE SCRIPT
Updated

Regime [CHE]

111
Regime [CHE] — Minimal HTF MACD histogram regime marker with a simple rising versus falling state.

Summary

Regime [CHE] is a lightweight overlay that turns a higher-timeframe-style MACD histogram condition into a simple regime marker on your chart. It queries an imported core module to determine whether the histogram is rising and then paints a consistent marker color based on that boolean state. The output is intentionally minimal: no lines, no panels, no extra smoothing visuals, just a repeated marker that reflects the current regime. This makes it useful as a quick context filter for other signals rather than a standalone system.

Motivation: Why this design?

A common problem in discretionary and systematic workflows is clutter and over-interpretation. Many regime tools draw multiple plots, which can distract from price structure. This script reduces the regime idea to one stable question: is the MACD histogram rising under a given preset and smoothing length. The core logic is delegated to a shared module to keep the indicator thin and consistent across scripts that rely on the same definition.

What’s different vs. standard approaches?

Reference baseline: A standard MACD histogram plotted in a separate pane with manual interpretation.
Architecture differences:

Uses a shared library call for the regime decision, rather than re-implementing MACD logic locally.
Uses a single boolean output to drive marker color, rather than plotting histogram bars.
Uses fixed marker placement at the bottom of the chart for consistent visibility.
Practical effect:

You get a persistent “context layer” on price without dedicating a separate pane or reading histogram amplitude. The chart shows state, not magnitude.

How it works (technical)

1. The script imports `chervolino/CoreMACDHTF/2` and calls `core.is_hist_rising()` on each bar.
2. Inputs provide the source series, a preset string for MACD-style parameters, and a smoothing length used by the library function.
3. The library returns a boolean `rising` that represents whether the histogram is rising according to the library’s internal definition.
4. The script maps that boolean to a color: yellow when rising, blue otherwise.
5. A circle marker is plotted on every bar at the bottom of the chart, colored by the current regime state. Only the most recent five hundred bars are displayed to limit visual load.

Notes:

The exact internal calculation details of `core.is_hist_rising()` are not shown in this code. Any higher timeframe mechanics, security usage, or confirmation behavior are determined by the imported library. (Unknown)

Parameter Guide

Source — Selects the price series used by the library call — Default: close — Tips: Use close for consistency; alternate sources may shift regime changes.
Preset — Chooses parameter preset for the library’s MACD-style configuration — Default: 3,10,16 — Trade-offs: Faster presets tend to flip more often; slower presets tend to react later.
Smoothing Length — Controls smoothing used inside the library regime decision — Default: 21 — Bounds: minimum one — Trade-offs: Higher values typically reduce noise but can delay transitions. (Library behavior: Unknown)

Reading & Interpretation

Yellow markers indicate the library considers the histogram to be rising at that bar.
Blue markers indicate the library considers it not rising, which may include falling or flat conditions depending on the library definition. (Unknown)
Because markers repeat on every bar, focus on transitions from one color to the other as regime changes.
This tool is best read as context: it does not express strength, only direction of change as defined by the library.

Practical Workflows & Combinations

Trend following:

Use yellow as a condition to allow long-side entries and blue as a condition to allow short-side entries, then trigger entries with your primary setup such as structure breaks or pullback patterns. (Optional)
Exits and stops:

Consider tightening management after a color transition against your position direction, but do not treat a single flip as an exit signal without price-based confirmation. (Optional)
Multi-asset and multi-timeframe:

Keep `Source` consistent across assets.
Use the slower preset when instruments are noisy, and the faster preset when you need earlier context shifts. The best transferability depends on the imported library’s behavior. (Unknown)

Behavior, Constraints & Performance

Repaint and confirmation:


This script itself uses no forward-looking indexing and no explicit closed-bar gating. It evaluates on every bar update.
Any repaint or confirmation behavior may come from the imported library. If the library uses higher timeframe data, intrabar updates can change the state until the higher timeframe bar closes. (Unknown)
security and HTF:

Not visible here. The library name suggests HTF behavior, but the implementation is not shown. Treat this as potentially higher-timeframe-driven unless you confirm the library source. (Unknown)
Resources:

No loops, no arrays, no heavy objects. The plotting is one marker series with a five hundred bar display window.
Known limits:

This indicator does not convey histogram magnitude, divergence, or volatility context.
A binary regime can flip in choppy phases depending on preset and smoothing.

Sensible Defaults & Quick Tuning

Starting point:

Source: close
Preset: 3,10,16
Smoothing Length: 21

Tuning recipes:

Too many flips: choose the slower preset and increase smoothing length.
Too sluggish: choose the faster preset and reduce smoothing length.
Regime changes feel misaligned with your entries: keep the preset, switch the source back to close, and tune smoothing length in small steps.

What this indicator is—and isn’t

This is a minimal regime visualization and a context filter. It is not a complete trading system, not a risk model, and not a prediction engine. Use it together with price structure, execution rules, and position management. The regime definition depends on the imported library, so validate it against your market and timeframe before relying on it.

Disclaimer

The content provided, including all code and materials, is strictly for educational and informational purposes only. It is not intended as, and should not be interpreted as, financial advice, a recommendation to buy or sell any financial instrument, or an offer of any financial product or service. All strategies, tools, and examples discussed are provided for illustrative purposes to demonstrate coding techniques and the functionality of Pine Script within a trading context.

Any results from strategies or tools provided are hypothetical, and past performance is not indicative of future results. Trading and investing involve high risk, including the potential loss of principal, and may not be suitable for all individuals. Before making any trading decisions, please consult with a qualified financial professional to understand the risks involved.

By using this script, you acknowledge and agree that any trading decisions are made solely at your discretion and risk.

Do not use this indicator on Heikin-Ashi, Renko, Kagi, Point-and-Figure, or Range charts, as these chart types can produce unrealistic results for signal markers and alerts.

Best regards and happy trading

Chervolino

MACD HTF Hardcoded
MACD HTF Hardcoded (A/B Presets) + Regimes [CHE]

Release Notes
Update Description

This update adds an advanced alert handler for regime changes:

Confirmation logic: Alerts can be restricted to bar close and require N consecutive confirming bars.

Cooldown: Optional bar-based cooldown to prevent alert spam during choppy conditions.

Three alert types: Dedicated alertcondition() outputs for Regime Up, Regime Down, and Regime Flip.

Optional runtime alerts: Additional alert() firing for webhook-style setups.

Message format: Runtime alert() messages can be sent in Simple or JSON format.

Fix included: Removed an invalid na() check on a boolean series (compile error resolved).

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.