OPEN-SOURCE SCRIPT

FX Risk Cockpit [forexobroker]

998
FX Risk Cockpit puts your entire risk management workflow into one indicator. Instead of juggling separate tools for position sizing, pip calculations, and risk/reward visualization, this cockpit displays everything on your chart: exact position size based on your risk percentage, color-coded risk and reward zones, direction arrows, session tracking, and a comprehensive dashboard — all visible the moment you add it.

WHAT IT DOES

The indicator calculates proper position sizing based on your account size, risk percentage, and stop loss distance in pips. It auto-detects pip size for any forex pair (including JPY pairs), draws color-coded entry/SL/TP lines with filled risk and reward zones on your chart, tracks session statistics in real time, and displays a dashboard with all risk metrics at a glance.

Six risk tools combined:

Position Size Calculator — Calculates exact lot size based on account, risk %, and SL distance in pips
Pip Value Auto-Detection — Automatically handles standard (0.0001) and JPY (0.01) pip sizes
R:R Visualization — On-chart lines with colored zone fills showing risk (red) and reward (green) areas, plus direction arrows
Drawdown Tracker — Real-time session drawdown from session high in pips and percentage
Risk Heat Gauge — Color-coded indicator showing risk as percentage of account (green/yellow/red)
Session P&L — Running session profit/loss in pips with session range tracking
HOW IT WORKS

Add the indicator to any forex chart — it works immediately with default settings
Set your account size (default 10,000) and risk percentage (default 1%) in Account inputs
Choose Long or Short direction
Set your Stop Loss and Take Profit distances in pips (defaults: SL 25 pips, TP1 50 pips, TP2 75 pips)
The indicator instantly shows:
A direction arrow (LONG/SHORT) at the current entry price
Red zone fill between entry and stop loss
Green zone fills between entry and take profit levels
Labels at each level showing pip distance, dollar value, and R:R ratio
Dashboard with full risk breakdown, position sizing, and session stats
Entry defaults to the current close price. Set a specific price via the "Entry Price" input (0 = current price).

VISUAL ELEMENTS

The indicator draws on your chart:

Entry arrow — Large direction label (LONG/SHORT) with entry price at the current bar
Stop loss line — Red dashed line with label showing pips and dollar risk
Take profit lines — Green dashed lines with labels showing pips, dollar reward, and R:R ratio
Risk zone — Semi-transparent red fill between entry and stop loss
Reward zones — Semi-transparent green fills between entry and each take profit level
Dashboard — Full risk breakdown table in the corner
All visual elements appear immediately when the indicator is added.

POSITION SIZE FORMULA

Risk Amount = Account Size × Risk %
Position Size (units) = Risk Amount ÷ (SL Pips × Pip Value per Unit)
Position Size (lots) = Units ÷ Lot Units (100K/10K/1K)
Pip value is automatically calculated using syminfo.pointvalue and syminfo.mintick. A manual Pip Value Override input is available if auto-detection doesn't match your broker.

PIP SIZE AUTO-DETECTION

The indicator automatically detects the correct pip size:

Standard pairs (EUR/USD, GBP/USD, etc.): 1 pip = 0.0001
JPY pairs (USD/JPY, EUR/JPY, etc.): 1 pip = 0.01
The detected pip size is shown in the dashboard for verification.

RISK HEAT GAUGE

The Risk Heat shows your total risk exposure as a percentage of your account:

GREEN (LOW): Risk below 2% — conservative, standard risk management
YELLOW (MEDIUM): Risk between 2-5% — elevated exposure, use caution
RED (HIGH): Risk above 5% — high exposure, consider reducing position size
FEATURES

Works immediately on any forex chart — no setup required
Pip-based SL/TP inputs with sensible defaults (25/50/75/100 pips)
Entry auto-detects to current price, or set manually
Color-coded risk (red) and reward (green) zone fills on chart
Direction arrow label showing LONG/SHORT at entry
Position size calculator with Standard/Mini/Micro lot support
Up to 3 take profit targets with independent R:R ratios
Labels showing pips, dollar values, and ratios at each level
Pip Value auto-detection with manual override option
Risk heat gauge with color-coded exposure warning
Session tracking: range, drawdown, and P&L in pips
Dashboard with all risk metrics in one compact view
Auto-detection of JPY and standard pip sizes
Theme-aware dashboard for light and dark charts
Data Window integration for all key values
5 alert conditions for price levels and risk thresholds
Non-repainting: session tracking uses confirmed bars
Zero security calls — all calculations on current chart data
Works on any forex pair and any timeframe
HOW TO READ THE CHART

Element | What It Shows
---------------------|--------------------------------------------------
Direction arrow | LONG or SHORT label at entry price
Solid blue line | Entry price level
Dashed red line | Stop loss level
Red zone fill | Risk area (entry to SL) — what you lose if stopped
Dashed teal line | TP1 level
Green zone fills | Reward areas (entry to TPs) — what you gain at targets
Level labels | Pip distance, dollar value, R:R at each level
Dashboard | Full risk breakdown with position sizing and session data
USE CASES

Instant Risk Assessment — Add to any chart and immediately see where your SL/TP levels fall relative to current price. The colored zones make risk/reward visually obvious.

Position Sizing — The calculator shows exact lot size for your risk tolerance. No mental math or external calculators needed.

Multi-Target Planning — Use TP1 for partial profit (50% close), TP2 for breakeven move, TP3 for runner. The dashboard shows dollar values at each target.

Risk Heat Check — Before every trade, glance at the Risk Heat gauge. GREEN = safe. YELLOW = caution. RED = reduce size.

Session Monitoring — Track how the current session is developing with range, drawdown, and P&L metrics.

Trade Journal — The dashboard provides every number needed for a trade journal entry: entry, SL, TP levels, position size, risk amount, R:R ratios.

SETTINGS

Account: Set account size (10,000), risk per trade % (1%), and account currency.

Trade Setup: Choose Long/Short direction. Set Entry Price (0 = current close). Set SL and TP distances in pips.

Position Sizing: Choose Standard (100K), Mini (10K), or Micro (1K) lots. Optional pip value override.

Display: Toggle lines, zone fills, dashboard, and risk heat gauge. Position the dashboard anywhere.

Colors: Customize entry, SL, and TP colors.

TECHNICAL NOTES

Zero security calls — all calculations use current chart data only
Non-repainting: session tracking uses var persistence and session.isfirstbar
Pip size detected via syminfo.mintick — works for all forex pairs
Pip value calculated via syminfo.pointvalue with manual override option
Entry defaults to close for immediate functionality (0 = current price)
Linefill objects create zone fills between entry and SL/TP lines
Dashboard renders only on barstate.islast for performance
Works on any forex pair and any timeframe
DISCLAIMER

This indicator is for educational and informational purposes only. It does not constitute financial advice. Position size calculations depend on accurate account size and pip value inputs. Always verify calculations independently before placing trades. Forex trading involves substantial risk of loss. Past performance does not guarantee future results.

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.