Pivot Measurements Indicator for TradingView
TradingView and Pine Script
If you’re a trader using TradingView, you probably know how powerful it is for charting and analyzing markets. What makes it even better is Pine Script – the scripting language that lets you build custom indicators and share them with the trading community.
Today, I want to share with you Pivot Measurements, an indicator I’ve built that takes pivot point detection to the next level. It not only identifies key reversal points but also automatically calculates and displays the price movements between them. Think of it as having a smart assistant that measures and visualizes the distance between important market turning points.
Ready to give it a try? You can test it directly on TradingView: Pivot Measurements Indicator
Or if you prefer to dive into the code, you can view and copy it from GitHub: GitHub - pivot-measurements.pine
What Makes This Indicator Special?
At its core, Pivot Measurements does two things really well:
- Smart Pivot Detection: It finds those crucial reversal points (both the obvious ones and the ones you might have missed) using a proven algorithm
- Automatic Calculations: Once it finds the pivots, it automatically measures everything between them – price changes, time duration, and volume
The best part? Everything is fully customizable. You can adjust colors, transparency, and it works beautifully across all timeframes – from quick scalping to long-term swing trading.
Finding the Right Pivot Points
What It Does
The indicator uses LuxAlgo’s proven algorithm to spot those important reversal moments in the market. But here’s what makes it special: it doesn’t just find the obvious pivots – it also catches the ones that happened “between the cracks” that you might have missed.
How It Works
Under the hood, the indicator:
- Uses TradingView’s built-in
ta.pivothigh()andta.pivotlow()functions with a configurable pivot length - Keeps track of the highest and lowest values as pivots form
- Compares current pivots with previous ones to catch those missed reversal levels
- Creates clear visual markers:
- Red triangles (▼) mark regular pivot highs
- Teal triangles (▲) mark regular pivot lows
- Ghost emoji (👻) highlight those missed pivots you might have overlooked
- Draws connecting lines between pivots (solid lines for regular pivots, dashed for missed ones)
- Shows horizontal “ghost levels” that act as potential support or resistance from those missed pivots
Make It Your Own
You have full control over how the pivots are detected and displayed:
- Pivot length: Set how many bars to look back (default is 50, but adjust based on your timeframe)
- Color coding: Choose different colors for regular vs missed pivots
- Visibility toggles: Show or hide regular pivots, missed pivots, or both
- Timeframe flexibility: It automatically adapts to whatever timeframe you’re trading
Measuring Price Movements Automatically
What It Does
Once the indicator finds the pivot points, it automatically calculates everything you need to know about the price movements between them. No more manual measuring or guessing – you get quantitative data about trend strength, how long moves lasted, and volume information, all at a glance.
How It Works
Here’s the process:
- First, it organizes all detected pivots chronologically (using a bubble sort algorithm)
- Then it creates measurements between consecutive pivots, working from the most recent back in time
- For each movement, it calculates:
- Price change: Both the absolute dollar/point change and the percentage move
- Duration: How long the move took in bars, days, hours, and minutes
- Volume: An approximation using a 20-period moving average
- Finally, it displays everything beautifully:
- Colored boxes: Blue for upward movements, red for downward ones (with adjustable transparency)
- Detailed labels: Positioned outside the boxes with all the key information
- Smart layout: Automatically spaces everything to prevent clutter and overlap
Customize the Display
You can tweak the measurements to match your trading style:
- How many to show: Display anywhere from 1 to 10 measurements (default is 10)
- Box transparency: Control how visible the colored boxes are (0-100%, default 90%)
- Border transparency: Adjust the box borders separately (0-100%, default 50%)
- Label background: Make the label backgrounds more or less visible (0-100%, default 30%)
- Label size: Choose from tiny, small, normal, or large – whatever works best for your screen
Built for Performance and Usability
Clean, Modular Code
I’ve organized the code into clear, reusable functions that make the indicator both maintainable and easy to understand:
add_pivot_and_label(): Handles all the pivot creation and labeling in one placecreate_zigzag_line(): Makes drawing those connecting lines simple and consistentcreate_ghost_level(): Takes care of visualizing those missed pivot levelssort_pivots_by_bar(): Efficiently organizes pivots chronologicallycreate_measurement(): Does all the heavy lifting for calculating measurementscreate_measurement_display(): Renders everything beautifully on your chart
Performance Optimizations
Nobody wants a laggy indicator, so I’ve made sure it runs smoothly:
- Smart calculations: Only computes measurements on the latest bar (using
barstate.islast) to avoid unnecessary processing - Memory efficient: Limits stored pivots to just what you need (
max_measurements + 1) - Clean display: Clears and rebuilds display objects each bar to prevent visual clutter and memory buildup
- Historical depth: Uses
max_bars_back=5000to ensure you have enough historical data for accurate pivot detection
Trader-Friendly Design
I’ve put a lot of thought into making this indicator easy to use:
- Organized settings: Parameters are grouped logically so you can find what you need quickly
- Color coding: Blue for gains, red for losses – instant visual feedback
- Complete information: Labels show all the metrics you need without cluttering your chart
- Flexible visuals: Adjust transparency to match your chart style and keep things clean
Built on Solid Foundations
This indicator wouldn’t be possible without the excellent work from LuxAlgo. I’ve built on top of their Pivot Points High Low & Missed Reversal Levels algorithm, which provides the rock-solid pivot detection logic that makes everything work.
What I’ve added is the automatic measurement system – an original feature that takes the pivot detection and extends it with quantitative analysis. Now you don’t just see where the pivots are, you also get detailed information about what happened between them.
What You Get
In a nutshell, Pivot Measurements gives you:
- Smart pivot detection: Finds both regular and missed reversal points automatically
- Automatic calculations: Measures price movements, duration, and volume between pivots
- Clear visualization: Color-coded boxes and detailed labels make everything easy to read
- Full customization: Adjust everything to match your trading style and preferred timeframes
Whether you’re looking for support/resistance levels or want to measure price movements between key reversal points, this indicator has you covered. It’s designed to be your all-in-one tool for pivot-based trading analysis.
Give it a try and see how it can improve your trading workflow. Happy trading!