PROTECTED SOURCE SCRIPT
Aktualisiert

POSITION SIZER

27
📊 POSITION SIZER - DUAL RISK MANAGEMENT (Long/Short) v5.1

🎯 WHAT IS THIS?
Professional risk management tool that automatically calculates the optimal position size for LONG and SHORT trades. Supports Forex, Stocks, Futures, Index CFDs, and Cryptocurrencies.

✨ KEY FEATURES
✅ Dual Risk Management - Independent calculations for Long and Short positions
✅ Auto/Manual Margin - Leverage control from 1x to 20x
✅ 5 Instruments - Forex, Stocks, Futures, CFDs, Crypto
✅ 2 SL Methods - Dynamic ATR or Structural (Highs/Lows)
✅ Complete Panel - 35+ real-time metrics
✅ Cost Calculation - Commission and Spread included
✅ Partial TP - Close profits at multiple points
✅ SL/TP Lines - Visual levels on chart

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚙️ QUICK START

Open Pine Script Editor in TradingView

Create new indicator (+ → Scripts → Indicator)

Delete default code

Paste indicator code

Press Alt+Enter or Add to Chart

Panel appears automatically

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📋 MAIN INPUTS

1️⃣ CONFIGURATION
├─ 💰 Capital Total: Your trading capital
├─ ⚠️ Risk %: Risk per trade (recommended 0.5%-1%)
├─ 📊 Direction: Long/Short/Both
├─ 🧮 Auto Margin: Enable automatic leverage
└─ ⚡ Leverage Factor: 1x-20x multiplier

2️⃣ SL/TP STRATEGY
├─ 🛑 SL/TP Method: ATR or Structural
├─ 🎯 Risk:Reward Ratio: Example 2.0 = 1:2
├─ ATR Multiplier: If method = ATR
├─ Lookback Candles: If method = Structural
└─ SL Buffer: Extra safety distance in pips

3️⃣ COSTS (OPTIONAL)
├─ 💸 Include Commission: Add trading costs
└─ 📊 Include Spread: Add spread costs

4️⃣ INSTRUMENTS
├─ Asset Type: Forex/Stocks/Futures/CFDs/Crypto
└─ Lot Display: Micro/Mini/Standard/All (Forex only)

5️⃣ DISPLAY
├─ Show Panel: On/Off
├─ Show SL/TP Lines: On/Off
└─ Panel Position: Top/Bottom × Left/Right

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📊 PANEL EXPLANATION

HEADER:
🎯 [Method] Calculator - Calculation method used
[Entry Status] - Auto/Manual/Out of Range

CONFIGURATION:
💰 Capital: Your total capital
⚠️ Risk: Money at risk per trade
📊 R:R: Risk/Reward ratio
🎲 Min. WR: Minimum win rate to break even
🏦 Max Margin: Maximum investment allowed

LONG SECTION:
🛑 SL | Price | Pips | % | Risk USD
🎯 TP | Price | Pips | % | Profit USD
💰 Nominal Value: Total investment USD
📊 Capital Used: Percentage of capital used
⚡ Leverage: Position multiplier
📦 Size: Lots/Shares/Contracts/Units

SHORT SECTION:
(Identical to LONG but inverted)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

💡 PRACTICAL EXAMPLES

EXAMPLE 1: Forex Day Trader
─────────────────────────────
Capital: $2,000
Risk: 1% = $20 per trade
Method: ATR (2.0x, Period 14)
R:R: 2.0 (1:2)
Result:
├─ SL: 50 pips
├─ TP: 100 pips
├─ Size: 1 Micro lot
└─ Max Profit: $40 (Risk $20)

EXAMPLE 2: Stock Swing Trader
────────────────────────────
Capital: $25,000
Risk: 0.5% = $125 per trade
R:R: 3.0 (1:3)
Auto Margin: 1.5x
Result:
├─ SL: $190 (5 pips distance)
├─ TP: $210 (15 pips - 3x risk)
├─ Shares: 25 units
└─ Max Profit: $375 (Risk $125)

EXAMPLE 3: Crypto Scalper
────────────────────────
Capital: $1,000
Risk: 2% = $20 per trade
Auto Margin: 5x
Result:
├─ SL: $150 distance
├─ TP: $225 distance
├─ Units: 0.0001 BTC
└─ Max Profit: $30 (Risk $20)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

