OPEN-SOURCE SCRIPT
Telah dikemas kini

All-in-one CPR indicator

75 472
Introduction and Acknowledgement:
The script is basically a mashup script and provides a combined functionality of various indicators. I'll explain the usefulness and the optimal usage of the script after giving the credits where it is due. A CPR indicator for visually identifying the trend along with the strength of the trend is NOT available in the public library of TradingView. Hence, the need of this indicator.

The credit of creating the original indicators remain unknown to me but I would like to acknowledge the authors whose formulae and codes I have used for creating this mashup indicator.
- Frank Ochoa
- Guruprasad Meduri
- Rafael Zioni
- Stoked Stocks
- Pine team for default indicators

The prime focus of the script is identifying and simplifying the 2 main aspects of a trend:
1. Direction / Underlying trend
2. Strength of the trend

Flaws in traditional CPR:
Some may see this as a flaw, some may not. So take my opinion with a grain of salt. In general, the traditional CPR indicator is used to plot just support and resistance levels, and the trend identification is purely discretionary. In addition to this, there is no way to assess the strength of the move without using a dedicated volumed based indicator. This causes amateur traders to take counter trades to the market direction.

What is the need of this hybrid indicator?
A CPR indicator that also aids in visually identifying the trend and the strength of the trend with respect to the price action in NOT available in the public library of TradingView. The traditional CPR can be used to assess the rough direction of the market but if it combined with the Hull ribbon, the probability of identifying the trend increases manifold. Hence, I decided to create this mashup indicator.

In addition to the basic CPR pivots, the script provides the functionality of the following indicators:

1. HMA based trend ribbons with auto buy/sell signals
2. Volatility based bands - Bollinger bands, Keltner channel, Donchian channel, envelope.
3. Coloured volume candles to determine the strength of the trend
4. CPR with daily, weekly, and monthly levels
5. Previous day high/low
6. Tomorrow CPR
7. 3 Simple moving averages
8. Volume Weighted Average Price (VWAP)

Correct usage of the indicator:
The optimal usage of the indicators consists of mainly 2 parts:
1. Identification of the trend using the combination of CPR and Hull ribbon
2. Determining the strength of the trend

How to identify the trend?
In general, when the price is above CPR it is considered a bullish trend. Also, when the price is above the Hull ribbon, it is considered bullish. Reverse is true for a bearish trend. Combining the traditional CPR logic with the Hull trend ribbon, we can conclude that:
1. Bullish trend = Price above CPR and above the Hull ribbon
2. Bearish trend = Price below CPR and below the Hull ribbon

If the Hull ribbon is showing a zig-zag move, the trend will be sideways. Also, the time frame of the Hull ribbon can be defined as per the need of the user.

Exhibit: Identification of a bullish trend
syot kilat

Exhibit: Identification of a bullish trend with a contra move (pullback)
syot kilat

Exhibit: Identification of a bearish trend
syot kilat

Exhibit: Identification of a bearish trend with a contra move (pullback)
syot kilat

How to determine the strength of the trend?
1. Strong trend = The dark coloured candles represent volume more than 150% of the look back period. For instance
2. Moderate trend = The bright coloured candles represent volume between 50-150%.
3. Neutral trend = The Grey coloured candles represent a weak trend where the volume is less than 50%.

Exhibit: Identification of a strong bearish trend along with the trend direction
syot kilat

Exhibit: Identification of a strong bullish trend using only coloured candles
syot kilat

All the other indicators including the SMA, VWAP, Bollinger bands, Keltner channels, etc. can be used as per the taste of the trader.

Thanks for reading! I hope you find this indicator useful.

Happy learning. Cheers!
Rajat Kumar Singh (johntradingwick)
Community Manager (India), TradingView
Nota Keluaran
📝 Changelog – All-in-One CPR (2025 Update)
📅 Version: v2.0
📦 Update Date: June 2025
🔧 Total Lines of Code: 380 ➜ 780+

----------

Code Quality & Performance
- Converted everything to Pine Script v6
- Reduced repainting and ensured correct lookahead=barmerge.lookahead_on use
- Reorganized inputs into logical groups with proper tooltips
- Modularized reusable functions (e.g., CPR calculations, S/R, color diff logic)
- Added inline comments and documentation for all features

Visual & UI Enhancements
- Added complete light/dark theme detection with automatic color switching.
- Support for custom label text and background colors.
- Color-coded distance % values (green = above, red = below) in live stats table.

Live Stats Table (NEW)
- Introduced table: Live CPR Stats
- Displays real-time value of Pivot, TC, BC, S1, R1
- Added proper color styling for headers and values depending on theme
- Improved table layout with better readability and alignment
- Header and row text are now white in dark mode for better visibility

Distance Table (NEW)
- Introduced table: Distance from main elements
- Displays real-time % distance from: CPR, S1, R1, VWAP
- Added proper color styling for headers and values depending on theme
- Improved table layout with better readability and alignment
- Header and row text are now white in dark mode for better visibility

Modular Display Controls
- All elements now have individual visibility toggles.
- Added user-friendly grouping in input UI for easy navigation.
- Support for custom table placement & text size (both for CPR table and Live stats table).
- Added toggles to show/hide each table independently.

Strategy Presets (NEW)
- Added preset/template toggles for quick strategy-based configuration
-- Intraday CPR Setup
-- Swing MA + VWAP Setup
- Automatically toggles relevant indicators and hides others.

Alerts Overhaul (NEW)
- Added alert conditions for:
-- CPR breakout (Pivot, TC, BC)
-- S/R breach (Daily S1/S2/S3 & R1/R2/R3)
-- PDH/PDL breach
-- HMA Buy/Sell signals
- Configurable per-level alert toggles from input settings
- Fully compatible with TradingView’s native alert system
Nota Keluaran
📝 Changelog – All-in-One CPR (2025 Update)
📅 Version: v2.1

🔁 Refactored HMA Plotting Logic
✅ Resolved issue where toggling "Show HMA Lines" would also hide the HMA Ribbon Fill, even if "Show HMA Ribbon" was enabled.
✅ Refactored plot() and fill() logic to decouple line and ribbon visibility:
✅ Plots are always created for ribbon fill to function correctly.
✅ Visibility is controlled using dynamic color=na instead of disabling the plot completely.

New Toggles Added
✅ Show HMA Lines: Allows showing/hiding of HMA A & B lines independently.
✅ Show HMA Ribbon Fill: Enables/disables the background fill ribbon without affecting HMA lines.
✅ Show HMA Buy Labels: Toggle visibility of buy crossover labels.
✅ Show HMA Sell Labels: Toggle visibility of sell crossover labels.

🔔 Alert Improvements
✅ Alerts for HMA Buy and HMA Sell signals are now conditionally tied to individual signal toggles.
✅ Alerts only triggered when the corresponding HMA crossover occurs and user has enabled that alert type.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.