OPEN-SOURCE SCRIPT

Advanced VCP Strategy v6.1

Key Fixes Implemented:

ATR Consistency Fix

Pre-calculated atr outside conditional logic

Ensures ATR updates on every bar

Used consistently in both breakout level and stop loss

Length Validation for Highest/Lowest

Added safeLength = math.max(contractionCount, 1)

Prevents zero-length errors in ta.highest()/ta.lowest()

Maintains valid calculations even during reset periods

Order of Execution Fix

Moved ATR calculation before any dependent operations

Ensures all subsequent calculations use the same ATR value

Code Structure Improvements

Separated breakout logic into distinct sections

Added clear comments for each calculation stage

Maintained non-repainting guarantees with barstate.isconfirmed

Additional Enhancements:

Added minimum 1-bar lookback for consolidation ranges

Improved numerical stability with math.max() safeguards

Better memory management through variable ordering

Aviso legal