OPEN-SOURCE SCRIPT
Volatility Expansion Strategy 30M [MNQ]

This script is designed to exploit the cyclical nature of market volatility—specifically the transition from "coiling" phases (low volatility) to "expansion" phases (high volatility). Here is the technical breakdown of how the engine handles the data:
The Mathematical Core: The Volatility Ratio
Instead of looking at raw price, the script calculates a Volatility Ratio.
This is the core engine:
volRatio = ta.atr(20) / ta.sma(ta.atr(20), 40)
We are comparing a short-term volatility window (20 periods) against a long-term baseline (40 periods).
The Squeeze ($< 0.95$): When the ratio drops below 0.95, it mathematically proves that current price action is significantly more compressed than its own historical average. This is our "coiling" phase.
The Expansion ($> 1.02$): We look for a 2% increase in relative volatility to confirm that the "spring" has been released.
Level Locking & Execution Logic
Most breakout strategies fail because they buy any high/low. This script uses Conditional Level Locking:
While isCompressed is true, the script continuously updates breakoutHigh and breakoutLow to the high/low of the current bar.
The moment the market leaves the squeeze phase, those levels "freeze."
The Trigger: A trade is only executed if we have a volatility expansion (volRatio > 1.02) occurring simultaneously with a price crossover of those frozen levels. This ensures we aren't just buying a slow drift, but a high-velocity move.
Risk & Precision
For a fast instrument like MNQ, fixed price stops often fail due to slippage. I’ve programmed this to use Tick-Based Offsets. The risk is calculated dynamically using
ATR \times 1.5$, then converted into the smallest possible unit of movement (ticks). This ensures that the strategy.exit orders are hard-coded into the broker's matching engine the millisecond you enter, protecting you from "stuck" trades during high-volatility spikes.
The Mathematical Core: The Volatility Ratio
Instead of looking at raw price, the script calculates a Volatility Ratio.
This is the core engine:
volRatio = ta.atr(20) / ta.sma(ta.atr(20), 40)
We are comparing a short-term volatility window (20 periods) against a long-term baseline (40 periods).
The Squeeze ($< 0.95$): When the ratio drops below 0.95, it mathematically proves that current price action is significantly more compressed than its own historical average. This is our "coiling" phase.
The Expansion ($> 1.02$): We look for a 2% increase in relative volatility to confirm that the "spring" has been released.
Level Locking & Execution Logic
Most breakout strategies fail because they buy any high/low. This script uses Conditional Level Locking:
While isCompressed is true, the script continuously updates breakoutHigh and breakoutLow to the high/low of the current bar.
The moment the market leaves the squeeze phase, those levels "freeze."
The Trigger: A trade is only executed if we have a volatility expansion (volRatio > 1.02) occurring simultaneously with a price crossover of those frozen levels. This ensures we aren't just buying a slow drift, but a high-velocity move.
Risk & Precision
For a fast instrument like MNQ, fixed price stops often fail due to slippage. I’ve programmed this to use Tick-Based Offsets. The risk is calculated dynamically using
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.