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提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。