本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
//Author : V-i-c-k-y
indicator('Universal Futures Lot Calculator',shorttitle="Futty", overlay = true)
// ================= General Settings =================
accountSize = input.int(25000, title = 'Account Size', group = 'Account 1 Settings')
riskPercentage = input.float(0.5, title = 'Risk Percentage (%)', group = 'Account 1 Settings')
// ================= Account 2 Settings =================
enableAccount2 = input.bool(false, title = 'Enable Account 2', group = 'Account 2 Settings')
accountSize2 = input.int(50000, title = 'Account 2 Size', group = 'Account 2 Settings')
riskPercentage2 = input.float(0.5, title = 'Account 2 Risk Percentage (%)', group = 'Account 2 Settings')
// ================= Auto Dollars Per Point =================
var dollarsPerPoint = 0.0
if syminfo.ticker == 'MES1!'
dollarsPerPoint := 5.0
dollarsPerPoint
else if syminfo.ticker == 'ES1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'NQ1!'
dollarsPerPoint := 20.0
dollarsPerPoint
else if syminfo.ticker == 'MNQ1!'
dollarsPerPoint := 2.0
dollarsPerPoint
else if syminfo.ticker == 'RTY1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'M2K1!'
dollarsPerPoint := 5.0
dollarsPerPoint
else if syminfo.ticker == 'NKD1!'
dollarsPerPoint := 5.0
dollarsPerPoint
else if syminfo.ticker == 'MBT1!'
dollarsPerPoint := 0.1
dollarsPerPoint
else if syminfo.ticker == 'MET1!'
dollarsPerPoint := 0.1
dollarsPerPoint
// Crypto (Standard)
else if syminfo.ticker == 'BTC1!'
dollarsPerPoint := 5.0
dollarsPerPoint
else if syminfo.ticker == 'ETH1!'
dollarsPerPoint := 50.0
dollarsPerPoint
// Indices & Volatility
else if syminfo.ticker == 'VX1!'
dollarsPerPoint := 1000.0
dollarsPerPoint
// Forex Futures
else if syminfo.ticker == '6A1!'
dollarsPerPoint := 100000
dollarsPerPoint
else if syminfo.ticker == '6B1!'
dollarsPerPoint := 62500
dollarsPerPoint
else if syminfo.ticker == '6C1!'
dollarsPerPoint := 100000
dollarsPerPoint
else if syminfo.ticker == '6E1!'
dollarsPerPoint := 125000
dollarsPerPoint
else if syminfo.ticker == '6J1!'
dollarsPerPoint := 12500000
dollarsPerPoint
else if syminfo.ticker == '6S1!'
dollarsPerPoint := 125000
dollarsPerPoint
else if syminfo.ticker == 'E71!'
dollarsPerPoint := 62500
dollarsPerPoint
else if syminfo.ticker == 'M6E1!'
dollarsPerPoint := 12500
dollarsPerPoint
else if syminfo.ticker == 'M6A1!'
dollarsPerPoint := 10000
dollarsPerPoint
else if syminfo.ticker == '6M1!'
dollarsPerPoint := 500000
dollarsPerPoint
else if syminfo.ticker == '6N1!'
dollarsPerPoint := 100000
dollarsPerPoint
else if syminfo.ticker == 'M6B1!'
dollarsPerPoint := 6250
dollarsPerPoint
// Additional Micro Forex
else if syminfo.ticker == 'M6C1!'
dollarsPerPoint := 10000.0
dollarsPerPoint
else if syminfo.ticker == 'M6S1!'
dollarsPerPoint := 12500.0
dollarsPerPoint
else if syminfo.ticker == 'M6J1!'
dollarsPerPoint := 1250000.0
dollarsPerPoint
// Commodities - Meats
else if syminfo.ticker == 'HE1!'
dollarsPerPoint := 400
dollarsPerPoint
else if syminfo.ticker == 'LE1!'
dollarsPerPoint := 400
dollarsPerPoint
else if syminfo.ticker == 'GF1!'
dollarsPerPoint := 500.0
dollarsPerPoint
// Commodities - Energy
else if syminfo.ticker == 'CL1!'
dollarsPerPoint := 1000
dollarsPerPoint
else if syminfo.ticker == 'QM1!'
dollarsPerPoint := 500
dollarsPerPoint
else if syminfo.ticker == 'NG1!'
dollarsPerPoint := 10000
dollarsPerPoint
else if syminfo.ticker == 'QG1!'
dollarsPerPoint := 2500
dollarsPerPoint
else if syminfo.ticker == 'MCL1!'
dollarsPerPoint := 100
dollarsPerPoint
else if syminfo.ticker == 'RB1!'
dollarsPerPoint := 42000
dollarsPerPoint
else if syminfo.ticker == 'HO1!'
dollarsPerPoint := 42000
dollarsPerPoint
else if syminfo.ticker == 'PL1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'MNG1!'
dollarsPerPoint := 2500
dollarsPerPoint
// Commodities - Agriculture & Softs
else if syminfo.ticker == 'ZC1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'ZW1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'ZS1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'ZM1!'
dollarsPerPoint := 100.0
dollarsPerPoint
else if syminfo.ticker == 'ZL1!'
dollarsPerPoint := 600.0
dollarsPerPoint
else if syminfo.ticker == 'CT1!'
dollarsPerPoint := 500.0
dollarsPerPoint
else if syminfo.ticker == 'CC1!'
dollarsPerPoint := 10.0
dollarsPerPoint
else if syminfo.ticker == 'SB1!'
dollarsPerPoint := 1120.0
dollarsPerPoint
else if syminfo.ticker == 'KC1!'
dollarsPerPoint := 375.0
dollarsPerPoint
else if syminfo.ticker == 'KE1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'ZO1!'
dollarsPerPoint := 50.0
dollarsPerPoint
// Indices - Dow
else if syminfo.ticker == 'YM1!'
dollarsPerPoint := 5.0
dollarsPerPoint
else if syminfo.ticker == 'MYM1!'
dollarsPerPoint := 0.5
dollarsPerPoint
// Treasury Bonds & Notes
else if syminfo.ticker == 'ZT1!'
dollarsPerPoint := 2000
dollarsPerPoint
else if syminfo.ticker == 'ZF1!'
dollarsPerPoint := 1000
dollarsPerPoint
else if syminfo.ticker == 'ZN1!'
dollarsPerPoint := 1000
dollarsPerPoint
else if syminfo.ticker == 'TN1!'
dollarsPerPoint := 1000
dollarsPerPoint
else if syminfo.ticker == 'ZB1!'
dollarsPerPoint := 1000
dollarsPerPoint
else if syminfo.ticker == 'UB1!'
dollarsPerPoint := 1000
dollarsPerPoint
// Precious Metals
else if syminfo.ticker == 'GC1!'
dollarsPerPoint := 100
dollarsPerPoint
else if syminfo.ticker == 'SI1!'
dollarsPerPoint := 50.0
dollarsPerPoint
else if syminfo.ticker == 'HG1!'
dollarsPerPoint := 250
dollarsPerPoint
else if syminfo.ticker == 'MGC1!'
dollarsPerPoint := 10.0
dollarsPerPoint
else if syminfo.ticker == 'SIL1!'
dollarsPerPoint := 5.0
dollarsPerPoint
else if syminfo.ticker == 'MHG1!'
dollarsPerPoint := 25.0
dollarsPerPoint
else
dollarsPerPoint := na
dollarsPerPoint
// ================= Entry, SL & TP Inputs =================
entry = input.price(defval = 0, title = 'Entry', group = 'Trade Levels', confirm = true)
stopLoss = input.price(defval = 0, title = 'Stop Loss', group = 'Trade Levels', confirm = true)
takeProfit = input.price(defval = 0, title = 'Take Profit', group = 'Trade Levels', confirm = true)
// ================= Risk & Contracts Calculations =================
stopSizeInPoints = math.abs(entry - stopLoss)
cashAtRisk = accountSize * (riskPercentage / 100.0)
contractsToRisk = stopSizeInPoints != 0 ? cashAtRisk / (dollarsPerPoint * stopSizeInPoints) : 0
cashAtRisk2 = enableAccount2 ? accountSize2 * (riskPercentage2 / 100.0) : na
contractsToRisk2 = enableAccount2 and stopSizeInPoints != 0 ? cashAtRisk2 / (dollarsPerPoint * stopSizeInPoints) : na
contractType = str.startswith(syminfo.ticker, 'M') ? 'Micro' : 'Mini'
// ================= New Visualization =================
if barstate.islastconfirmedhistory
tradeLength = 20
line.new(bar_index + 1, entry, bar_index + tradeLength, entry, color = color.green)
box.new(bar_index + 1, entry, bar_index + tradeLength, stopLoss, bgcolor = color.new(color.red, 80), border_color = na)
box.new(bar_index + 1, entry, bar_index + tradeLength, takeProfit, bgcolor = color.new(color.green, 80), border_color = na)
label.new(bar_index + int(tradeLength / 2), stopLoss, str.tostring(stopSizeInPoints, '#.##') + ' pts | -$' + str.tostring(cashAtRisk, '#.##'), color = color.red, textcolor = color.white, style = label.style_label_center, size = size.small)
rrRatio = stopSizeInPoints != 0 ? math.abs(takeProfit - entry) / stopSizeInPoints : na
label.new(bar_index + int(tradeLength / 2), takeProfit, '+$' + str.tostring(cashAtRisk * rrRatio, '#.##') + ' | R:R ' + str.tostring(rrRatio, '#.##'), color = color.green, textcolor = color.white, style = label.style_label_center, size = size.small)
// ================= Info Table Setup =================
string tablePosition = input.string('Top Right', 'Table Position', options = ['Top Left', 'Top Center', 'Top Right', 'Middle Left', 'Middle Center', 'Middle Right', 'Bottom Left', 'Bottom Center', 'Bottom Right'], group = 'Table Settings')
string tableSizeInput = input.string('Small', 'Table Size', options = ['Auto', 'Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = 'Table Settings')
textSize = switch tableSizeInput
'Auto' => size.auto
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large
'Huge' => size.huge
=> size.normal
var table myTable = na
numCols = enableAccount2 ? 3 : 2
if barstate.isfirst
myTable := table.new(tablePosition == 'Top Left' ? position.top_left : tablePosition == 'Top Center' ? position.top_center : tablePosition == 'Top Right' ? position.top_right : tablePosition == 'Middle Left' ? position.middle_left : tablePosition == 'Middle Center' ? position.middle_center : tablePosition == 'Middle Right' ? position.middle_right : tablePosition == 'Bottom Left' ? position.bottom_left : tablePosition == 'Bottom Center' ? position.bottom_center : position.bottom_right, numCols, 6)
table.set_frame_color(myTable, color.new(color.black, 0))
table.set_frame_width(myTable, 2)
table.set_border_color(myTable, color.new(color.gray, 60))
table.set_border_width(myTable, 1)
// ================= Info Table Population =================
if not na(myTable)
if enableAccount2
table.cell(myTable, 0, 0, 'Parameter', bgcolor = #1e222d, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 0, 'Account 1', bgcolor = #1e222d, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 2, 0, 'Account 2', bgcolor = #1e222d, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 1, 'Account Size', bgcolor = #131722, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 1, '$' + str.tostring(accountSize, '#,###'), bgcolor = #131722, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 2, 1, '$' + str.tostring(accountSize2, '#,###'), bgcolor = #131722, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 2, 'Risk %', bgcolor = #1e222d, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 2, str.tostring(riskPercentage, '#.##') + '%', bgcolor = #1e222d, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 2, 2, str.tostring(riskPercentage2, '#.##') + '%', bgcolor = #1e222d, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 3, 'Point Val', bgcolor = #131722, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 3, str.tostring(dollarsPerPoint, '#.##'), bgcolor = #131722, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 2, 3, str.tostring(dollarsPerPoint, '#.##'), bgcolor = #131722, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 4, 'Cash at Risk', bgcolor = #1e222d, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 4, '$' + str.tostring(cashAtRisk, '#.##'), bgcolor = #1e222d, text_color = #f23645, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 2, 4, '$' + str.tostring(cashAtRisk2, '#.##'), bgcolor = #1e222d, text_color = #f23645, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 5, 'Lot Size', bgcolor = #2962ff, text_color = color.white, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 5, str.tostring(contractsToRisk, '#.##') + ' (' + contractType + ')', bgcolor = #2962ff, text_color = #00ff7f, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 2, 5, str.tostring(contractsToRisk2, '#.##') + ' (' + contractType + ')', bgcolor = #2962ff, text_color = #00ff7f, text_size = textSize, text_halign = text.align_center)
else
table.cell(myTable, 0, 0, 'Parameter', bgcolor = #1e222d, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 0, 'Account 1', bgcolor = #1e222d, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 1, 'Account Size', bgcolor = #131722, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 1, '$' + str.tostring(accountSize, '#,###'), bgcolor = #131722, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 2, 'Risk %', bgcolor = #1e222d, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 2, str.tostring(riskPercentage, '#.##') + '%', bgcolor = #1e222d, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 3, 'Point Val', bgcolor = #131722, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 3, str.tostring(dollarsPerPoint, '#.##'), bgcolor = #131722, text_color = color.white, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 4, 'Cash at Risk', bgcolor = #1e222d, text_color = #787b86, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 4, '$' + str.tostring(cashAtRisk, '#.##'), bgcolor = #1e222d, text_color = #f23645, text_size = textSize, text_halign = text.align_center)
table.cell(myTable, 0, 5, 'Lot Size', bgcolor = #2962ff, text_color = color.white, text_size = textSize, text_halign = text.align_left)
table.cell(myTable, 1, 5, str.tostring(contractsToRisk, '#.##') + ' (' + contractType + ')', bgcolor = #2962ff, text_color = #00ff7f, text_size = textSize, text_halign = text.align_center)