OPEN-SOURCE SCRIPT
Penguin Trend

Measures the volatility regime by comparing the upper Bollinger Band to the upper Keltner Channel and colors bars with a lightweight trend state. Supports SMA/EMA/WMA/RMA/HMA/VWMA/VWAP and a selectable calculation timeframe. Default settings preserve the original look and behavior.
Penguin Trend visualizes expansion vs. compression in price action by comparing two classic volatility envelopes. It computes:
Diff% = (UpperBB − UpperKC) / UpperKC × 100
* Diff > 0: Bollinger Bands are wider than Keltner Channels -> expansion / momentum regime.
* Diff < 0: BB narrower than KC -> compression / squeeze regime.
A white “Average Difference” line smooths Diff% (default: SMA(5)) to help spot regime shifts.
Trend coloring (kept from original):
Bars are colored only when Diff > 0 to emphasize expansion phases. A lightweight trend engine defines four states using a fast/slow MA bias and a short “thrust” MA applied to ohlc4:
* Green: Bullish bias and thrust > fast MA (healthy upside thrust).
* Red: Bearish bias and thrust < fast MA (healthy downside thrust).
* Yellow: Bullish bias but thrust ≤ fast MA (pullback/weakness).
* Blue: Bearish bias but thrust ≥ fast MA (bear rally/short squeeze).
Note: By default, Blue renders as Yellow to preserve the original visual style. Enable “Use true BLUE color” if you prefer Aqua for Blue.
How it works (under the hood):
* Bollinger Bands (BB): Basis = selected MA of src (default SMA(20)). Width = StdDev × Mult (default 2.0).
* Keltner Channels (KC): Basis = selected MA of src (default SMA(20)). Width = ATR(kcATR) × Mult (defaults 20 and 2.0).
* Diff%: Safe division guards against division-by-zero.
* MA engine: You can choose SMA / EMA / WMA / RMA / HMA / VWMA / VWAP for BB/KC bases, Diff smoothing, and the trend components (VWAP is session-anchored).
* Calculation timeframe: Set “Calculation timeframe” to compute all internals on a chosen TF via request.security() while viewing any chart TF.
Inputs (key ones):
* Calculation timeframe: Empty = use chart TF; if set (e.g., 60), all internals compute on that TF.
* BB: Length, StdDev Mult, MA Type.
* KC: Basis Length, ATR Length, Multiplier, MA Type.
* Smoothing: Average Length & MA Type for the “Average Difference” line.
* Trend Engine: Fast/Slow lengths & MA type; Signal (kept for completeness); Thrust length & MA type (defaults replicate original behavior).
* Display: Paint bars only when Diff > 0; optional Zero line; optional true Blue color.
How to use:
1. Regime changes: Watch Diff% or Average Diff crossing 0. Above zero favors momentum/continuation setups; below zero suggests compression and potential breakout conditions.
2. State confirmation: Use bar colors to qualify expansion: Green/Red indicate expansion aligned with trend thrust; Yellow/Blue flag weaker/contrarian thrust during expansion.
3. Multi-timeframe analysis: Run calculations on a higher TF (e.g., H1/H4) while trading a lower TF chart to smooth noise.
Alerts:
* Diff crosses above/below 0.
* Average Diff crosses above/below 0.
* State changes: GREEN / RED / YELLOW / BLUE.
Notes & limitations:
* VWAP is session-anchored and best on intraday data. If not applicable on the selected calculation TF, the script automatically falls back to EMA.
* Default parameters (SMA(20) for BB/KC, multipliers 2.0, SMA(5) smoothing, trend logic and bar painting) preserve the original appearance.
Release notes:
v6.0 — Rewritten in Pine v6 with structured inputs and guards. Multi-MA support (SMA/EMA/WMA/RMA/HMA/VWMA/VWAP). Calculation timeframe via request.security() for multi-TF workflows. Safe division; optional zero line; optional true Blue color. Original visuals and behavior preserved by default.
License / disclaimer:
© waranyu.trkm — MIT License. Educational use only; not financial advice.
Penguin Trend visualizes expansion vs. compression in price action by comparing two classic volatility envelopes. It computes:
Diff% = (UpperBB − UpperKC) / UpperKC × 100
* Diff > 0: Bollinger Bands are wider than Keltner Channels -> expansion / momentum regime.
* Diff < 0: BB narrower than KC -> compression / squeeze regime.
A white “Average Difference” line smooths Diff% (default: SMA(5)) to help spot regime shifts.
Trend coloring (kept from original):
Bars are colored only when Diff > 0 to emphasize expansion phases. A lightweight trend engine defines four states using a fast/slow MA bias and a short “thrust” MA applied to ohlc4:
* Green: Bullish bias and thrust > fast MA (healthy upside thrust).
* Red: Bearish bias and thrust < fast MA (healthy downside thrust).
* Yellow: Bullish bias but thrust ≤ fast MA (pullback/weakness).
* Blue: Bearish bias but thrust ≥ fast MA (bear rally/short squeeze).
Note: By default, Blue renders as Yellow to preserve the original visual style. Enable “Use true BLUE color” if you prefer Aqua for Blue.
How it works (under the hood):
* Bollinger Bands (BB): Basis = selected MA of src (default SMA(20)). Width = StdDev × Mult (default 2.0).
* Keltner Channels (KC): Basis = selected MA of src (default SMA(20)). Width = ATR(kcATR) × Mult (defaults 20 and 2.0).
* Diff%: Safe division guards against division-by-zero.
* MA engine: You can choose SMA / EMA / WMA / RMA / HMA / VWMA / VWAP for BB/KC bases, Diff smoothing, and the trend components (VWAP is session-anchored).
* Calculation timeframe: Set “Calculation timeframe” to compute all internals on a chosen TF via request.security() while viewing any chart TF.
Inputs (key ones):
* Calculation timeframe: Empty = use chart TF; if set (e.g., 60), all internals compute on that TF.
* BB: Length, StdDev Mult, MA Type.
* KC: Basis Length, ATR Length, Multiplier, MA Type.
* Smoothing: Average Length & MA Type for the “Average Difference” line.
* Trend Engine: Fast/Slow lengths & MA type; Signal (kept for completeness); Thrust length & MA type (defaults replicate original behavior).
* Display: Paint bars only when Diff > 0; optional Zero line; optional true Blue color.
How to use:
1. Regime changes: Watch Diff% or Average Diff crossing 0. Above zero favors momentum/continuation setups; below zero suggests compression and potential breakout conditions.
2. State confirmation: Use bar colors to qualify expansion: Green/Red indicate expansion aligned with trend thrust; Yellow/Blue flag weaker/contrarian thrust during expansion.
3. Multi-timeframe analysis: Run calculations on a higher TF (e.g., H1/H4) while trading a lower TF chart to smooth noise.
Alerts:
* Diff crosses above/below 0.
* Average Diff crosses above/below 0.
* State changes: GREEN / RED / YELLOW / BLUE.
Notes & limitations:
* VWAP is session-anchored and best on intraday data. If not applicable on the selected calculation TF, the script automatically falls back to EMA.
* Default parameters (SMA(20) for BB/KC, multipliers 2.0, SMA(5) smoothing, trend logic and bar painting) preserve the original appearance.
Release notes:
v6.0 — Rewritten in Pine v6 with structured inputs and guards. Multi-MA support (SMA/EMA/WMA/RMA/HMA/VWMA/VWAP). Calculation timeframe via request.security() for multi-TF workflows. Safe division; optional zero line; optional true Blue color. Original visuals and behavior preserved by default.
License / disclaimer:
© waranyu.trkm — MIT License. Educational use only; not financial advice.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.