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提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。