OPEN-SOURCE SCRIPT

RiskCraft - Advanced Risk Management System

68
RiskCraft – Risk Intelligence Dashboard
Trade like you actually respect risk

"I know the setup looks good… but how much am I actually risking right now?"


RiskCraft is an open-source Pine Script v6 indicator that keeps risk transparent directly on the chart. It is not a signal generator; it is a risk desk that calculates size, frames volatility, and reminds you when your behaviour drifts away from the plan.

Core utilities
  • Calculates professional-style position sizing in real time.
  • Reads volatility and market regime before position size is confirmed.
  • Adjusts risk based on the trader’s emotional state and confidence inputs.
  • Maps session risk across Asian, London, and New York hours.
  • Draws exactly one stop line and one target line in the preferred direction.
  • Provides rotating education tips plus contextual warnings when risk escalates.


It is intentionally conservative and keeps you in the game long enough for any separate entry logic to matter.

---

Chart layout checklist
  • Use a clean chart on a liquid symbol (e.g., SPY or major FX pairs).
  • Main RiskCraft dashboard placed on the right edge.
  • Session Risk box on the left with UTC time visible.
  • Floating risk badge above price.
  • Stop/target guide lines enabled.
  • Education panel visible in the bottom-right corner.


스냅샷

---

1. On-chart components
  • Right-side dashboard: account risk %, position size/value, stop, target, risk/reward, regime, trend strength, emotional state, behavioural score, correlation, and preferred trade direction.
  • Session Risk box: highlights active session (Asian, London, NY), current UTC time, and risk label (High/Med/Low) per session.
  • Floating risk badge: keeps actual account risk percent visible with colour-coded wording from Ultra Cautious to Very Aggressive.
  • Stop/target lines: exactly one dashed stop and one dashed target aligned with the preferred bias.
  • Education panel: rotates core principles and AI-style warnings tied to volatility, risk %, and behaviour flags.


---

2. Volatility engine – ATR with context 📈

Pine Script®
atr = ta.atr(atrLength) atrPercent = (atr / close) * 100 atrSMA = ta.sma(atr, atrLength) volatilityRatio = atr / atrSMA isHighVol = volatilityRatio > volThreshold


  • ATR vs ATR SMA shows how wild price is relative to recent history.
  • Volatility ratio above the threshold flips isHighVol, which immediately trims risk.
  • An ATR percentile rank over the last 100 bars indicates calm versus chaotic regimes.
  • Daily ATR sampling via
    Pine Script®
    request.security()
    gives higher time-frame context for intraday sessions.


When volatility spikes the script dials position size down automatically instead of cheering for maximum exposure.

---

3. Market regime radar – Danger or Drift 🌊

Pine Script®
ema20 = ta.ema(close, 20) ema50 = ta.ema(close, 50) ema200 = ta.ema(close, 200) trendScore = (close > ema20 ? 1 : -1) + (ema20 > ema50 ? 1 : -1) + (ema50 > ema200 ? 1 : -1) [diPlus, diMinus, adx] = ta.dmi(14, 14)


Regimes covered:
  • Danger: high volatility with weak trend.
  • Volatile: volatility elevated but structure still directional.
  • Choppy: low ADX and noisy action.
  • Trending: directional flows without extreme volatility.
  • Mixed: anything between.


Each regime maps to a 1–10 risk score and a multiplier that feeds the final position size. Danger and Choppy clamp size; Trending restores normal risk.

---

4. Behaviour engine – trader inputs matter 🧠

You provide:
  • Emotional state: Confident, Neutral, FOMO, Revenge, Fearful.
  • Confidence: slider from 1 to 10.
  • Toggle for behavioural adjustment on/off.


Behind the scenes:
  • Each state triggers an emotional multiplier.
  • Confidence produces a confidence multiplier.
  • Combined they form
    Pine Script®
    behavioralFactor
    and a 0–100 Behavioural Score.


High-risk emotions or low conviction clamp the final risk. Calm inputs allow normal size. The dashboard prints both fields to keep accountability on-screen.

---

5. Correlation guardrail – avoid stacking identical risk 📊

Optional correlation mode compares the active symbol to a reference (default SPY):

Pine Script®
corrClose = request.security(correlationSymbol, timeframe.period, close) priceReturn = ta.change(close) / close[1] corrReturn = ta.change(corrClose) / corrClose[1] correlation = calcCorrelation()


  • Absolute correlation above the threshold applies a correlation multiplier (< 1) to reduce size.
  • Dashboard row shows the live correlation and reference ticker.
  • When disabled, the row simply echoes the current symbol, keeping the table readable.


