OPEN-SOURCE SCRIPT
تم تحديثه

[blackcat] L2 Price Envelope Tracker

5 279
Level: 2

Background

Price envelopes sare shown at a set percentage above and below a moving average. They are used to indicate overbought and oversold levels and can be traded individually or in conjunction with a momentum indicator.

Function

[blackcat] L2 Price Envelope Tracker is an innovative indicator that use customized envelope of price to disclose overbought and oversold periods. With this function, long and short entries can be further developped in this pine script.

Key Signal

sma5 --> typical price moving average line
resistance --> upper envelope as resistance line
support ---> lower envelope as support line

Pros and Cons

Pros:

1. easy observe overbought and oversold zone
2. disclose exact long and short entries in overbought and oversold zones


Cons:

1. Only applicable for the trading pairs that support financial() functions. crypto/xau/xag/indice are not applicable
2. Need to tune r1 and s1 for different trading pairs


Remarks

NA

Readme

In real life, I am a prolific inventor. I have successfully applied for more than 60 international and regional patents in the past 12 years. But in the past two years or so, I have tried to transfer my creativity to the development of trading strategies. Tradingview is the ideal platform for me. I am selecting and contributing some of the hundreds of scripts to publish in Tradingview community. Welcome everyone to interact with me to discuss these interesting pine scripts.

The scripts posted are categorized into 5 levels according to my efforts or manhours put into these works.

Level 1 : interesting script snippets or distinctive improvement from classic indicators or strategy. Level 1 scripts can usually appear in more complex indicators as a function module or element.

Level 2 : composite indicator/strategy. By selecting or combining several independent or dependent functions or sub indicators in proper way, the composite script exhibits a resonance phenomenon which can filter out noise or fake trading signal to enhance trading confidence level.

Level 3 : comprehensive indicator/strategy. They are simple trading systems based on my strategies. They are commonly containing several or all of entry signal, close signal, stop loss, take profit, re-entry, risk management, and position sizing techniques. Even some interesting fundamental and mass psychological aspects are incorporated.

Level 4 : script snippets or functions that do not disclose source code. Interesting element that can reveal market laws and work as raw material for indicators and strategies. If you find Level 1~2 scripts are helpful, Level 4 is a private version that took me far more efforts to develop.

Level 5 : indicator/strategy that do not disclose source code. private version of Level 3 script with my accumulated script processing skills or a large number of custom functions. I had a private function library built in past two years. Level 5 scripts use many of them to achieve private trading strategy.
ملاحظات الأخبار
This release responsed to Jittra inquiry to add support for XAU, XAG with this indicator. NOTE: different time frame requires different but proper r1 and s1 coefficients to be applicable.
ملاحظات الأخبار
OVERVIEW

This study tracks Level 2 price envelope dynamics using linear regression-adjusted moving averages and dynamic support/resistance zones. It provides real-time visual analysis of trend directionality and generates buy/sell signals based on multi-tier momentum checks.

FEATURES

Dual moving average system: Combines 5-period short-term and 18-period long-term averages adjusted with linear regression slope calculations
Dynamic zone creation: • Resistance level calculated via 12-period SMA × 1.06 coefficient • Support level determined using 10-period SMA × 0.95 multiplier
Advanced pattern detection using backward-looking index scanning (up to 1000 bars)
Visual indicators: ✔ Colored background alerts for confirmed signals ✔ Filled band between critical support/resistance zones changing color based on trend direction ✔ Key lines for trend identification (white line) and risk boundaries (yellow/purple zones)

HOW TO USE

Adjust input multipliers: • [Resistance Multiplier]: Modify 1.06 base value (range ≥1.00) • [Support Multiplier]: Adjust 0.95 base value (range ≥0.90)
Monitor trend direction via colored fill bands: ▶ Yellow indicates upward momentum dominance ▶ Purple signifies downward pressure advantage
Execute trades when: ✅ Lime background appears for confirmed buy setups ✅ Red highlighting confirms sell opportunities

LIMITATIONS

• Lag potential due to SMA-based foundation
• Over-reliance on historical pattern detection within limited lookback window
• Timeframe sensitivity affecting signal frequency/accuracy
• No volatility normalization mechanisms built-in

NOTES

• Uses Pine Script v4 requiring minimum TF multiplier consideration
• Signal validation employs three-stage comparison:

Cross-validation across 1-, 2-, and 3-bar offsets
Lookback confirmation across up to 1000 prior bars
Proximity check maintaining ≤2% deviation from critical support threshold
ملاحظات الأخبار
█ OVERVIEW

This indicator tracks an adaptive price envelope derived from linear-regression momentum and flags trend entries, exits, and ATR-based risk levels on any chart. Buy and sell labels, a color-coded envelope band, and a live position dashboard make signal states readable at a glance.

