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, "#.##"))
受保護腳本
此腳本以閉源形式發佈。 不過,您可以自由使用,沒有任何限制 — 點擊此處了解更多。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
受保護腳本
此腳本以閉源形式發佈。 不過,您可以自由使用,沒有任何限制 — 點擊此處了解更多。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。