PROTECTED SOURCE SCRIPT

POSITION SIZER

18
📊 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! 🚀

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.