█ CONCEPTS

The script combines four layers of analysis:

 • Trend Baseline: two smoothed linear-regression baselines (short and long term) measure the direction and slope of momentum around price.
 • Price Envelope: support and resistance zones are projected from moving-average multipliers, and the band between them is shaded by envelope direction.
 • Signal Governance: signals are edge-triggered and passed through a position state machine with an optional cooldown and same-bar entry/exit exclusivity, so one signal means one state change.
 • Risk Overlay: stop-loss and take-profit reference levels are calculated from ATR multiples anchored to the entry price of the active position.

█ HOW TO USE

1 — Add the script to a candlestick chart; the Trend MA, Support Zone, and Resistance Zone plots appear immediately.
2 — Tune the Resistance/Support Multipliers and the MA lengths in the Signal group to fit the volatility of your symbol.
3 — Read signals from the labels, the shaded background, and the dashboard in the top-right corner.
4 — Create TradingView alerts from any of the five alert conditions; alerts are designed for bar-close confirmation.

Input Parameters
 • Resistance Multiplier / Support Multiplier: widen or narrow the envelope around the price averages (defaults 1.06 / 0.95).
 • Short/Long LR Length, Short/Long MA Length, LR Change Scale: control both trend baselines and how strongly regression change is scaled (defaults 4/5 and 10/18, scale 5).
 • Resistance MA Length / Support MA Length: averaging windows behind the envelope bands (defaults 12 / 10).
• Min Support/MA Ratio: optional strictness filter on the support band's distance below the trend baseline (default 0.90, lenient by default).
• Trend Lookback Bars: bars over which the baseline slope is measured (default 2).
• Envelope Touch Lookback: how recently price must have tagged the support/resistance zone for a signal to arm (default 3 bars).
 • Enable Lookback Pattern Filter / Pattern Lookback Bars: optional extra lookback confirmation, disabled by default.
 • Enable Short Signals: turn the sell side on or off for long-only trading (default on).
 • Same-bar Entry/Exit Exclusivity, Cooldown Bars: signal governance; cooldown of 0 disables the pause between signals (default 3 bars).
 • ATR Length, Stop Loss (xATR), Take Profit (xATR), Show TP/SL Levels: risk overlay settings (defaults 14, 2.0, 3.0).
 • Show Signal Labels / Show Position Background / Show Dashboard: visibility toggles for the visual layers.

█ FEATURES

 • Dual-direction Buy/Sell signals with a one-toggle long-only mode.
 • Position state machine: flat, long, or short; exits fire independently of entries.
 • ATR-based stop-loss and take-profit reference lines that follow the active position.
 • Five alert conditions (buy, sell, long exit, short exit, any entry) plus close-confirmed dynamic alerts.
 • Six-row status dashboard: position badge, baseline direction, last signal with bars-ago, entry price, SL/TP levels, and current ATR.

█ SIGNALS

Visual Elements
 • Buy label (green, below the bar): price tagged the support zone recently and the baseline turned up; the label prints the entry price plus SL/TP levels, and state switches to long.
 • Sell label (red, above the bar): price tagged the resistance zone while the baseline turned down, or the baseline pushed above the resistance envelope; the label prints entry price plus SL/TP levels, and state switches to short (when shorts are enabled).
 • XL / XS label (orange, above the bar): "Exit Long" / "Exit Short" — the opposite signal condition fired while a position was open; state returns to flat.
 • Envelope band shading: yellow while the trend MA rises, magenta while it falls.
 • Background tint: faint green while long, faint red while short.
 • Status dashboard (top-right): Position badge (LONG/SHORT/FLAT, color-coded), Baseline direction, Last Signal with bars-ago count, Entry price, SL/TP levels, and ATR.

█ IMPLEMENTATION NOTES

Open-source implementation built on ta.linreg for the regression baselines, ta.sma for the envelope bands, and ta.atr for the risk overlay. Signals are evaluated once per bar and alerts are confirmed at bar close; no higher-timeframe requests are used, so there is no lookahead. The position state is also exported to the data window for programmatic reading.

█ LIMITATIONS

 • Envelope multipliers are not universal — retune them per symbol and timeframe.
 • Ranging markets can still produce whipsaw signals; the cooldown filter reduces but does not eliminate them.
 • Default parameters were chosen for liquid, trending instruments; sparse symbols may need longer lookbacks.
 • TP/SL lines are visual reference levels, not automated orders — this is an indicator, not a strategy.

█ NOTES

 • Original concept and code by blackcat1402, released under the Mozilla Public License 2.0.
 • This version adds symmetric signal governance, ATR risk levels, dashboards, and alert coverage on top of the original envelope tracker.

════════════════════════════════════════════════════════════════════════
For questions or feedback, please use the comments section below.
Feel free to use and modify — attribution appreciated.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.