❓ FREQUENTLY ASKED QUESTIONS

Q: What does "1% Risk" mean?
A: You lose maximum 1% of capital per trade.
Capital $10,000 → Max loss $100

Q: ATR vs Structural - Which is better?
A: ATR = Based on volatility (dynamic)
Structural = Based on price levels (static)
Use ATR for volatile, Structural for ranging markets

Q: How do I enable auto leverage?
A: 1. Enable "Auto Margin Calculation"
2. Set "Leverage Factor" (1x-20x)
3. Margin calculates automatically

Q: Do costs affect SL/TP?
A: NO. Costs are informational only.
They reduce profits, not risk.

Q: Why is my position size so small?
A: Low risk %, wide SL, or small capital.
Solution: Increase risk % (carefully) or tighten SL

Q: Does it work on all timeframes?
A: YES. Better on D1, H4, H1.
Avoid very low timeframes (<5 min) due to spread

Q: What is "Min. WR"?
A: Minimum win rate to break even.
R:R 1:2 requires 33% win rate
R:R 1:3 requires 25% win rate

Q: Can I use for backtesting?
A: YES. Manually validate your strategy historically.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚡ TIPS & TRICKS

COMPARE SCENARIOS
├─ Try different R:R ratios
├─ Adjust leverage factors
└─ Watch how position size changes

VALIDATE YOUR STRATEGY
├─ Enter real price levels
├─ Compare theoretical vs actual
└─ Adjust based on market conditions

OPTIMIZE FOR YOUR STYLE
├─ Scalpers: Risk 2%, R:R 1:1
├─ Day Traders: Risk 1%, R:R 1:2
└─ Swing: Risk 0.5%, R:R 1:3

MONITOR COSTS
├─ Enable commission and spread
├─ See impact on profits
└─ Compare different brokers

USE AUTO MARGIN WISELY
├─ Keep safe capital aside
├─ Use 1.5x-2x only if needed
└─ Never use maximum (20x too risky)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🔧 TROUBLESHOOTING

❌ Panel doesn't appear
✅ Solution: Ensure "Show Panel" = On

❌ Text too small
✅ Solution: Increase "Panel Font Size"

❌ Lines not visible
✅ Solution: Enable "Show SL/TP Lines"

❌ Position size is 0
✅ Solution: Increase capital or reduce SL distance

❌ Forex not calculating correctly
✅ Solution: Select Asset Type = "Forex"

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📚 RECOMMENDED LEARNING

Study Position Sizing
└─ Search: "Position Sizing" on YouTube

Understand Risk:Reward
└─ Search: "Risk Reward Ratio" on Google

Practice on Demo
└─ Always demo before real account

Do Manual Backtesting
└─ Validate strategy historically

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📝 CHANGELOG

V5.1 (CURRENT)
✅ Auto Margin Calculation fix
✅ 5 instrument support
✅ Improved Cost Calculation
✅ Optimized Panel (35+ metrics)

V5.0
✅ Advanced Modularity
✅ Manual/Auto Margin Support
✅ Configurable Leverage

V4.0
✅ Complete Panel
✅ Two SL/TP Methods

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠️ DISCLAIMER

📌 IMPORTANT:
├─ NOT financial advice
├─ NO profit guarantee
├─ Use at your own risk
├─ ALWAYS use stop losses
├─ Practice on DEMO first
└─ Trading has risk of total loss

Author is NOT responsible for losses or gains.
Each trader is responsible for their decisions.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🎉 READY TO TRADE!

With this tool you have a professional position
sizing system. Remember the basics:

DISCIPLINE - Follow your plan

RISK - Never risk more than 1% per trade

PATIENCE - Don't go all-in every trade

ANALYSIS - Validate before entering

Good luck with your trading! 📈

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📞 SUPPORT

For issues or suggestions:

Ensure you're using Pine Script v6

Check that code compiles without errors

Provide detailed problem description

Happy Trading! 🚀
Versionshinweise
📊 Position Sizer — Dual Risk Management (Long/Short)
What does this tool do?
A professional position sizing and risk management utility for TradingView. Calculates the optimal size for your trades, supports LONG and SHORT simultaneously, and provides a panel with all key risk metrics, labels, and lines directly on your chart.

