OPEN-SOURCE SCRIPT
ที่อัปเดต:

Market Cycle

217
# Market Cycle (SMA200 Slope / ATR)

**A regime classifier for long-term investors.** It labels the market as **UPTREND**, **DOWNTREND**, or **SIDEWAYS** by reading the *slope* of the Daily 200-period SMA, normalized by ATR so the reading is comparable across any symbol regardless of price or volatility. A hysteresis band and directional memory keep the state stable — it commits to a regime and holds it until the trend genuinely turns, instead of flipping on every wiggle.

## How it works

1. **ATR-normalized slope.** The per-bar change of the Daily SMA200 over a lookback window is divided by ATR (and ×100 for readability). This expresses the trend's strength in "ATRs per bar," a volatility-neutral unit that behaves the same on a $5 stock and a $5,000 index.
2. **Hysteresis state machine.** Entering a trend requires the slope to cross an **enter threshold**; leaving it only happens once the slope falls back through a lower **exit threshold**. The gap between the two creates a sticky band that filters noise and prevents whipsaw.
3. **Directional memory (continuation discount).** After a pause, re-entering the *same* direction the market just came from is treated as continuation and needs a smaller threshold, while a full reversal still requires the complete enter threshold. This makes the indicator resume established trends quickly but stay skeptical of reversals.
4. **Daily-locked & multi-timeframe consistent.** The signal and the entire state machine run inside the Daily context. The committed regime on a closed Daily bar is therefore **identical whether you view the Daily, Weekly, or Monthly chart** — no timeframe disagreement.

## Features

- **Regime coloring** — green (uptrend), red (downtrend), gray (sideways) applied to the SMA200 line and an optional background tint.
- **Sideways memory color** — optionally keep the prior trend's color during a pause, so you can see which trend the sideways phase came out of.
- **Trend age counter** — Daily bars since the last reversal (shown in the status line), continues counting through sideways pauses and only resets on a genuine trend flip.
- **Status line readout** — normalized slope value and trend age, without cluttering the price scale.
- **No repaint on history** — history is leak-free (`lookahead_off`); the current forming Daily bar updates in real time and locks at the Daily close.

## Inputs

- **SMA length / Slope lookback / ATR length** — the core signal parameters.
- **Enter & Exit thresholds** — width of the hysteresis band (in ATR/bar ×100).
- **Re-entry factor** — how much cheaper continuation is versus a fresh entry (0–1).
- **Visualization toggles** — SMA200 line, background tint, and sideways-color behavior.

## How to use

Use it as a **top-down regime filter**: take long-side setups only while the state is UPTREND, stand aside or reduce risk in SIDEWAYS, and treat DOWNTREND as a defensive/cash regime. Because the state is Daily-locked, it pairs well with a Weekly or Monthly chart for position-level context while you execute on lower timeframes.

*This indicator is a market-condition tool, not a buy/sell signal. It does not account for fundamentals, news, or risk management. Past regime behavior does not guarantee future results — always do your own research.*
Release Note
Update input defaults
Release Note
- **Trend age counter now measures calendar days.** Previously it counted Daily bars since the last reversal, which skips weekends and market holidays and so understated the real elapsed time (a full-year trend read ~250 instead of ~365). It is now derived from bar timestamps, so the count reflects actual calendar days elapsed. The continue-through-sideways and reset-on-reversal behavior is unchanged.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน