OPEN-SOURCE SCRIPT
Risk Recommender — (Heatmap)

📊 Risk Recommender — Per-Trade & Annualized (Heatmap Columns)
Estimate the optimal risk percentage for any market regime.
This tool dynamically recommends how much of your account equity to risk — either per trade or at a portfolio (annualized) level — using volatility as the guide.
⚙️ How it works
Two distinct modes give you flexibility:
1️⃣ Per-Trade (ATR-based)
• Calculates the current Average True Range (ATR) compared to its long-term baseline.
• When volatility is high (ATR ↑), risk per trade decreases to maintain constant dollar risk.
• When volatility is low (ATR ↓), risk per trade increases within your defined floor and ceiling.
• The display is normalized by stop distance (× ATR) and smoothed to avoid noise.
2️⃣ Annualized (Volatility Targeting)
• Computes realized volatility (standard deviation of log returns) and an EWMA forecast of future volatility.
• Blends current and forecast volatilities to estimate “effective” volatility.
• Scales your base risk so that portfolio volatility converges toward your chosen annual target (e.g., 20%).
• Useful for portfolio-level or systematic strategies that maintain constant volatility exposure.
🎨 Heatmap Visualization
The vertical column graph acts like a thermometer:
• 🟥 Red → “Reduce risk” (volatility high).
• 🟩 Green → “Increase risk” (volatility low).
• Smoothed and bounded between your Floor and Ceiling risk levels.
• Optional dotted guides mark those bounds.
• Label shows the current mode, recommended risk %, and key metrics (ATR ratio or effective volatility).
🔧 Key Inputs
• Base max risk per trade (%) — your normal per-trade risk budget.
• ATR length / Baseline ATR length — control sensitivity to short- vs. long-term volatility.
• Target annualized volatility (%) — portfolio volatility target for quant mode.
• λ (lambda) — smoothing factor for the EWMA volatility forecast (0.90–0.99 typical).
• Floor & Ceiling — clamps the output to avoid extreme sizing.
• Smoothing & Hysteresis — prevent rapid changes in risk recommendations.
🧮 Interpreting the Output
• “Recommended Risk (%)” = suggested portion of equity to risk on the next trade (or current exposure).
• In Per-Trade mode: reflects current ATR ÷ baseline ATR.
• In Annualized mode: reflects target volatility ÷ effective volatility.
• Use the color and height of the column as a quick visual cue for aggressiveness.
💡 Typical Use Cases
• Position-sizing overlay for discretionary traders.
• Volatility-targeting component for algorithmic or multi-asset systems.
• Educational tool to understand how volatility governs prudent risk management.
📘 Notes
• This indicator provides risk suggestions only; it does not place trades.
• Works on any symbol or timeframe.
• Combine with your own strategy or alerts for full automation.
• All calculations use built-in Pine functions; no proprietary logic.
Tags:
#RiskManagement #ATR #Volatility #Quant #PositionSizing #SystematicTrading #AlgorithmicTrading #Portfolio #TradingStrategy #Heatmap #EWMA #Risk
Estimate the optimal risk percentage for any market regime.
This tool dynamically recommends how much of your account equity to risk — either per trade or at a portfolio (annualized) level — using volatility as the guide.
⚙️ How it works
Two distinct modes give you flexibility:
1️⃣ Per-Trade (ATR-based)
• Calculates the current Average True Range (ATR) compared to its long-term baseline.
• When volatility is high (ATR ↑), risk per trade decreases to maintain constant dollar risk.
• When volatility is low (ATR ↓), risk per trade increases within your defined floor and ceiling.
• The display is normalized by stop distance (× ATR) and smoothed to avoid noise.
2️⃣ Annualized (Volatility Targeting)
• Computes realized volatility (standard deviation of log returns) and an EWMA forecast of future volatility.
• Blends current and forecast volatilities to estimate “effective” volatility.
• Scales your base risk so that portfolio volatility converges toward your chosen annual target (e.g., 20%).
• Useful for portfolio-level or systematic strategies that maintain constant volatility exposure.
🎨 Heatmap Visualization
The vertical column graph acts like a thermometer:
• 🟥 Red → “Reduce risk” (volatility high).
• 🟩 Green → “Increase risk” (volatility low).
• Smoothed and bounded between your Floor and Ceiling risk levels.
• Optional dotted guides mark those bounds.
• Label shows the current mode, recommended risk %, and key metrics (ATR ratio or effective volatility).
🔧 Key Inputs
• Base max risk per trade (%) — your normal per-trade risk budget.
• ATR length / Baseline ATR length — control sensitivity to short- vs. long-term volatility.
• Target annualized volatility (%) — portfolio volatility target for quant mode.
• λ (lambda) — smoothing factor for the EWMA volatility forecast (0.90–0.99 typical).
• Floor & Ceiling — clamps the output to avoid extreme sizing.
• Smoothing & Hysteresis — prevent rapid changes in risk recommendations.
🧮 Interpreting the Output
• “Recommended Risk (%)” = suggested portion of equity to risk on the next trade (or current exposure).
• In Per-Trade mode: reflects current ATR ÷ baseline ATR.
• In Annualized mode: reflects target volatility ÷ effective volatility.
• Use the color and height of the column as a quick visual cue for aggressiveness.
💡 Typical Use Cases
• Position-sizing overlay for discretionary traders.
• Volatility-targeting component for algorithmic or multi-asset systems.
• Educational tool to understand how volatility governs prudent risk management.
📘 Notes
• This indicator provides risk suggestions only; it does not place trades.
• Works on any symbol or timeframe.
• Combine with your own strategy or alerts for full automation.
• All calculations use built-in Pine functions; no proprietary logic.
Tags:
#RiskManagement #ATR #Volatility #Quant #PositionSizing #SystematicTrading #AlgorithmicTrading #Portfolio #TradingStrategy #Heatmap #EWMA #Risk
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
📊 Access & Subscription → algorific.gumroad.com/
💬 After purchase, DM @Algorific on TradingView for invite-only access.
💬 After purchase, DM @Algorific on TradingView for invite-only access.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
📊 Access & Subscription → algorific.gumroad.com/
💬 After purchase, DM @Algorific on TradingView for invite-only access.
💬 After purchase, DM @Algorific on TradingView for invite-only access.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.