🧩 CONFIGURATION PANEL — HOW TO USE EACH SECTION
1️⃣ MAIN CONFIGURATION
Sets up the logic for your account, core risk, and position direction.



💰 Total Capital (for % Risk): Your account size or the capital to be managed. All % risk calculations are based on this.

⚠️ Risk per Trade (%): How much you wish to risk per trade, as a percentage of your capital.

📊 Direction: Calculate and display for Long, Short, or Both. “Both” is recommended for fully dual strategies.

🏦 Max Margin (Nominal Value): (Optional) Maximum exposure per trade (in USD). 0 means unlimited.

🧮 Auto Margin Calculation: Calculates margin automatically from your capital and the leverage factor.

⚡ Leverage Factor: Sets leverage ("1" is no leverage, "2" is double margin, and so on) when Auto Margin is enabled.

2️⃣ SL/TP STRATEGY (Stop Loss / Take Profit)
Controls how your stop and profit targets are set, and how your sizing reacts to volatility or chart structure.



🔴 SL/TP Method:

Structural Minimum: Based on recent lows/highs plus buffer.

ATR Multiplier: Uses current volatility (ATR) for a dynamic stop.

Manual Entry Price (0 = Auto): Input a price to simulate planning, or use “0” for actual price.

🎯 Risk/Reward Ratio (R:R): Profit target as a multiple of your risk (e.g., 2.0 = risk $1, aim $2).

SL Multiplier (×ATR): (ATR only) Set how many ATRs wide your stop will be.

ATR Period: (ATR only) How many bars/candles to calculate ATR.

🔎 Structural Lookback + Buffer: (Structural only)

Number of candles to scan for lowest low/highest high.

Buffer (in pips): Added for extra safety margin.

📏 Sizing Basis: Buffer included (safer), or pure SL distance (aggressive).

Cost and Advanced Options


💸 Include Commissions: If checked, enter commission per lot (e.g., $5 for standard FX brokers).

📊 Include Spread: If checked, enter your expected spread in pips (set to 0 for auto).

Show Partial TP: Enables a partial take profit line/level.

Partial TP R:R: Sets reward/risk ratio for the partial take profit.

4️⃣ DISPLAY & VISUALIZATION
Customize how/where all the info is shown.



Show Panel: Show/hide the calculation/info box.

Panel Position: Place in desired chart corner.

Show Pips / Show %: Toggle distance metrics for SL/TP.

Show Size: Show calculated lots, contracts, shares, or units.

Show SL/TP Lines: Display horizontal dashed lines at stop and target.

Lines to display (if Both): If both directions, choose to show only Long, only Short, or both.

Panel Font Size / Label Font Size: Adjust size for readability.

🖥️ RESULT PANEL & VISUALS
Here’s how the output looks and what each metric means:



Panel Header: Shows SL/TP method, and input status (auto or manual).

Risk Row: Capital, risk percentage and cash risk per trade.

R:R & Min WR: Your risk/reward setting, and the minimum win rate (%) needed to break even.

Margin & Method: Calculated margin details and SL/TP method configuration.

LONG Section:

Entry: What price is used (manual or auto).

SL (Stop): Price/Distance/%/Risk (all in one row).

TP (Profit): Price/Distance/%/Potential profit.

Nominal Value: Trade value at entry.

Capital Used & Leverage: Proportion of capital at risk/margin.

Shares/Contracts/Lots: Dynamically matches instrument.

SHORT Section: Mirrors the LONG logic for short trades.

SL/TP Lines on Chart:

TP (Green label): Take profit level (shows price).

SL (Red label): Stop loss level (shows price).

Dashed Lines: Connect entry to SL/TP. See both directions if “Both” is enabled.

Partial TP Label: Yellow/orange if enabled.

📝 ICON GLOSSARY
💰 = Capital, money, exposure

⚠️ = Risk, warning

🏦 = Margin, account, guarantee

⚡ = Leverage

🧮 = (Auto) Calculation performed by the script

📏 = Measurement logic (position size/distance)

🖥️ = On-chart display/panel

🔎 = Chart structure/scan

🔴/🟢 = SL/TP point markers (red/green)

🎯 = Target, goal (Take Profit)

📊 = Analytics, settings

💸 = Cost

📦 = Position size (Lots, Contracts, Shares, Units)

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.