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.
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
Contact me in PM or on Telegram: @nguyenthl
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
Contact me in PM or on Telegram: @nguyenthl
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。