PROTECTED SOURCE SCRIPT
Position Size Calculator forex

//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, "#.##"))
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, "#.##"))
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya secara bebas dan tanpa apa-apa had – ketahui lebih di sini.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya secara bebas dan tanpa apa-apa had – ketahui lebih di sini.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.