---

6. Position sizing engine – heart of the script 💰

Pine Script®
baseRiskAmount = accountSize * (baseRiskPercent / 100) adjustedRisk = baseRiskAmount * behavioralFactor * regimeAdjustment * volAdjustment * correlationAdjustment finalRiskAmount = math.min(adjustedRisk, accountSize * (maxRiskCap / 100)) stopDistance = atr * atrStopMultiplier takeProfit = atr * atrTargetMultiplier positionSize = stopDistance > 0 ? finalRiskAmount / stopDistance : 0 positionValue = positionSize * close


Outputs shown on the dashboard:
  • Position size in units and value in currency.
  • Actual risk % back on account after adjustments.
  • Risk/Reward derived from ATR-based stop and target.


---

7. Intelligent trade direction – bias without signals 🎯

Direction score ingredients:
  • EMA stack alignment.
  • Price versus EMA20.
  • RSI momentum relative to 50.
  • MACD line vs signal.
  • Directional Movement (DI+/DI–).


The resulting Trade Direction row prints LONG, SHORT, or NEUTRAL. No orders are generated—this is guidance so you only risk capital when the structure supports it.

---

8. Stop/target guide lines – two lines only ✂️

Pine Script®
if showStopLines if preferLong // long stop below, target above else if preferShort // short stop above, target below


  • Lines refresh each bar to keep clutter low.
  • When the direction score is neutral, no lines appear.
  • Use them as visual anchors, not auto-orders.


---

9. Session Risk map – global volatility clock 🌍

  • Tracks Asian, London, and New York windows via UTC.
  • Computes average ATR per session versus global ATR SMA.
  • Labels each session High/Med/Low and colours the cells accordingly.
  • Top row shows the active session plus current UTC time so you always know the regime you are trading.


스냅샷


One glance tells you whether you are trading quiet drift or the part of the day that hunts stops.

---

10. Floating risk badge – honesty above price 🪪

  • Text ranges from Ultra Cautious through Very Aggressive.
  • Colour matches the risk palette inputs (High/Med/Low).
  • Updates on the last bar only, keeping historical clutter off the chart.


Account risk becomes impossible to ignore while you stare at price.

---

11. Education engine & warnings 📚

  • Rotates evergreen principles (risk 1–2%, journal trades, respect plan).
  • Triggers contextual warnings when volatility and risk % conflict.
  • Flags when emotional state = FOMO or Revenge.
  • Highlights sub-standard risk/reward setups.


When multiple danger flags stack, an AI-style warning overrides the tip text so you can course-correct before capital is exposed.

---

12. Alerts – hard guard rails 🚨

  • Excessive Risk Alert: actual risk % crosses custom threshold.
  • High Volatility Alert: ATR behaviour signals danger regime.
  • Emotional State Warning: FOMO or Revenge selected.
  • Poor Risk/Reward Alert: risk/reward drops below your standard.


All alerts reinforce discipline; none suggest entries or exits.

---

13. Multi-market behaviour 🕒

  • Intraday (1m–1h): session box and badge react quickly; ideal for scalpers needing constant risk context.
  • Higher time frames (1D–1W): dashboard shifts slowly, supporting swing planning.
  • Asset classes confirmed in validation: crypto majors, large-cap equities, indices, major FX pairs, and liquid commodities.


Risk logic is price-based, so it adapts across markets without bespoke tuning.


15. Key inputs & recommended defaults
  • Account Size: 10,000 (modify to match actual account; min 100).
  • Base Risk %: 1.0 with a Maximum Risk Cap of 2.5%.
  • ATR Period: 14, Stop Multiplier 2.0, Target Multiplier 3.0.
  • High Vol Threshold: 1.5 for ATR ratio.
  • Behavioural Adjustment: enabled by default; disable for fixed risk.
  • Correlation Check: optional; default symbol SPY, threshold 0.7.
  • Display toggles: main dashboard, risk badge, session map, education panel, and stop lines can be individually disabled to reduce clutter.



16. Usage notes & limits
  • Indicator mode only; no automated entries or exits.
  • Trade history panel intentionally disabled (requires strategy context).
  • Correlation analysis depends on additional data requests and may lag slightly on illiquid symbols.
  • Session timing uses UTC; adjust expectations if you trade localized instruments.
  • HTF ATR sampling uses daily data, so bar replay on lower charts may show brief data gaps while HTF loads.


What does everyone think RISK really means?

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.