PROTECTED SOURCE SCRIPT
Position Sizer

🔧 Major Improvements: Leverage Management
New Feature: Configurable Leverage Warning
Added new input: "⚠️ Max Leverage Warning" (default: 20x)
Allows users to set their own leverage threshold for visual alerts
Fully customizable from 1x to 100x
Located in Configuration Panel → Section 1: Main Settings
Behavior Change: Non-Intrusive Alerts
Removed: Automatic indicator shutdown when leverage exceeds 20x
New behavior:
The indicator now continues operating regardless of leverage level
When leverage exceeds the configured threshold, it displays in RED color
All calculations and visualizations remain active
No more unexpected indicator crashes due to high leverage positions
Enhanced Color Coding System
Leverage display colors:
🔴 Red: Exceeds configured Max Leverage Warning threshold
🟠 Orange: Leverage between 5x-10x
🟡 Yellow: Leverage between 1x-5x
🟢 Green: Below 1x (no leverage)
Capital Used (%) colors:
🔴 Red: Exceeds Max Leverage Warning
🟠 Orange: 500%+ capital used
🟡 Yellow: 100%+ capital used
🟢 Green: Below 100%
🐛 Bug Fixes
Fixed exposureColor declaration scope issue for both LONG and SHORT positions
Improved color logic consistency across all leverage scenarios
Resolved indicator interruption issues during high-volatility trading
📋 Technical Changes
Modified exposureColor calculation to use maxLeverageWarning parameter
Modified exposureColorShort calculation to use maxLeverageWarning parameter
Removed runtime.error() calls that stopped script execution
Code optimization for better performance
💡 Usage Recommendation
For conservative trading, set Max Leverage Warning to 5x-10x. For aggressive strategies with proper risk management, you can increase it to 20x-50x. Always monitor the "Capital Used %" and "Leverage" rows in the panel.
⚠️ Important Note
This update improves user experience by providing non-intrusive warnings instead of stopping the indicator. The indicator will now continue to function and provide critical position sizing information even in extreme leverage scenarios, giving you full control and awareness of your risk exposure.
Descripción completa actualizada (para referencia futura)
Si en el futuro necesitas republicar el indicador desde cero, aquí está la descripción completa actualizada:
POSITION SIZER - DUAL RISK MANAGEMENT (Long/Short)
Overview
Professional risk management tool that automatically calculates the optimal position size for LONG and SHORT trades based on your account capital, desired risk percentage, and Stop Loss distance. Adapts seamlessly to multiple financial instruments including Forex, Stocks, Futures, Indices/CFDs, and Cryptocurrencies.
✨ Key Features
1. Advanced Leverage Management ⚡
Configurable Max Leverage Warning: Set your own threshold (1x-100x, default: 20x)
Automatic Leverage Calculation: Multiplies capital by configurable factor (1x-20x)
Manual Margin Control: Define maximum margin in USD
Visual Alert System: Displays leverage in RED when exceeding threshold without stopping the indicator
Non-Intrusive Operation: Indicator continues functioning regardless of leverage level
2. Capital & Risk Management 💰
Configurable Total Capital: Define your account size
Customizable Risk Percentage: Set % of capital to risk per trade (recommended 0.5-1%)
Real-Time Risk Calculation: See exact USD risk and profit potential
Minimum Win Rate Calculator: Know the % of winning trades needed for profitability
3. Dual Stop Loss Methods 🛑
ATR Multiplier: Volatility-based SL (ideal for trend following)
Structural Minimum: Support/Resistance-based SL with configurable buffer in pips
Flexible Calculation Basis: Choose between "Pure SL" or "Buffer Included"
4. Risk/Reward Configuration 📊
Customizable RR Ratio: Set your desired profit ratio (e.g., 1:2, 1:3)
Partial Take Profit: Display intermediate TP levels
Visual SL/TP Lines: Graphical price levels with labels
5. Trading Costs Integration 💵
Commission Tracking: Include costs per lot/contract
Spread Management: Manual or automatic for Forex
Transparent Breakdown: View cost details without affecting SL/TP levels
📈 Detailed Information Panel
For LONG & SHORT Trades:
Entry price (automatic or manual planning)
Exact SL/TP levels (price, pips/distance, percentage)
Expected risk and profit in USD
Position Nominal Value
Capital Used (%) with color-coded exposure alerts
Leverage (x) with configurable threshold warnings
Position size by instrument type
🛠️ Supported Instruments
Forex: Micro (1K), Mini (10K), Standard (100K) lots
Stocks: Fractional shares
Futures: Whole contracts (auto-rounding)
Indices/CFDs: Fractional lots
Cryptocurrencies: Decimal units
🎨 Customizable Visualization
Panel Position: 4 locations (top/bottom right/left)
Font Sizes: Adjustable for panel and labels
Color Coding:
🟢 Green: Take Profit
🔴 Red: Stop Loss & critical alerts
🟡 Yellow: Moderate warnings
🟠 Orange: Partial TP & costs
⚙️ Advanced Settings
Manual Entry Planning: Set specific entry price for future trades
Directionality: LONG only, SHORT only, or both simultaneously
Size Calculation Basis: Pure SL vs Buffer Included
Auto/Manual Margin: Choose your leverage control method
🎓 Best Practices
Keep risk at 0.5-1% of capital per trade
Use conservative leverage (1x-5x) for long-term strategies
Always verify your broker's real spread
Monitor "Capital Used %" to avoid overexposure
Configure Max Leverage Warning according to your risk tolerance
New Feature: Configurable Leverage Warning
Added new input: "⚠️ Max Leverage Warning" (default: 20x)
Allows users to set their own leverage threshold for visual alerts
Fully customizable from 1x to 100x
Located in Configuration Panel → Section 1: Main Settings
Behavior Change: Non-Intrusive Alerts
Removed: Automatic indicator shutdown when leverage exceeds 20x
New behavior:
The indicator now continues operating regardless of leverage level
When leverage exceeds the configured threshold, it displays in RED color
All calculations and visualizations remain active
No more unexpected indicator crashes due to high leverage positions
Enhanced Color Coding System
Leverage display colors:
🔴 Red: Exceeds configured Max Leverage Warning threshold
🟠 Orange: Leverage between 5x-10x
🟡 Yellow: Leverage between 1x-5x
🟢 Green: Below 1x (no leverage)
Capital Used (%) colors:
🔴 Red: Exceeds Max Leverage Warning
🟠 Orange: 500%+ capital used
🟡 Yellow: 100%+ capital used
🟢 Green: Below 100%
🐛 Bug Fixes
Fixed exposureColor declaration scope issue for both LONG and SHORT positions
Improved color logic consistency across all leverage scenarios
Resolved indicator interruption issues during high-volatility trading
📋 Technical Changes
Modified exposureColor calculation to use maxLeverageWarning parameter
Modified exposureColorShort calculation to use maxLeverageWarning parameter
Removed runtime.error() calls that stopped script execution
Code optimization for better performance
💡 Usage Recommendation
For conservative trading, set Max Leverage Warning to 5x-10x. For aggressive strategies with proper risk management, you can increase it to 20x-50x. Always monitor the "Capital Used %" and "Leverage" rows in the panel.
⚠️ Important Note
This update improves user experience by providing non-intrusive warnings instead of stopping the indicator. The indicator will now continue to function and provide critical position sizing information even in extreme leverage scenarios, giving you full control and awareness of your risk exposure.
Descripción completa actualizada (para referencia futura)
Si en el futuro necesitas republicar el indicador desde cero, aquí está la descripción completa actualizada:
POSITION SIZER - DUAL RISK MANAGEMENT (Long/Short)
Overview
Professional risk management tool that automatically calculates the optimal position size for LONG and SHORT trades based on your account capital, desired risk percentage, and Stop Loss distance. Adapts seamlessly to multiple financial instruments including Forex, Stocks, Futures, Indices/CFDs, and Cryptocurrencies.
✨ Key Features
1. Advanced Leverage Management ⚡
Configurable Max Leverage Warning: Set your own threshold (1x-100x, default: 20x)
Automatic Leverage Calculation: Multiplies capital by configurable factor (1x-20x)
Manual Margin Control: Define maximum margin in USD
Visual Alert System: Displays leverage in RED when exceeding threshold without stopping the indicator
Non-Intrusive Operation: Indicator continues functioning regardless of leverage level
2. Capital & Risk Management 💰
Configurable Total Capital: Define your account size
Customizable Risk Percentage: Set % of capital to risk per trade (recommended 0.5-1%)
Real-Time Risk Calculation: See exact USD risk and profit potential
Minimum Win Rate Calculator: Know the % of winning trades needed for profitability
3. Dual Stop Loss Methods 🛑
ATR Multiplier: Volatility-based SL (ideal for trend following)
Structural Minimum: Support/Resistance-based SL with configurable buffer in pips
Flexible Calculation Basis: Choose between "Pure SL" or "Buffer Included"
4. Risk/Reward Configuration 📊
Customizable RR Ratio: Set your desired profit ratio (e.g., 1:2, 1:3)
Partial Take Profit: Display intermediate TP levels
Visual SL/TP Lines: Graphical price levels with labels
5. Trading Costs Integration 💵
Commission Tracking: Include costs per lot/contract
Spread Management: Manual or automatic for Forex
Transparent Breakdown: View cost details without affecting SL/TP levels
📈 Detailed Information Panel
For LONG & SHORT Trades:
Entry price (automatic or manual planning)
Exact SL/TP levels (price, pips/distance, percentage)
Expected risk and profit in USD
Position Nominal Value
Capital Used (%) with color-coded exposure alerts
Leverage (x) with configurable threshold warnings
Position size by instrument type
🛠️ Supported Instruments
Forex: Micro (1K), Mini (10K), Standard (100K) lots
Stocks: Fractional shares
Futures: Whole contracts (auto-rounding)
Indices/CFDs: Fractional lots
Cryptocurrencies: Decimal units
🎨 Customizable Visualization
Panel Position: 4 locations (top/bottom right/left)
Font Sizes: Adjustable for panel and labels
Color Coding:
🟢 Green: Take Profit
🔴 Red: Stop Loss & critical alerts
🟡 Yellow: Moderate warnings
🟠 Orange: Partial TP & costs
⚙️ Advanced Settings
Manual Entry Planning: Set specific entry price for future trades
Directionality: LONG only, SHORT only, or both simultaneously
Size Calculation Basis: Pure SL vs Buffer Included
Auto/Manual Margin: Choose your leverage control method
🎓 Best Practices
Keep risk at 0.5-1% of capital per trade
Use conservative leverage (1x-5x) for long-term strategies
Always verify your broker's real spread
Monitor "Capital Used %" to avoid overexposure
Configure Max Leverage Warning according to your risk tolerance
Skrypt chroniony
Ten skrypt został opublikowany jako zamknięty kod źródłowy. Możesz jednak używać go swobodnie i bez żadnych ograniczeń – więcej informacji tutaj.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.
Skrypt chroniony
Ten skrypt został opublikowany jako zamknięty kod źródłowy. Możesz jednak używać go swobodnie i bez żadnych ograniczeń – więcej informacji tutaj.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.