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
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.