PROTECTED SOURCE SCRIPT

Position Size Calculator forex

25
//version=5
indicator("AUTO Risk & Position Size Calculator – FOREX (EURUSD)", overlay=true)

// === INPUTS ===
accountBalance = input.float(100000, "Account Balance")
riskPercent = input.float(1.0, "Risk % per Trade", step=0.1)

// === ENTRY & STOP (MANUAL) ===
entryPrice = input.float(0.0, "Entry Price")
stopPrice = input.float(0.0, "Stop Loss Price")

// === SYMBOL DATA (AUTO FROM TRADINGVIEW) ===
tickSize = syminfo.mintick
tickValue = syminfo.pointvalue * syminfo.mintick

// === CALCULATIONS ===
riskAmount = accountBalance * (riskPercent / 100)
stopDistance = math.abs(entryPrice - stopPrice)

// antal ticks mellem entry og stop
ticks = stopDistance / tickSize

// risk pr. 1 lot
riskPerLot = ticks * tickValue

// lots der skal trades
lotsToTrade = riskPerLot > 0 ? riskAmount / riskPerLot : na

// === DISPLAY ===
var table t = table.new(position.top_right, 2, 9, border_width=1)

table.cell(t, 0, 0, "Symbol")
table.cell(t, 1, 0, syminfo.ticker)

table.cell(t, 0, 1, "Account Balance")
table.cell(t, 1, 1, str.tostring(accountBalance))

table.cell(t, 0, 2, "Risk %")
table.cell(t, 1, 2, str.tostring(riskPercent) + "%")

table.cell(t, 0, 3, "Risk Amount ($)")
table.cell(t, 1, 3, str.tostring(riskAmount))

table.cell(t, 0, 4, "Entry Price")
table.cell(t, 1, 4, str.tostring(entryPrice))

table.cell(t, 0, 5, "Stop Loss Price")
table.cell(t, 1, 5, str.tostring(stopPrice))

table.cell(t, 0, 6, "Stop Distance")
table.cell(t, 1, 6, str.tostring(stopDistance))

table.cell(t, 0, 7, "Risk per 1 Lot ($)")
table.cell(t, 1, 7, str.tostring(riskPerLot))

table.cell(t, 0, 8, "LOTS TO TRADE")
table.cell(t, 1, 8, str.tostring(lotsToTrade, "#.##"))

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.