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提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。