OPEN-SOURCE SCRIPT
Telah dikemas kini

ATR Stop Oscillator

383
**What This Indicator Does — In Plain Terms**

This is a trend-following tool that measures how far price has moved away from its own volatility-based "safety line" (the ATR trailing stop), and displays that distance as a bar chart (histogram) below your main price chart — similar in spirit to how RSI or MACD sits below the chart, except this one is tracking distance from a trailing stop instead of momentum.

Here's the core idea in one sentence: **the indicator draws an invisible line that trails behind price and adjusts itself based on volatility (ATR), and the oscillator shows you how many "ATR units" price currently is above or below that line.**

- When the bars are **green and above the zero line**, price is above its trailing stop — meaning the trend is currently bullish/long-favoring.
- When the bars are **red and below the zero line**, price is below its trailing stop — meaning the trend is currently bearish/short-favoring.
- The **farther the bar is from zero**, the more "stretched" price is from its stop, in multiples of ATR (e.g., a reading of 3.0 means price is 3 full ATR units away from the stop line).
- When the bars **flip from red to green (or vice versa)**, that's a trend change — and that's exactly what triggers your alert.

---

**Input-by-Input Breakdown**

**Non-Repainting Signals (`ConfirmOnClose`)**
- **What it does:** Controls whether the trend-change alert waits for the current candle to fully close before firing, or fires immediately as soon as the condition is met — even mid-candle.
- **Why it matters:** If left ON (default), you avoid false or "fake" signals that flip back and forth while a candle is still forming — the alert only confirms once the bar is locked in. If turned OFF, you'll get faster signals, but some of them may reverse or disappear before the candle actually closes, since price is still moving. Think of it as a tradeoff between speed and reliability.
- **Practical use:** Leave this ON for swing trading or anything where you can't watch the chart constantly. Turn it OFF only if you're actively watching the screen and want the earliest possible warning, accepting the risk of a signal that later gets invalidated.

**ATR Period (`Atr`)**
- **What it does:** Sets how many bars are used to calculate the Average True Range (ATR) — the volatility measurement this whole indicator is built on. Default is 5.
- **Why it matters:** A shorter period (like 5) makes the ATR — and therefore the trailing stop and oscillator — more reactive to recent price swings, so it adjusts quickly but can feel "twitchy" or noisy. A longer period (like 20 or 50) smooths things out, making the stop line and oscillator move more slowly and steadily, but it'll lag behind sudden volatility changes.
- **Practical use:** Lower values suit fast-moving or short-timeframe trading (scalping, day trading). Higher values suit slower, longer-term trend following where you don't want to be shaken out by every small wiggle.

**Multiplier (`Mult`)**
- **What it does:** Multiplies the ATR value to determine how far away the trailing stop sits from price. Default is 5.
- **Why it matters:** This directly controls how "loose" or "tight" your trailing stop is. A higher multiplier (like 5 or higher) gives price more room to breathe before the trend is considered reversed — fewer false flips, but bigger moves against you before you get an alert. A lower multiplier (like 1 or 2) tightens the stop, giving you faster trend-change signals, but at the cost of more false flips during choppy/sideways price action.
- **Practical use:** This is your single biggest lever for tuning sensitivity. Tighten it if you're getting alerts too late or missing moves; loosen it if you're getting whipsawed by too many false trend-change alerts during sideways markets.

**Above Stop Color (`PosColor`)**
- **What it does:** Sets the color of the oscillator bars when price is above the trailing stop (positive/bullish readings). Default is green.
- **Why it matters:** Purely visual — it does not affect any calculation, alert, or signal logic. It only changes what you see on the chart.
- **Practical use:** Adjust this to match your personal chart theme or color-blind-friendly palette if needed. No functional impact either way.

**Below Stop Color (`NegColor`)**
- **What it does:** Sets the color of the oscillator bars when price is below the trailing stop (negative/bearish readings). Default is red.
- **Why it matters:** Same as above — cosmetic only, no effect on calculations or alerts.
- **Practical use:** Same as above — purely a visual preference setting.

---

**What You'll See on the Chart**

- A **histogram (bar chart)** oscillating above and below a dashed gray zero line, in your own separate pane below the price chart.
- **Green bars** = price above the ATR trailing stop (bullish state).
- **Red bars** = price below the ATR trailing stop (bearish state).
- **No labels or markers** on the price chart itself — you removed those. All the trend information lives in this oscillator pane only.

**What Triggers an Alert**

- The alert fires only on an actual **trend flip** — meaning the internal trend direction changed from bullish to bearish or vice versa, not just because the oscillator crossed zero on a fluke tick.
- You'll get one alert message telling you whether it flipped **BULLISH** or **BEARISH**, plus two separate alert conditions in TradingView's alert menu if you'd rather set them up individually.

If any of this doesn't match how you're actually planning to use it (e.g., you want the color inputs to also influence something functional, or you want a numeric readout of the current ATR-multiple value), tell me and I'll adjust — I didn't want to assume beyond what's in the script.
Nota Keluaran
# ATR Stop Oscillator — Change Log
**Original upload → Current version (v2)**

Core math is untouched: the trailing stop, trend flips, and every histogram bar calculate exactly as before. All changes are visual, alert-related, or settings-related.

## New: Signal Line (Moving Average)
- Moving average plotted over the histogram (default: 9-period EMA) for reading momentum and pullbacks within a trend.
- New "Signal Line" settings group with: on/off toggle, MA type (Simple, Exponential, Weighted, Smoothed/Wilder, Hull, Volume-Weighted), length (1–500), color picker, and line thickness (1–5, defaults to thinnest).

## Overhauled: Histogram Coloring
- New dropdown with three styles:
- **Solid** — the original two-color look, preserved exactly.
- **Magnitude Gradient** (new default) — dark near zero, bright at the extremes; bright = plenty of room to the stop, dark = price hugging the stop.
- **Slope (4-Color)** — MACD-style; bright = gap to the stop expanding, dark = shrinking (early flip warning).
- All shading is fully solid — no see-through fading — so bars stay readable on any chart background.
- Four color pickers (Bull Strong/Weak, Bear Strong/Weak) on paired rows, replacing the original two.
- Brighter defaults (vivid green/red + deep forest green/dark maroon), tuned for dark charts.

## Alerts
- **New:** two signal-line cross alerts — histogram crossing above or below its MA.
- **Fix:** the "Non-Repainting Signals" switch now controls *all* alerts. Originally the automatic pop-up alert always waited for candle close regardless of the setting. Now: ON = every alert waits for the close (safe, no false signals); OFF = alerts fire live intrabar (faster, can repaint).
- Original "Trend Change: Bullish/Bearish" alerts kept under the same names — existing alerts keep working.

## Settings
- Multiplier now adjustable in 0.1 steps with a 0.5 minimum (was whole numbers, minimum 1).
- Inputs organized into named groups ("Signal Line," "Oscillator Style").

## Housekeeping (no visible effect)
- Removed redundant look-back instructions in the internal logic — identical behavior, cleaner code.
- Added explanatory comments throughout for future editing.

## Unchanged
ATR stop calculation, flip/reset logic, oscillator formula, bar heights and timing, original alert names, default ATR period (5) and multiplier (5). With Solid coloring and the signal line hidden, output is identical to the original.

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.