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
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.