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が提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。