OPEN-SOURCE SCRIPT

Smart Position Sizer [QuantRegime]

723
## Overview

The Smart Position Sizer calculates the exact position size for any trade based on your account size, risk percentage, and stop loss distance. It answers the question every trader should ask before every trade: **"How many shares/contracts/coins should I buy?"**

Most traders either skip this calculation (and blow up) or do it manually (and make mistakes). This indicator does it instantly, on any market, on any timeframe.

## How It Works

**The core formula:**

$$\text{Position Size} = \frac{\text{Account} \times \text{Risk \%}}{\text{Stop Loss Distance}}$$

But unlike a simple calculator, this indicator:

1. **Automatically calculates stop loss distance** using 5 different methods
2. **Shows entry, SL, and 3 take-profit levels** directly on your chart
3. **Displays exact dollar risk, position value, and implied leverage**
4. **Adjusts in real-time** as price and volatility change

## 5 Stop Loss Methods

| Method | Best For | How It Works |
|--------|----------|-------------|
| **ATR** | Most traders | Places SL at N × ATR from entry. Adapts to current volatility. |
| **Fixed Points** | Scalpers | Fixed pip/point distance. Consistent mechanical stop. |
| **Fixed %** | Swing traders | SL at a fixed % below/above entry. Simple and predictable. |
| **Recent Swing** | Price action traders | Uses the most recent swing high/low as the stop level. |
| **Manual Price** | Specific levels | You type in the exact SL price (e.g., below a key support). |

## The Dashboard

The dashboard shows everything you need at a glance:

- **Direction** — Long or Short (auto-detected or manual)
- **Position Size** — How many units/shares/contracts to buy
- **Position Value** — Total dollar value of the position
- **Risk Amount** — Exact dollars at risk if stopped out
- **Stop Loss** — Price level and % distance
- **ATR** — Current average true range and % of price
- **TP1, TP2, TP3** — Take profit targets with R:R ratio and dollar profit

## Chart Lines

The indicator draws directly on your chart:
- **White solid line** — Entry price
- **Red dashed line** — Stop loss level
- **Cyan dotted lines** — 3 take profit levels with R:R labels

## Who This Is For

- **Crypto traders** — Know exactly how many coins to buy for your risk tolerance
- **Stock traders** — Calculate share count for any position
- **Forex traders** — Get lot sizes based on pip risk
- **Futures traders** — Contract sizing with proper risk management

## Settings Guide

### For Conservative Traders (1% risk)
- Risk Per Trade: 1%
- ATR Multiplier: 2.0-2.5
- TP1: 1.5R, TP2: 2.5R, TP3: 4R

### For Moderate Traders (2% risk)
- Risk Per Trade: 2%
- ATR Multiplier: 1.5-2.0
- TP1: 1R, TP2: 2R, TP3: 3R

### For Aggressive (scalping, 3%+)
- Risk Per Trade: 3%
- SL Method: Fixed Points (tight)
- TP1: 1R, TP2: 1.5R, TP3: 2R

## Important Notes

- **Update your account size** as it changes — this is not connected to your broker
- Position sizes are calculated based on the current bar's close price
- The "Auto" direction uses a 21 EMA — override manually if you have a specific bias
- Works on any market with proper syminfo (stocks, crypto, forex, futures, indices)

## Risk Management Rules

This indicator enforces proper risk management by design:
- Never risk more than your set % per trade
- ATR-based stops adapt to current market volatility
- The R:R display helps you only take trades with favorable risk/reward

> "The goal of a successful trader is to make the best trades. Money is secondary." — Alexander Elder

## Disclaimer

This indicator is for educational and analytical purposes only. It does not constitute financial advice. Position sizing calculations depend on accurate input of your account size and do not account for slippage, gaps, or execution differences. Always verify calculations before placing trades.

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.