Indicator · Pine Script v6 · On the chart

Scalping Position Size

by iamrichardD

This indicator calculates a suggested position size from account size, risk per trade, and a percentage stop.

View on GitHub

GitHub stars57on the repository
Pine versionv6current
Lines of code44
Settings3inputs
LicenceApache-2.0
Last update1 year ago19 Aug 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

44 lines of Pine Script v6 from testing-lab/risk-management-tools/position-size-calculator.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

position-size-calculator.pine
// Position Size Calculator for Scalping - EXPERIMENTAL
// Ultra-tight risk management for BTC True Scalping strategy
// 
// ⚠️ EXPERIMENTAL WARNING: Testing lab development only
//
//@version=6

indicator("Scalping Position Size [EXP]", "SPS_EXP", overlay=true)

//=====================================================================================================================
// 🚧 EXPERIMENTAL RISK MANAGEMENT TOOL
//=====================================================================================================================

grpRisk = "🛡️ Risk Management"
accountSize = input.float(10000.0, "Account Size", minval=100, group=grpRisk)
riskPercent = input.float(0.5, "Risk Per Trade %", minval=0.1, maxval=2.0, step=0.1, group=grpRisk)
stopLossPercent = input.float(0.15, "Stop Loss %", minval=0.05, maxval=0.5, step=0.01, group=grpRisk)

// Calculate position size
riskAmount = accountSize * (riskPercent / 100)
stopDistance = close * (stopLossPercent / 100)
positionSize = stopDistance > 0 ? riskAmount / stopDistance : 0

// Display calculation
if barstate.islast
    var table riskTable = table.new(position.bottom_left, 2, 6, bgcolor=color.white, border_width=1)
    
    table.cell(riskTable, 0, 0, "🛡️ RISK CALCULATOR", text_color=color.white, bgcolor=color.red)
    table.cell(riskTable, 1, 0, "VALUE", text_color=color.white, bgcolor=color.red)
    
    table.cell(riskTable, 0, 1, "Account Size", text_color=color.black)
    table.cell(riskTable, 1, 1, "$" + str.tostring(accountSize, "#,###"), text_color=color.black)
    
    table.cell(riskTable, 0, 2, "Risk Amount", text_color=color.black)
    table.cell(riskTable, 1, 2, "$" + str.tostring(riskAmount, "#.##"), text_color=color.red)
    
    table.cell(riskTable, 0, 3, "Stop Distance", text_color=color.black)
    table.cell(riskTable, 1, 3, "$" + str.tostring(stopDistance, "#.##"), text_color=color.red)
    
    table.cell(riskTable, 0, 4, "Position Size", text_color=color.black)
    table.cell(riskTable, 1, 4, str.tostring(positionSize, "#.####"), text_color=color.green)
    
    table.cell(riskTable, 0, 5, "⚠️ STATUS", text_color=color.black)
    table.cell(riskTable, 1, 5, "EXPERIMENTAL", text_color=color.red)

Overview

Scalping Position Size multiplies account size by the risk percent to get the dollar risk, then divides that by a stop distance equal to the current close times the stop-loss percent. The result appears in a two-column table at the bottom left of the price chart, filled only on the last bar. Account size, risk percent, and stop percent are the main settings. It does not generate entries, exits, or orders, and the displayed size changes as the live close moves.

Details

Published by

iamrichardD on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Screeners & dashboards, Scalping

Markets

Crypto

Timeframes

M1-M5

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Account Sizefloat10000.0accountSize
Risk Per Trade %float0.5riskPercent
Stop Loss %float0.15stopLossPercent
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This indicator scans NSE-listed stocks for momentum signals using Supertrend, multiple EMAs, MACD, and stochastic oscillator. It supports continuous or flip signal modes and displays matching setups in a customizable table at the bottom left of the chart. The

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup Scanner
14 stars

This overlay indicator builds a money-management table on the price chart. It takes a deposit, a maximum risk percentage per trade, and a commission percentage, then sizes risk against up to ten user-defined stop-loss percentages and an optional ATR stop. The

Indicator v5 ScalpingVolatility & bands
Updated 3 years ago · None stated GitHub repository of Scalping money management

ICT State Machine

by alboogycOdR
6 stars

This indicator tracks a sequential smart money concepts workflow using a state machine on the price chart. It monitors higher-timeframe four-hour bias, Asian session ranges, liquidity sweeps, market structure shifts, change in state of delivery, and fair value

Indicator v5 SMC / ICT / price actionSessions & time
Updated 7 months ago · None stated GitHub repository of ICT State Machine
4 stars

This TradingView indicator provides scalping money management tools by displaying a customizable panel on the chart. It shows risk management details such as deposit size, maximum risk per trade as a percentage, and commission adjustments. The indicator plots

Indicator v5 ScalpingScreeners & dashboards
Updated 3 years ago · MIT GitHub repository of Scalping Money Management

This indicator evaluates multiple technical trading strategies and strategy combinations across various timeframes to identify the top-performing setup for Turkish stocks and other assets. Depending on whether the active chart is intraday or higher timeframe,

Indicator v5 Screeners & dashboardsTrend
3 stars

This indicator plots trading signals and overlays directly on the price chart. It generates directional buy and sell signals filtered by configurable sensitivity, signal tuning, volume, and trend clouds. The script visualizes reversal dots, market structure sw

Indicator v5 TrendSupport & resistance
Updated 12 months ago · None stated GitHub repository of ZZ Algo | Signals & Overlays

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers