OPEN-SOURCE SCRIPT
Liquidity Spectrum Visualizer [BigBeluga] [Optimized]

This version of Liquidity Spectrum Visualizer (© BigBeluga) has been optimized to improve execution speed and reduce script load times without altering the visual output or analytical logic of the original indicator. The key improvements focus on reducing computational complexity, eliminating redundant calculations, and minimizing expensive function calls within loops.
Core Optimization Changes
Single-Pass Volume Binning (O(N) instead of O(N×M))
Original: For each bin (100) the script iterated through every bar (lookback), resulting in ~20,000 operations.
Optimized: Each bar is processed once to directly calculate its bin index. This reduces the loop complexity from O(N×M) to O(N), where N = lookback.
Precomputed Min/Max Values
Original: array.min() and array.max() were repeatedly called inside loops, re-scanning arrays hundreds of times.
Optimized: Min and max are computed once before all calculations and reused, reducing computational overhead.
Reduced Label Creation
Original: Labels were created in every iteration, potentially hundreds of times per update — a very expensive operation in Pine.
Optimized: Only two labels are created for significant high and low levels, cutting down label calls by ~99%.
Efficient Resource Management
All boxes and lines are cleared once before re-rendering instead of being deleted individually inside nested loops.
Optional gradient rendering and POC drawing remain, but only after binning is complete.
Performance Evaluation
The most important change is the reduction of loop complexity — instead of performing around 20,000 iterations per update, the optimized version now processes only about 200. This reduces execution time and makes the indicator much lighter.
Function calls such as min() and max() are now calculated only once instead of hundreds of times, which removes unnecessary overhead. Likewise, label creation has been reduced from hundreds of labels per refresh to just two, further improving performance.
As a result, the average loading time of the indicator dropped from roughly 1.5–3 seconds to about 0.05–0.2 seconds on typical datasets.
Core Optimization Changes
Single-Pass Volume Binning (O(N) instead of O(N×M))
Original: For each bin (100) the script iterated through every bar (lookback), resulting in ~20,000 operations.
Optimized: Each bar is processed once to directly calculate its bin index. This reduces the loop complexity from O(N×M) to O(N), where N = lookback.
Precomputed Min/Max Values
Original: array.min() and array.max() were repeatedly called inside loops, re-scanning arrays hundreds of times.
Optimized: Min and max are computed once before all calculations and reused, reducing computational overhead.
Reduced Label Creation
Original: Labels were created in every iteration, potentially hundreds of times per update — a very expensive operation in Pine.
Optimized: Only two labels are created for significant high and low levels, cutting down label calls by ~99%.
Efficient Resource Management
All boxes and lines are cleared once before re-rendering instead of being deleted individually inside nested loops.
Optional gradient rendering and POC drawing remain, but only after binning is complete.
Performance Evaluation
The most important change is the reduction of loop complexity — instead of performing around 20,000 iterations per update, the optimized version now processes only about 200. This reduces execution time and makes the indicator much lighter.
Function calls such as min() and max() are now calculated only once instead of hundreds of times, which removes unnecessary overhead. Likewise, label creation has been reduced from hundreds of labels per refresh to just two, further improving performance.
As a result, the average loading time of the indicator dropped from roughly 1.5–3 seconds to about 0.05–0.2 seconds on typical datasets.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Contact me in PM or on Telegram: @nguyenthl
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Contact me in PM or on Telegram: @nguyenthl
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.