1%is Thai Gold Dashboard

AntmanForex · study · 72 行 · 点赞 3 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("1%is Thai Gold Dashboard PRO", overlay=true)
 
// ===== INPUT =====
premiumTHB = input.float(0.0, "Thai Premium / Discount (THB)", step=1.0)
xauMovePoints = input.float(100.0, "XAU Move (points)", step=1.0)
 
// ===== POSITION CONTROL =====
posInput = input.string("bottom_left", "Dashboard Position", 
     options = ["top_left","top_right","bottom_left","bottom_right"])
 
pos =
     posInput == "top_left" ? position.top_left :
     posInput == "top_right" ? position.top_right :
     posInput == "bottom_right" ? position.bottom_right :
     position.bottom_left
 
// ===== SIZE CONTROL =====
sizeInput = input.string("normal", "Text Size",
     options = ["tiny","small","normal","large","huge"])
 
txtSize =
     sizeInput == "tiny" ? size.tiny :
     sizeInput == "small" ? size.small :
     sizeInput == "large" ? size.large :
     sizeInput == "huge" ? size.huge :
     size.normal
 
// ===== SYMBOLS =====
usdthb = request.security("FX_IDC:USDTHB", timeframe.period, close)
xauusd = close
 
// ===== CONSTANTS =====
troyOunceToGram = 31.1035
thaiGoldBahtWeight = 15.244
thaiPurity = 0.965
 
// ===== FUNCTION =====
calcThaiGold(_xau) =>
    (_xau / troyOunceToGram) * thaiGoldBahtWeight * thaiPurity * usdthb + premiumTHB
 
// ===== CALC =====
thaiGoldNow = calcThaiGold(xauusd)
thaiGoldUp = calcThaiGold(xauusd + xauMovePoints)
thaiGoldDown = calcThaiGold(xauusd - xauMovePoints)
 
diffUp = thaiGoldUp - thaiGoldNow
diffDown = thaiGoldDown - thaiGoldNow
 
// ===== DASHBOARD =====
var table dash = table.new(pos, 2, 5, border_width=1)
 
if barstate.islast
    // Header
    table.cell(dash, 0, 0, "1%is Thai Gold", text_color=color.white, bgcolor=color.black, text_size=txtSize)
    table.cell(dash, 1, 0, "Dashboard", text_color=color.white, bgcolor=color.black, text_size=txtSize)
 
    // Current price
    table.cell(dash, 0, 1, "ทองไทย 1 บาท", text_color=color.white, bgcolor=color.black, text_size=txtSize)
    table.cell(dash, 1, 1, str.tostring(thaiGoldNow, "#,##0.00") + " บาท", text_color=color.yellow, bgcolor=color.black, text_size=txtSize)
 
    // XAU UP
    table.cell(dash, 0, 2, "XAU +" + str.tostring(xauMovePoints, "#") + " จุด", text_color=color.white, bgcolor=color.black, text_size=txtSize)
    table.cell(dash, 1, 2, "+" + str.tostring(diffUp, "#,##0.00") + " บาท", text_color=color.lime, bgcolor=color.black, text_size=txtSize)
 
    // XAU DOWN
    table.cell(dash, 0, 3, "XAU -" + str.tostring(xauMovePoints, "#") + " จุด", text_color=color.white, bgcolor=color.black, text_size=txtSize)
    table.cell(dash, 1, 3, str.tostring(diffDown, "#,##0.00") + " บาท", text_color=color.red, bgcolor=color.black, text_size=txtSize)
 
    // USDTHB
    table.cell(dash, 0, 4, "USDTHB", text_color=color.white, bgcolor=color.black, text_size=txtSize)
    table.cell(dash, 1, 4, str.tostring(usdthb, "#,##0.00"), text_color=color.aqua, bgcolor=color.black, text_size=txtSize)

← 返回列表